1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005 |
- /*[clinic input]
- preserve
- [clinic start generated code]*/
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- # include "pycore_gc.h" // PyGC_Head
- # include "pycore_runtime.h" // _Py_ID()
- #endif
- PyDoc_STRVAR(os_stat__doc__,
- "stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Perform a stat system call on the given path.\n"
- "\n"
- " path\n"
- " Path to be examined; can be string, bytes, a path-like object or\n"
- " open-file-descriptor int.\n"
- " dir_fd\n"
- " If not None, it should be a file descriptor open to a directory,\n"
- " and path should be a relative string; path will then be relative to\n"
- " that directory.\n"
- " follow_symlinks\n"
- " If False, and the last element of the path is a symbolic link,\n"
- " stat will examine the symbolic link itself instead of the file\n"
- " the link points to.\n"
- "\n"
- "dir_fd and follow_symlinks may not be implemented\n"
- " on your platform. If they are unavailable, using them will raise a\n"
- " NotImplementedError.\n"
- "\n"
- "It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
- " an open file descriptor.");
- #define OS_STAT_METHODDEF \
- {"stat", _PyCFunction_CAST(os_stat), METH_FASTCALL|METH_KEYWORDS, os_stat__doc__},
- static PyObject *
- os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
- static PyObject *
- os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "stat",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1);
- int dir_fd = DEFAULT_DIR_FD;
- int follow_symlinks = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (args[1]) {
- if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- follow_symlinks = PyObject_IsTrue(args[2]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- PyDoc_STRVAR(os_lstat__doc__,
- "lstat($module, /, path, *, dir_fd=None)\n"
- "--\n"
- "\n"
- "Perform a stat system call on the given path, without following symbolic links.\n"
- "\n"
- "Like stat(), but do not follow symbolic links.\n"
- "Equivalent to stat(path, follow_symlinks=False).");
- #define OS_LSTAT_METHODDEF \
- {"lstat", _PyCFunction_CAST(os_lstat), METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__},
- static PyObject *
- os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
- static PyObject *
- os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "dir_fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "lstat",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- path_t path = PATH_T_INITIALIZE_P("lstat", "path", 0, 0, 0, 0);
- int dir_fd = DEFAULT_DIR_FD;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_lstat_impl(module, &path, dir_fd);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- PyDoc_STRVAR(os_access__doc__,
- "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
- " follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Use the real uid/gid to test for access to a path.\n"
- "\n"
- " path\n"
- " Path to be tested; can be string, bytes, or a path-like object.\n"
- " mode\n"
- " Operating-system mode bitfield. Can be F_OK to test existence,\n"
- " or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
- " dir_fd\n"
- " If not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that\n"
- " directory.\n"
- " effective_ids\n"
- " If True, access will use the effective uid/gid instead of\n"
- " the real uid/gid.\n"
- " follow_symlinks\n"
- " If False, and the last element of the path is a symbolic link,\n"
- " access will examine the symbolic link itself instead of the file\n"
- " the link points to.\n"
- "\n"
- "dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
- " on your platform. If they are unavailable, using them will raise a\n"
- " NotImplementedError.\n"
- "\n"
- "Note that most operations will use the effective uid/gid, therefore this\n"
- " routine can be used in a suid/sgid environment to test if the invoking user\n"
- " has the specified access to the path.");
- #define OS_ACCESS_METHODDEF \
- {"access", _PyCFunction_CAST(os_access), METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
- static int
- os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
- int effective_ids, int follow_symlinks);
- static PyObject *
- os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 5
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(effective_ids), &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "access",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[5];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
- path_t path = PATH_T_INITIALIZE_P("access", "path", 0, 0, 0, 0);
- int mode;
- int dir_fd = DEFAULT_DIR_FD;
- int effective_ids = 0;
- int follow_symlinks = 1;
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- mode = _PyLong_AsInt(args[1]);
- if (mode == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (args[2]) {
- if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[3]) {
- effective_ids = PyObject_IsTrue(args[3]);
- if (effective_ids < 0) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- follow_symlinks = PyObject_IsTrue(args[4]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #if defined(HAVE_TTYNAME)
- PyDoc_STRVAR(os_ttyname__doc__,
- "ttyname($module, fd, /)\n"
- "--\n"
- "\n"
- "Return the name of the terminal device connected to \'fd\'.\n"
- "\n"
- " fd\n"
- " Integer file descriptor handle.");
- #define OS_TTYNAME_METHODDEF \
- {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
- static PyObject *
- os_ttyname_impl(PyObject *module, int fd);
- static PyObject *
- os_ttyname(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int fd;
- fd = _PyLong_AsInt(arg);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_ttyname_impl(module, fd);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_TTYNAME) */
- #if defined(HAVE_CTERMID)
- PyDoc_STRVAR(os_ctermid__doc__,
- "ctermid($module, /)\n"
- "--\n"
- "\n"
- "Return the name of the controlling terminal for this process.");
- #define OS_CTERMID_METHODDEF \
- {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
- static PyObject *
- os_ctermid_impl(PyObject *module);
- static PyObject *
- os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_ctermid_impl(module);
- }
- #endif /* defined(HAVE_CTERMID) */
- PyDoc_STRVAR(os_chdir__doc__,
- "chdir($module, /, path)\n"
- "--\n"
- "\n"
- "Change the current working directory to the specified path.\n"
- "\n"
- "path may always be specified as a string.\n"
- "On some platforms, path may also be specified as an open file descriptor.\n"
- " If this functionality is unavailable, using it raises an exception.");
- #define OS_CHDIR_METHODDEF \
- {"chdir", _PyCFunction_CAST(os_chdir), METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
- static PyObject *
- os_chdir_impl(PyObject *module, path_t *path);
- static PyObject *
- os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "chdir",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t path = PATH_T_INITIALIZE_P("chdir", "path", 0, 0, 0, PATH_HAVE_FCHDIR);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- return_value = os_chdir_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #if defined(HAVE_FCHDIR)
- PyDoc_STRVAR(os_fchdir__doc__,
- "fchdir($module, /, fd)\n"
- "--\n"
- "\n"
- "Change to the directory of the given file descriptor.\n"
- "\n"
- "fd must be opened on a directory, not a file.\n"
- "Equivalent to os.chdir(fd).");
- #define OS_FCHDIR_METHODDEF \
- {"fchdir", _PyCFunction_CAST(os_fchdir), METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
- static PyObject *
- os_fchdir_impl(PyObject *module, int fd);
- static PyObject *
- os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "fchdir",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int fd;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
- goto exit;
- }
- return_value = os_fchdir_impl(module, fd);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_FCHDIR) */
- PyDoc_STRVAR(os_chmod__doc__,
- "chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Change the access permissions of a file.\n"
- "\n"
- " path\n"
- " Path to be modified. May always be specified as a str, bytes, or a path-like object.\n"
- " On some platforms, path may also be specified as an open file descriptor.\n"
- " If this functionality is unavailable, using it raises an exception.\n"
- " mode\n"
- " Operating-system mode bitfield.\n"
- " Be careful when using number literals for *mode*. The conventional UNIX notation for\n"
- " numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n"
- " Python.\n"
- " dir_fd\n"
- " If not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that\n"
- " directory.\n"
- " follow_symlinks\n"
- " If False, and the last element of the path is a symbolic link,\n"
- " chmod will modify the symbolic link itself instead of the file\n"
- " the link points to.\n"
- "\n"
- "It is an error to use dir_fd or follow_symlinks when specifying path as\n"
- " an open file descriptor.\n"
- "dir_fd and follow_symlinks may not be implemented on your platform.\n"
- " If they are unavailable, using them will raise a NotImplementedError.");
- #define OS_CHMOD_METHODDEF \
- {"chmod", _PyCFunction_CAST(os_chmod), METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
- static PyObject *
- os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
- int follow_symlinks);
- static PyObject *
- os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 4
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "chmod",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[4];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
- path_t path = PATH_T_INITIALIZE_P("chmod", "path", 0, 0, 0, PATH_HAVE_FCHMOD);
- int mode;
- int dir_fd = DEFAULT_DIR_FD;
- int follow_symlinks = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- mode = _PyLong_AsInt(args[1]);
- if (mode == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (args[2]) {
- if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- follow_symlinks = PyObject_IsTrue(args[3]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #if defined(HAVE_FCHMOD)
- PyDoc_STRVAR(os_fchmod__doc__,
- "fchmod($module, /, fd, mode)\n"
- "--\n"
- "\n"
- "Change the access permissions of the file given by file descriptor fd.\n"
- "\n"
- " fd\n"
- " The file descriptor of the file to be modified.\n"
- " mode\n"
- " Operating-system mode bitfield.\n"
- " Be careful when using number literals for *mode*. The conventional UNIX notation for\n"
- " numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n"
- " Python.\n"
- "\n"
- "Equivalent to os.chmod(fd, mode).");
- #define OS_FCHMOD_METHODDEF \
- {"fchmod", _PyCFunction_CAST(os_fchmod), METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
- static PyObject *
- os_fchmod_impl(PyObject *module, int fd, int mode);
- static PyObject *
- os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(fd), &_Py_ID(mode), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"fd", "mode", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "fchmod",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- int fd;
- int mode;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- mode = _PyLong_AsInt(args[1]);
- if (mode == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_fchmod_impl(module, fd, mode);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_FCHMOD) */
- #if defined(HAVE_LCHMOD)
- PyDoc_STRVAR(os_lchmod__doc__,
- "lchmod($module, /, path, mode)\n"
- "--\n"
- "\n"
- "Change the access permissions of a file, without following symbolic links.\n"
- "\n"
- "If path is a symlink, this affects the link itself rather than the target.\n"
- "Equivalent to chmod(path, mode, follow_symlinks=False).\"");
- #define OS_LCHMOD_METHODDEF \
- {"lchmod", _PyCFunction_CAST(os_lchmod), METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
- static PyObject *
- os_lchmod_impl(PyObject *module, path_t *path, int mode);
- static PyObject *
- os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(mode), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "mode", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "lchmod",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- path_t path = PATH_T_INITIALIZE_P("lchmod", "path", 0, 0, 0, 0);
- int mode;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- mode = _PyLong_AsInt(args[1]);
- if (mode == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_lchmod_impl(module, &path, mode);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(HAVE_LCHMOD) */
- #if defined(HAVE_CHFLAGS)
- PyDoc_STRVAR(os_chflags__doc__,
- "chflags($module, /, path, flags, follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Set file flags.\n"
- "\n"
- "If follow_symlinks is False, and the last element of the path is a symbolic\n"
- " link, chflags will change flags on the symbolic link itself instead of the\n"
- " file the link points to.\n"
- "follow_symlinks may not be implemented on your platform. If it is\n"
- "unavailable, using it will raise a NotImplementedError.");
- #define OS_CHFLAGS_METHODDEF \
- {"chflags", _PyCFunction_CAST(os_chflags), METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
- static PyObject *
- os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
- int follow_symlinks);
- static PyObject *
- os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "chflags",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
- path_t path = PATH_T_INITIALIZE_P("chflags", "path", 0, 0, 0, 0);
- unsigned long flags;
- int follow_symlinks = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!PyLong_Check(args[1])) {
- _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]);
- goto exit;
- }
- flags = PyLong_AsUnsignedLongMask(args[1]);
- if (!noptargs) {
- goto skip_optional_pos;
- }
- follow_symlinks = PyObject_IsTrue(args[2]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_pos:
- return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(HAVE_CHFLAGS) */
- #if defined(HAVE_LCHFLAGS)
- PyDoc_STRVAR(os_lchflags__doc__,
- "lchflags($module, /, path, flags)\n"
- "--\n"
- "\n"
- "Set file flags.\n"
- "\n"
- "This function will not follow symbolic links.\n"
- "Equivalent to chflags(path, flags, follow_symlinks=False).");
- #define OS_LCHFLAGS_METHODDEF \
- {"lchflags", _PyCFunction_CAST(os_lchflags), METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
- static PyObject *
- os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
- static PyObject *
- os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(flags), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "flags", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "lchflags",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- path_t path = PATH_T_INITIALIZE_P("lchflags", "path", 0, 0, 0, 0);
- unsigned long flags;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!PyLong_Check(args[1])) {
- _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]);
- goto exit;
- }
- flags = PyLong_AsUnsignedLongMask(args[1]);
- return_value = os_lchflags_impl(module, &path, flags);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(HAVE_LCHFLAGS) */
- #if defined(HAVE_CHROOT)
- PyDoc_STRVAR(os_chroot__doc__,
- "chroot($module, /, path)\n"
- "--\n"
- "\n"
- "Change root directory to path.");
- #define OS_CHROOT_METHODDEF \
- {"chroot", _PyCFunction_CAST(os_chroot), METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
- static PyObject *
- os_chroot_impl(PyObject *module, path_t *path);
- static PyObject *
- os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "chroot",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t path = PATH_T_INITIALIZE_P("chroot", "path", 0, 0, 0, 0);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- return_value = os_chroot_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(HAVE_CHROOT) */
- #if defined(HAVE_FSYNC)
- PyDoc_STRVAR(os_fsync__doc__,
- "fsync($module, /, fd)\n"
- "--\n"
- "\n"
- "Force write of fd to disk.");
- #define OS_FSYNC_METHODDEF \
- {"fsync", _PyCFunction_CAST(os_fsync), METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
- static PyObject *
- os_fsync_impl(PyObject *module, int fd);
- static PyObject *
- os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "fsync",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int fd;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
- goto exit;
- }
- return_value = os_fsync_impl(module, fd);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_FSYNC) */
- #if defined(HAVE_SYNC)
- PyDoc_STRVAR(os_sync__doc__,
- "sync($module, /)\n"
- "--\n"
- "\n"
- "Force write of everything to disk.");
- #define OS_SYNC_METHODDEF \
- {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
- static PyObject *
- os_sync_impl(PyObject *module);
- static PyObject *
- os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_sync_impl(module);
- }
- #endif /* defined(HAVE_SYNC) */
- #if defined(HAVE_FDATASYNC)
- PyDoc_STRVAR(os_fdatasync__doc__,
- "fdatasync($module, /, fd)\n"
- "--\n"
- "\n"
- "Force write of fd to disk without forcing update of metadata.");
- #define OS_FDATASYNC_METHODDEF \
- {"fdatasync", _PyCFunction_CAST(os_fdatasync), METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
- static PyObject *
- os_fdatasync_impl(PyObject *module, int fd);
- static PyObject *
- os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "fdatasync",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int fd;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
- goto exit;
- }
- return_value = os_fdatasync_impl(module, fd);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_FDATASYNC) */
- #if defined(HAVE_CHOWN)
- PyDoc_STRVAR(os_chown__doc__,
- "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Change the owner and group id of path to the numeric uid and gid.\\\n"
- "\n"
- " path\n"
- " Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n"
- " dir_fd\n"
- " If not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that\n"
- " directory.\n"
- " follow_symlinks\n"
- " If False, and the last element of the path is a symbolic link,\n"
- " stat will examine the symbolic link itself instead of the file\n"
- " the link points to.\n"
- "\n"
- "path may always be specified as a string.\n"
- "On some platforms, path may also be specified as an open file descriptor.\n"
- " If this functionality is unavailable, using it raises an exception.\n"
- "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that directory.\n"
- "If follow_symlinks is False, and the last element of the path is a symbolic\n"
- " link, chown will modify the symbolic link itself instead of the file the\n"
- " link points to.\n"
- "It is an error to use dir_fd or follow_symlinks when specifying path as\n"
- " an open file descriptor.\n"
- "dir_fd and follow_symlinks may not be implemented on your platform.\n"
- " If they are unavailable, using them will raise a NotImplementedError.");
- #define OS_CHOWN_METHODDEF \
- {"chown", _PyCFunction_CAST(os_chown), METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
- static PyObject *
- os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
- int dir_fd, int follow_symlinks);
- static PyObject *
- os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 5
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "chown",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[5];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
- path_t path = PATH_T_INITIALIZE_P("chown", "path", 0, 0, 0, PATH_HAVE_FCHOWN);
- uid_t uid;
- gid_t gid;
- int dir_fd = DEFAULT_DIR_FD;
- int follow_symlinks = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!_Py_Uid_Converter(args[1], &uid)) {
- goto exit;
- }
- if (!_Py_Gid_Converter(args[2], &gid)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (args[3]) {
- if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- follow_symlinks = PyObject_IsTrue(args[4]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(HAVE_CHOWN) */
- #if defined(HAVE_FCHOWN)
- PyDoc_STRVAR(os_fchown__doc__,
- "fchown($module, /, fd, uid, gid)\n"
- "--\n"
- "\n"
- "Change the owner and group id of the file specified by file descriptor.\n"
- "\n"
- "Equivalent to os.chown(fd, uid, gid).");
- #define OS_FCHOWN_METHODDEF \
- {"fchown", _PyCFunction_CAST(os_fchown), METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
- static PyObject *
- os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
- static PyObject *
- os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(fd), &_Py_ID(uid), &_Py_ID(gid), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "fchown",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- int fd;
- uid_t uid;
- gid_t gid;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!_Py_Uid_Converter(args[1], &uid)) {
- goto exit;
- }
- if (!_Py_Gid_Converter(args[2], &gid)) {
- goto exit;
- }
- return_value = os_fchown_impl(module, fd, uid, gid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_FCHOWN) */
- #if defined(HAVE_LCHOWN)
- PyDoc_STRVAR(os_lchown__doc__,
- "lchown($module, /, path, uid, gid)\n"
- "--\n"
- "\n"
- "Change the owner and group id of path to the numeric uid and gid.\n"
- "\n"
- "This function will not follow symbolic links.\n"
- "Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
- #define OS_LCHOWN_METHODDEF \
- {"lchown", _PyCFunction_CAST(os_lchown), METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
- static PyObject *
- os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
- static PyObject *
- os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "uid", "gid", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "lchown",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- path_t path = PATH_T_INITIALIZE_P("lchown", "path", 0, 0, 0, 0);
- uid_t uid;
- gid_t gid;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!_Py_Uid_Converter(args[1], &uid)) {
- goto exit;
- }
- if (!_Py_Gid_Converter(args[2], &gid)) {
- goto exit;
- }
- return_value = os_lchown_impl(module, &path, uid, gid);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(HAVE_LCHOWN) */
- PyDoc_STRVAR(os_getcwd__doc__,
- "getcwd($module, /)\n"
- "--\n"
- "\n"
- "Return a unicode string representing the current working directory.");
- #define OS_GETCWD_METHODDEF \
- {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
- static PyObject *
- os_getcwd_impl(PyObject *module);
- static PyObject *
- os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getcwd_impl(module);
- }
- PyDoc_STRVAR(os_getcwdb__doc__,
- "getcwdb($module, /)\n"
- "--\n"
- "\n"
- "Return a bytes string representing the current working directory.");
- #define OS_GETCWDB_METHODDEF \
- {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
- static PyObject *
- os_getcwdb_impl(PyObject *module);
- static PyObject *
- os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getcwdb_impl(module);
- }
- #if defined(HAVE_LINK)
- PyDoc_STRVAR(os_link__doc__,
- "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
- " follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Create a hard link to a file.\n"
- "\n"
- "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
- " descriptor open to a directory, and the respective path string (src or dst)\n"
- " should be relative; the path will then be relative to that directory.\n"
- "If follow_symlinks is False, and the last element of src is a symbolic\n"
- " link, link will create a link to the symbolic link itself instead of the\n"
- " file the link points to.\n"
- "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
- " platform. If they are unavailable, using them will raise a\n"
- " NotImplementedError.");
- #define OS_LINK_METHODDEF \
- {"link", _PyCFunction_CAST(os_link), METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
- static PyObject *
- os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
- int dst_dir_fd, int follow_symlinks);
- static PyObject *
- os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 5
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "link",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[5];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
- path_t src = PATH_T_INITIALIZE_P("link", "src", 0, 0, 0, 0);
- path_t dst = PATH_T_INITIALIZE_P("link", "dst", 0, 0, 0, 0);
- int src_dir_fd = DEFAULT_DIR_FD;
- int dst_dir_fd = DEFAULT_DIR_FD;
- int follow_symlinks = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &src)) {
- goto exit;
- }
- if (!path_converter(args[1], &dst)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (args[2]) {
- if (!dir_fd_converter(args[2], &src_dir_fd)) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[3]) {
- if (!dir_fd_converter(args[3], &dst_dir_fd)) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- follow_symlinks = PyObject_IsTrue(args[4]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
- exit:
- /* Cleanup for src */
- path_cleanup(&src);
- /* Cleanup for dst */
- path_cleanup(&dst);
- return return_value;
- }
- #endif /* defined(HAVE_LINK) */
- PyDoc_STRVAR(os_listdir__doc__,
- "listdir($module, /, path=None)\n"
- "--\n"
- "\n"
- "Return a list containing the names of the files in the directory.\n"
- "\n"
- "path can be specified as either str, bytes, or a path-like object. If path is bytes,\n"
- " the filenames returned will also be bytes; in all other circumstances\n"
- " the filenames returned will be str.\n"
- "If path is None, uses the path=\'.\'.\n"
- "On some platforms, path may also be specified as an open file descriptor;\\\n"
- " the file descriptor must refer to a directory.\n"
- " If this functionality is unavailable, using it raises NotImplementedError.\n"
- "\n"
- "The list is in arbitrary order. It does not include the special\n"
- "entries \'.\' and \'..\' even if they are present in the directory.");
- #define OS_LISTDIR_METHODDEF \
- {"listdir", _PyCFunction_CAST(os_listdir), METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
- static PyObject *
- os_listdir_impl(PyObject *module, path_t *path);
- static PyObject *
- os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "listdir",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
- path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- skip_optional_pos:
- return_value = os_listdir_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os_listdrives__doc__,
- "listdrives($module, /)\n"
- "--\n"
- "\n"
- "Return a list containing the names of drives in the system.\n"
- "\n"
- "A drive name typically looks like \'C:\\\\\'.");
- #define OS_LISTDRIVES_METHODDEF \
- {"listdrives", (PyCFunction)os_listdrives, METH_NOARGS, os_listdrives__doc__},
- static PyObject *
- os_listdrives_impl(PyObject *module);
- static PyObject *
- os_listdrives(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_listdrives_impl(module);
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os_listvolumes__doc__,
- "listvolumes($module, /)\n"
- "--\n"
- "\n"
- "Return a list containing the volumes in the system.\n"
- "\n"
- "Volumes are typically represented as a GUID path.");
- #define OS_LISTVOLUMES_METHODDEF \
- {"listvolumes", (PyCFunction)os_listvolumes, METH_NOARGS, os_listvolumes__doc__},
- static PyObject *
- os_listvolumes_impl(PyObject *module);
- static PyObject *
- os_listvolumes(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_listvolumes_impl(module);
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os_listmounts__doc__,
- "listmounts($module, /, volume)\n"
- "--\n"
- "\n"
- "Return a list containing mount points for a particular volume.\n"
- "\n"
- "\'volume\' should be a GUID path as returned from os.listvolumes.");
- #define OS_LISTMOUNTS_METHODDEF \
- {"listmounts", _PyCFunction_CAST(os_listmounts), METH_FASTCALL|METH_KEYWORDS, os_listmounts__doc__},
- static PyObject *
- os_listmounts_impl(PyObject *module, path_t *volume);
- static PyObject *
- os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(volume), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"volume", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "listmounts",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t volume = PATH_T_INITIALIZE_P("listmounts", "volume", 0, 0, 0, 0);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &volume)) {
- goto exit;
- }
- return_value = os_listmounts_impl(module, &volume);
- exit:
- /* Cleanup for volume */
- path_cleanup(&volume);
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os__path_isdevdrive__doc__,
- "_path_isdevdrive($module, /, path)\n"
- "--\n"
- "\n"
- "Determines whether the specified path is on a Windows Dev Drive.");
- #define OS__PATH_ISDEVDRIVE_METHODDEF \
- {"_path_isdevdrive", _PyCFunction_CAST(os__path_isdevdrive), METH_FASTCALL|METH_KEYWORDS, os__path_isdevdrive__doc__},
- static PyObject *
- os__path_isdevdrive_impl(PyObject *module, path_t *path);
- static PyObject *
- os__path_isdevdrive(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_path_isdevdrive",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t path = PATH_T_INITIALIZE_P("_path_isdevdrive", "path", 0, 0, 0, 0);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- return_value = os__path_isdevdrive_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os__getfullpathname__doc__,
- "_getfullpathname($module, path, /)\n"
- "--\n"
- "\n");
- #define OS__GETFULLPATHNAME_METHODDEF \
- {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
- static PyObject *
- os__getfullpathname_impl(PyObject *module, path_t *path);
- static PyObject *
- os__getfullpathname(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- path_t path = PATH_T_INITIALIZE_P("_getfullpathname", "path", 0, 0, 0, 0);
- if (!path_converter(arg, &path)) {
- goto exit;
- }
- return_value = os__getfullpathname_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os__getfinalpathname__doc__,
- "_getfinalpathname($module, path, /)\n"
- "--\n"
- "\n"
- "A helper function for samepath on windows.");
- #define OS__GETFINALPATHNAME_METHODDEF \
- {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
- static PyObject *
- os__getfinalpathname_impl(PyObject *module, path_t *path);
- static PyObject *
- os__getfinalpathname(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- path_t path = PATH_T_INITIALIZE_P("_getfinalpathname", "path", 0, 0, 0, 0);
- if (!path_converter(arg, &path)) {
- goto exit;
- }
- return_value = os__getfinalpathname_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os__getvolumepathname__doc__,
- "_getvolumepathname($module, /, path)\n"
- "--\n"
- "\n"
- "A helper function for ismount on Win32.");
- #define OS__GETVOLUMEPATHNAME_METHODDEF \
- {"_getvolumepathname", _PyCFunction_CAST(os__getvolumepathname), METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
- static PyObject *
- os__getvolumepathname_impl(PyObject *module, path_t *path);
- static PyObject *
- os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_getvolumepathname",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t path = PATH_T_INITIALIZE_P("_getvolumepathname", "path", 0, 0, 0, 0);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- return_value = os__getvolumepathname_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os__path_splitroot__doc__,
- "_path_splitroot($module, /, path)\n"
- "--\n"
- "\n"
- "Removes everything after the root on Win32.");
- #define OS__PATH_SPLITROOT_METHODDEF \
- {"_path_splitroot", _PyCFunction_CAST(os__path_splitroot), METH_FASTCALL|METH_KEYWORDS, os__path_splitroot__doc__},
- static PyObject *
- os__path_splitroot_impl(PyObject *module, path_t *path);
- static PyObject *
- os__path_splitroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_path_splitroot",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- return_value = os__path_splitroot_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os__path_exists__doc__,
- "_path_exists($module, path, /)\n"
- "--\n"
- "\n"
- "Test whether a path exists. Returns False for broken symbolic links.");
- #define OS__PATH_EXISTS_METHODDEF \
- {"_path_exists", (PyCFunction)os__path_exists, METH_O, os__path_exists__doc__},
- static int
- os__path_exists_impl(PyObject *module, path_t *path);
- static PyObject *
- os__path_exists(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1);
- int _return_value;
- if (!path_converter(arg, &path)) {
- goto exit;
- }
- _return_value = os__path_exists_impl(module, &path);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os__path_isdir__doc__,
- "_path_isdir($module, /, s)\n"
- "--\n"
- "\n"
- "Return true if the pathname refers to an existing directory.");
- #define OS__PATH_ISDIR_METHODDEF \
- {"_path_isdir", _PyCFunction_CAST(os__path_isdir), METH_FASTCALL|METH_KEYWORDS, os__path_isdir__doc__},
- static int
- os__path_isdir_impl(PyObject *module, path_t *path);
- static PyObject *
- os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(s), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"s", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_path_isdir",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1);
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- _return_value = os__path_isdir_impl(module, &path);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os__path_isfile__doc__,
- "_path_isfile($module, /, path)\n"
- "--\n"
- "\n"
- "Test whether a path is a regular file");
- #define OS__PATH_ISFILE_METHODDEF \
- {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__},
- static int
- os__path_isfile_impl(PyObject *module, path_t *path);
- static PyObject *
- os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_path_isfile",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1);
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- _return_value = os__path_isfile_impl(module, &path);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os__path_islink__doc__,
- "_path_islink($module, /, path)\n"
- "--\n"
- "\n"
- "Test whether a path is a symbolic link");
- #define OS__PATH_ISLINK_METHODDEF \
- {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__},
- static int
- os__path_islink_impl(PyObject *module, path_t *path);
- static PyObject *
- os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_path_islink",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1);
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- _return_value = os__path_islink_impl(module, &path);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- PyDoc_STRVAR(os__path_normpath__doc__,
- "_path_normpath($module, /, path)\n"
- "--\n"
- "\n"
- "Normalize path, eliminating double slashes, etc.");
- #define OS__PATH_NORMPATH_METHODDEF \
- {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__},
- static PyObject *
- os__path_normpath_impl(PyObject *module, path_t *path);
- static PyObject *
- os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_path_normpath",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- return_value = os__path_normpath_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- PyDoc_STRVAR(os_mkdir__doc__,
- "mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
- "--\n"
- "\n"
- "Create a directory.\n"
- "\n"
- "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that directory.\n"
- "dir_fd may not be implemented on your platform.\n"
- " If it is unavailable, using it will raise a NotImplementedError.\n"
- "\n"
- "The mode argument is ignored on Windows. Where it is used, the current umask\n"
- "value is first masked out.");
- #define OS_MKDIR_METHODDEF \
- {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
- static PyObject *
- os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
- static PyObject *
- os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "mkdir",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0);
- int mode = 511;
- int dir_fd = DEFAULT_DIR_FD;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[1]) {
- mode = _PyLong_AsInt(args[1]);
- if (mode == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- skip_optional_pos:
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_mkdir_impl(module, &path, mode, dir_fd);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #if defined(HAVE_NICE)
- PyDoc_STRVAR(os_nice__doc__,
- "nice($module, increment, /)\n"
- "--\n"
- "\n"
- "Add increment to the priority of process and return the new priority.");
- #define OS_NICE_METHODDEF \
- {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
- static PyObject *
- os_nice_impl(PyObject *module, int increment);
- static PyObject *
- os_nice(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int increment;
- increment = _PyLong_AsInt(arg);
- if (increment == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_nice_impl(module, increment);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_NICE) */
- #if defined(HAVE_GETPRIORITY)
- PyDoc_STRVAR(os_getpriority__doc__,
- "getpriority($module, /, which, who)\n"
- "--\n"
- "\n"
- "Return program scheduling priority.");
- #define OS_GETPRIORITY_METHODDEF \
- {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
- static PyObject *
- os_getpriority_impl(PyObject *module, int which, int who);
- static PyObject *
- os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(which), &_Py_ID(who), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"which", "who", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "getpriority",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- int which;
- int who;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- which = _PyLong_AsInt(args[0]);
- if (which == -1 && PyErr_Occurred()) {
- goto exit;
- }
- who = _PyLong_AsInt(args[1]);
- if (who == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_getpriority_impl(module, which, who);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_GETPRIORITY) */
- #if defined(HAVE_SETPRIORITY)
- PyDoc_STRVAR(os_setpriority__doc__,
- "setpriority($module, /, which, who, priority)\n"
- "--\n"
- "\n"
- "Set program scheduling priority.");
- #define OS_SETPRIORITY_METHODDEF \
- {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
- static PyObject *
- os_setpriority_impl(PyObject *module, int which, int who, int priority);
- static PyObject *
- os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"which", "who", "priority", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "setpriority",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- int which;
- int who;
- int priority;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- which = _PyLong_AsInt(args[0]);
- if (which == -1 && PyErr_Occurred()) {
- goto exit;
- }
- who = _PyLong_AsInt(args[1]);
- if (who == -1 && PyErr_Occurred()) {
- goto exit;
- }
- priority = _PyLong_AsInt(args[2]);
- if (priority == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_setpriority_impl(module, which, who, priority);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SETPRIORITY) */
- PyDoc_STRVAR(os_rename__doc__,
- "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
- "--\n"
- "\n"
- "Rename a file or directory.\n"
- "\n"
- "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
- " descriptor open to a directory, and the respective path string (src or dst)\n"
- " should be relative; the path will then be relative to that directory.\n"
- "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
- " If they are unavailable, using them will raise a NotImplementedError.");
- #define OS_RENAME_METHODDEF \
- {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
- static PyObject *
- os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
- int dst_dir_fd);
- static PyObject *
- os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 4
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "rename",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[4];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
- path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0);
- path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0);
- int src_dir_fd = DEFAULT_DIR_FD;
- int dst_dir_fd = DEFAULT_DIR_FD;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &src)) {
- goto exit;
- }
- if (!path_converter(args[1], &dst)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (args[2]) {
- if (!dir_fd_converter(args[2], &src_dir_fd)) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (!dir_fd_converter(args[3], &dst_dir_fd)) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
- exit:
- /* Cleanup for src */
- path_cleanup(&src);
- /* Cleanup for dst */
- path_cleanup(&dst);
- return return_value;
- }
- PyDoc_STRVAR(os_replace__doc__,
- "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
- "--\n"
- "\n"
- "Rename a file or directory, overwriting the destination.\n"
- "\n"
- "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
- " descriptor open to a directory, and the respective path string (src or dst)\n"
- " should be relative; the path will then be relative to that directory.\n"
- "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
- " If they are unavailable, using them will raise a NotImplementedError.");
- #define OS_REPLACE_METHODDEF \
- {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
- static PyObject *
- os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
- int dst_dir_fd);
- static PyObject *
- os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 4
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "replace",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[4];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
- path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0);
- path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0);
- int src_dir_fd = DEFAULT_DIR_FD;
- int dst_dir_fd = DEFAULT_DIR_FD;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &src)) {
- goto exit;
- }
- if (!path_converter(args[1], &dst)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (args[2]) {
- if (!dir_fd_converter(args[2], &src_dir_fd)) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (!dir_fd_converter(args[3], &dst_dir_fd)) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
- exit:
- /* Cleanup for src */
- path_cleanup(&src);
- /* Cleanup for dst */
- path_cleanup(&dst);
- return return_value;
- }
- PyDoc_STRVAR(os_rmdir__doc__,
- "rmdir($module, /, path, *, dir_fd=None)\n"
- "--\n"
- "\n"
- "Remove a directory.\n"
- "\n"
- "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that directory.\n"
- "dir_fd may not be implemented on your platform.\n"
- " If it is unavailable, using it will raise a NotImplementedError.");
- #define OS_RMDIR_METHODDEF \
- {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
- static PyObject *
- os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
- static PyObject *
- os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "dir_fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "rmdir",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0);
- int dir_fd = DEFAULT_DIR_FD;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_rmdir_impl(module, &path, dir_fd);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
- PyDoc_STRVAR(os_system__doc__,
- "system($module, /, command)\n"
- "--\n"
- "\n"
- "Execute the command in a subshell.");
- #define OS_SYSTEM_METHODDEF \
- {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
- static long
- os_system_impl(PyObject *module, const Py_UNICODE *command);
- static PyObject *
- os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(command), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"command", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "system",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- const Py_UNICODE *command = NULL;
- long _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("system", "argument 'command'", "str", args[0]);
- goto exit;
- }
- command = PyUnicode_AsWideCharString(args[0], NULL);
- if (command == NULL) {
- goto exit;
- }
- _return_value = os_system_impl(module, command);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromLong(_return_value);
- exit:
- /* Cleanup for command */
- PyMem_Free((void *)command);
- return return_value;
- }
- #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
- #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
- PyDoc_STRVAR(os_system__doc__,
- "system($module, /, command)\n"
- "--\n"
- "\n"
- "Execute the command in a subshell.");
- #define OS_SYSTEM_METHODDEF \
- {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
- static long
- os_system_impl(PyObject *module, PyObject *command);
- static PyObject *
- os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(command), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"command", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "system",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- PyObject *command = NULL;
- long _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!PyUnicode_FSConverter(args[0], &command)) {
- goto exit;
- }
- _return_value = os_system_impl(module, command);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromLong(_return_value);
- exit:
- /* Cleanup for command */
- Py_XDECREF(command);
- return return_value;
- }
- #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
- #if defined(HAVE_UMASK)
- PyDoc_STRVAR(os_umask__doc__,
- "umask($module, mask, /)\n"
- "--\n"
- "\n"
- "Set the current numeric umask and return the previous umask.");
- #define OS_UMASK_METHODDEF \
- {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
- static PyObject *
- os_umask_impl(PyObject *module, int mask);
- static PyObject *
- os_umask(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int mask;
- mask = _PyLong_AsInt(arg);
- if (mask == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_umask_impl(module, mask);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_UMASK) */
- PyDoc_STRVAR(os_unlink__doc__,
- "unlink($module, /, path, *, dir_fd=None)\n"
- "--\n"
- "\n"
- "Remove a file (same as remove()).\n"
- "\n"
- "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that directory.\n"
- "dir_fd may not be implemented on your platform.\n"
- " If it is unavailable, using it will raise a NotImplementedError.");
- #define OS_UNLINK_METHODDEF \
- {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
- static PyObject *
- os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
- static PyObject *
- os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "dir_fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "unlink",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0);
- int dir_fd = DEFAULT_DIR_FD;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_unlink_impl(module, &path, dir_fd);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- PyDoc_STRVAR(os_remove__doc__,
- "remove($module, /, path, *, dir_fd=None)\n"
- "--\n"
- "\n"
- "Remove a file (same as unlink()).\n"
- "\n"
- "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that directory.\n"
- "dir_fd may not be implemented on your platform.\n"
- " If it is unavailable, using it will raise a NotImplementedError.");
- #define OS_REMOVE_METHODDEF \
- {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
- static PyObject *
- os_remove_impl(PyObject *module, path_t *path, int dir_fd);
- static PyObject *
- os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "dir_fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "remove",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0);
- int dir_fd = DEFAULT_DIR_FD;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_remove_impl(module, &path, dir_fd);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #if defined(HAVE_UNAME)
- PyDoc_STRVAR(os_uname__doc__,
- "uname($module, /)\n"
- "--\n"
- "\n"
- "Return an object identifying the current operating system.\n"
- "\n"
- "The object behaves like a named tuple with the following fields:\n"
- " (sysname, nodename, release, version, machine)");
- #define OS_UNAME_METHODDEF \
- {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
- static PyObject *
- os_uname_impl(PyObject *module);
- static PyObject *
- os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_uname_impl(module);
- }
- #endif /* defined(HAVE_UNAME) */
- PyDoc_STRVAR(os_utime__doc__,
- "utime($module, /, path, times=None, *, ns=<unrepresentable>,\n"
- " dir_fd=None, follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Set the access and modified time of path.\n"
- "\n"
- "path may always be specified as a string.\n"
- "On some platforms, path may also be specified as an open file descriptor.\n"
- " If this functionality is unavailable, using it raises an exception.\n"
- "\n"
- "If times is not None, it must be a tuple (atime, mtime);\n"
- " atime and mtime should be expressed as float seconds since the epoch.\n"
- "If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
- " atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
- " since the epoch.\n"
- "If times is None and ns is unspecified, utime uses the current time.\n"
- "Specifying tuples for both times and ns is an error.\n"
- "\n"
- "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that directory.\n"
- "If follow_symlinks is False, and the last element of the path is a symbolic\n"
- " link, utime will modify the symbolic link itself instead of the file the\n"
- " link points to.\n"
- "It is an error to use dir_fd or follow_symlinks when specifying path\n"
- " as an open file descriptor.\n"
- "dir_fd and follow_symlinks may not be available on your platform.\n"
- " If they are unavailable, using them will raise a NotImplementedError.");
- #define OS_UTIME_METHODDEF \
- {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
- static PyObject *
- os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
- int dir_fd, int follow_symlinks);
- static PyObject *
- os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 5
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "utime",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[5];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD);
- PyObject *times = Py_None;
- PyObject *ns = NULL;
- int dir_fd = DEFAULT_DIR_FD;
- int follow_symlinks = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[1]) {
- times = args[1];
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- skip_optional_pos:
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (args[2]) {
- ns = args[2];
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[3]) {
- if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- follow_symlinks = PyObject_IsTrue(args[4]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- PyDoc_STRVAR(os__exit__doc__,
- "_exit($module, /, status)\n"
- "--\n"
- "\n"
- "Exit to the system with specified status, without normal exit processing.");
- #define OS__EXIT_METHODDEF \
- {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
- static PyObject *
- os__exit_impl(PyObject *module, int status);
- static PyObject *
- os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(status), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"status", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_exit",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int status;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- status = _PyLong_AsInt(args[0]);
- if (status == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os__exit_impl(module, status);
- exit:
- return return_value;
- }
- #if defined(HAVE_EXECV)
- PyDoc_STRVAR(os_execv__doc__,
- "execv($module, path, argv, /)\n"
- "--\n"
- "\n"
- "Execute an executable path with arguments, replacing current process.\n"
- "\n"
- " path\n"
- " Path of executable file.\n"
- " argv\n"
- " Tuple or list of strings.");
- #define OS_EXECV_METHODDEF \
- {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__},
- static PyObject *
- os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
- static PyObject *
- os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0);
- PyObject *argv;
- if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- argv = args[1];
- return_value = os_execv_impl(module, &path, argv);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(HAVE_EXECV) */
- #if defined(HAVE_EXECV)
- PyDoc_STRVAR(os_execve__doc__,
- "execve($module, /, path, argv, env)\n"
- "--\n"
- "\n"
- "Execute an executable path with arguments, replacing current process.\n"
- "\n"
- " path\n"
- " Path of executable file.\n"
- " argv\n"
- " Tuple or list of strings.\n"
- " env\n"
- " Dictionary of strings mapping to strings.");
- #define OS_EXECVE_METHODDEF \
- {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
- static PyObject *
- os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
- static PyObject *
- os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "argv", "env", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "execve",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE);
- PyObject *argv;
- PyObject *env;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- argv = args[1];
- env = args[2];
- return_value = os_execve_impl(module, &path, argv, env);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(HAVE_EXECV) */
- #if defined(HAVE_POSIX_SPAWN)
- PyDoc_STRVAR(os_posix_spawn__doc__,
- "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
- " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
- " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
- "--\n"
- "\n"
- "Execute the program specified by path in a new process.\n"
- "\n"
- " path\n"
- " Path of executable file.\n"
- " argv\n"
- " Tuple or list of strings.\n"
- " env\n"
- " Dictionary of strings mapping to strings.\n"
- " file_actions\n"
- " A sequence of file action tuples.\n"
- " setpgroup\n"
- " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
- " resetids\n"
- " If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n"
- " setsid\n"
- " If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
- " setsigmask\n"
- " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
- " setsigdef\n"
- " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
- " scheduler\n"
- " A tuple with the scheduler policy (optional) and parameters.");
- #define OS_POSIX_SPAWN_METHODDEF \
- {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
- static PyObject *
- os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
- PyObject *env, PyObject *file_actions,
- PyObject *setpgroup, int resetids, int setsid,
- PyObject *setsigmask, PyObject *setsigdef,
- PyObject *scheduler);
- static PyObject *
- os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 7
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "posix_spawn",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[10];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
- path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0);
- PyObject *argv;
- PyObject *env;
- PyObject *file_actions = NULL;
- PyObject *setpgroup = NULL;
- int resetids = 0;
- int setsid = 0;
- PyObject *setsigmask = NULL;
- PyObject *setsigdef = NULL;
- PyObject *scheduler = NULL;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- argv = args[1];
- env = args[2];
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (args[3]) {
- file_actions = args[3];
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[4]) {
- setpgroup = args[4];
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[5]) {
- resetids = PyObject_IsTrue(args[5]);
- if (resetids < 0) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[6]) {
- setsid = PyObject_IsTrue(args[6]);
- if (setsid < 0) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[7]) {
- setsigmask = args[7];
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[8]) {
- setsigdef = args[8];
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- scheduler = args[9];
- skip_optional_kwonly:
- return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(HAVE_POSIX_SPAWN) */
- #if defined(HAVE_POSIX_SPAWNP)
- PyDoc_STRVAR(os_posix_spawnp__doc__,
- "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n"
- " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
- " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
- "--\n"
- "\n"
- "Execute the program specified by path in a new process.\n"
- "\n"
- " path\n"
- " Path of executable file.\n"
- " argv\n"
- " Tuple or list of strings.\n"
- " env\n"
- " Dictionary of strings mapping to strings.\n"
- " file_actions\n"
- " A sequence of file action tuples.\n"
- " setpgroup\n"
- " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
- " resetids\n"
- " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
- " setsid\n"
- " If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
- " setsigmask\n"
- " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
- " setsigdef\n"
- " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
- " scheduler\n"
- " A tuple with the scheduler policy (optional) and parameters.");
- #define OS_POSIX_SPAWNP_METHODDEF \
- {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__},
- static PyObject *
- os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
- PyObject *env, PyObject *file_actions,
- PyObject *setpgroup, int resetids, int setsid,
- PyObject *setsigmask, PyObject *setsigdef,
- PyObject *scheduler);
- static PyObject *
- os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 7
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "posix_spawnp",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[10];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
- path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0);
- PyObject *argv;
- PyObject *env;
- PyObject *file_actions = NULL;
- PyObject *setpgroup = NULL;
- int resetids = 0;
- int setsid = 0;
- PyObject *setsigmask = NULL;
- PyObject *setsigdef = NULL;
- PyObject *scheduler = NULL;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- argv = args[1];
- env = args[2];
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (args[3]) {
- file_actions = args[3];
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[4]) {
- setpgroup = args[4];
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[5]) {
- resetids = PyObject_IsTrue(args[5]);
- if (resetids < 0) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[6]) {
- setsid = PyObject_IsTrue(args[6]);
- if (setsid < 0) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[7]) {
- setsigmask = args[7];
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[8]) {
- setsigdef = args[8];
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- scheduler = args[9];
- skip_optional_kwonly:
- return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(HAVE_POSIX_SPAWNP) */
- #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
- PyDoc_STRVAR(os_spawnv__doc__,
- "spawnv($module, mode, path, argv, /)\n"
- "--\n"
- "\n"
- "Execute the program specified by path in a new process.\n"
- "\n"
- " mode\n"
- " Mode of process creation.\n"
- " path\n"
- " Path of executable file.\n"
- " argv\n"
- " Tuple or list of strings.");
- #define OS_SPAWNV_METHODDEF \
- {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__},
- static PyObject *
- os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
- static PyObject *
- os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int mode;
- path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0);
- PyObject *argv;
- if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
- goto exit;
- }
- mode = _PyLong_AsInt(args[0]);
- if (mode == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!path_converter(args[1], &path)) {
- goto exit;
- }
- argv = args[2];
- return_value = os_spawnv_impl(module, mode, &path, argv);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
- #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
- PyDoc_STRVAR(os_spawnve__doc__,
- "spawnve($module, mode, path, argv, env, /)\n"
- "--\n"
- "\n"
- "Execute the program specified by path in a new process.\n"
- "\n"
- " mode\n"
- " Mode of process creation.\n"
- " path\n"
- " Path of executable file.\n"
- " argv\n"
- " Tuple or list of strings.\n"
- " env\n"
- " Dictionary of strings mapping to strings.");
- #define OS_SPAWNVE_METHODDEF \
- {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__},
- static PyObject *
- os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
- PyObject *env);
- static PyObject *
- os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int mode;
- path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0);
- PyObject *argv;
- PyObject *env;
- if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
- goto exit;
- }
- mode = _PyLong_AsInt(args[0]);
- if (mode == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!path_converter(args[1], &path)) {
- goto exit;
- }
- argv = args[2];
- env = args[3];
- return_value = os_spawnve_impl(module, mode, &path, argv, env);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
- #if defined(HAVE_FORK)
- PyDoc_STRVAR(os_register_at_fork__doc__,
- "register_at_fork($module, /, *, before=<unrepresentable>,\n"
- " after_in_child=<unrepresentable>,\n"
- " after_in_parent=<unrepresentable>)\n"
- "--\n"
- "\n"
- "Register callables to be called when forking a new process.\n"
- "\n"
- " before\n"
- " A callable to be called in the parent before the fork() syscall.\n"
- " after_in_child\n"
- " A callable to be called in the child after fork().\n"
- " after_in_parent\n"
- " A callable to be called in the parent after fork().\n"
- "\n"
- "\'before\' callbacks are called in reverse order.\n"
- "\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
- #define OS_REGISTER_AT_FORK_METHODDEF \
- {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
- static PyObject *
- os_register_at_fork_impl(PyObject *module, PyObject *before,
- PyObject *after_in_child, PyObject *after_in_parent);
- static PyObject *
- os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "register_at_fork",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
- PyObject *before = NULL;
- PyObject *after_in_child = NULL;
- PyObject *after_in_parent = NULL;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (args[0]) {
- before = args[0];
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[1]) {
- after_in_child = args[1];
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- after_in_parent = args[2];
- skip_optional_kwonly:
- return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_FORK) */
- #if defined(HAVE_FORK1)
- PyDoc_STRVAR(os_fork1__doc__,
- "fork1($module, /)\n"
- "--\n"
- "\n"
- "Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
- "\n"
- "Return 0 to child process and PID of child to parent process.");
- #define OS_FORK1_METHODDEF \
- {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
- static PyObject *
- os_fork1_impl(PyObject *module);
- static PyObject *
- os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_fork1_impl(module);
- }
- #endif /* defined(HAVE_FORK1) */
- #if defined(HAVE_FORK)
- PyDoc_STRVAR(os_fork__doc__,
- "fork($module, /)\n"
- "--\n"
- "\n"
- "Fork a child process.\n"
- "\n"
- "Return 0 to child process and PID of child to parent process.");
- #define OS_FORK_METHODDEF \
- {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
- static PyObject *
- os_fork_impl(PyObject *module);
- static PyObject *
- os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_fork_impl(module);
- }
- #endif /* defined(HAVE_FORK) */
- #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
- PyDoc_STRVAR(os_sched_get_priority_max__doc__,
- "sched_get_priority_max($module, /, policy)\n"
- "--\n"
- "\n"
- "Get the maximum scheduling priority for policy.");
- #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
- {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
- static PyObject *
- os_sched_get_priority_max_impl(PyObject *module, int policy);
- static PyObject *
- os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(policy), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"policy", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "sched_get_priority_max",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int policy;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- policy = _PyLong_AsInt(args[0]);
- if (policy == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_sched_get_priority_max_impl(module, policy);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
- #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
- PyDoc_STRVAR(os_sched_get_priority_min__doc__,
- "sched_get_priority_min($module, /, policy)\n"
- "--\n"
- "\n"
- "Get the minimum scheduling priority for policy.");
- #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
- {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
- static PyObject *
- os_sched_get_priority_min_impl(PyObject *module, int policy);
- static PyObject *
- os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(policy), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"policy", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "sched_get_priority_min",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int policy;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- policy = _PyLong_AsInt(args[0]);
- if (policy == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_sched_get_priority_min_impl(module, policy);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
- #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
- PyDoc_STRVAR(os_sched_getscheduler__doc__,
- "sched_getscheduler($module, pid, /)\n"
- "--\n"
- "\n"
- "Get the scheduling policy for the process identified by pid.\n"
- "\n"
- "Passing 0 for pid returns the scheduling policy for the calling process.");
- #define OS_SCHED_GETSCHEDULER_METHODDEF \
- {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
- static PyObject *
- os_sched_getscheduler_impl(PyObject *module, pid_t pid);
- static PyObject *
- os_sched_getscheduler(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- pid_t pid;
- if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
- goto exit;
- }
- return_value = os_sched_getscheduler_impl(module, pid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
- #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM))
- PyDoc_STRVAR(os_sched_param__doc__,
- "sched_param(sched_priority)\n"
- "--\n"
- "\n"
- "Currently has only one field: sched_priority\n"
- "\n"
- " sched_priority\n"
- " A scheduling parameter.");
- static PyObject *
- os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
- static PyObject *
- os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(sched_priority), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"sched_priority", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "sched_param",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- PyObject * const *fastargs;
- Py_ssize_t nargs = PyTuple_GET_SIZE(args);
- PyObject *sched_priority;
- fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
- if (!fastargs) {
- goto exit;
- }
- sched_priority = fastargs[0];
- return_value = os_sched_param_impl(type, sched_priority);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */
- #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
- PyDoc_STRVAR(os_sched_setscheduler__doc__,
- "sched_setscheduler($module, pid, policy, param, /)\n"
- "--\n"
- "\n"
- "Set the scheduling policy for the process identified by pid.\n"
- "\n"
- "If pid is 0, the calling process is changed.\n"
- "param is an instance of sched_param.");
- #define OS_SCHED_SETSCHEDULER_METHODDEF \
- {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__},
- static PyObject *
- os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
- PyObject *param_obj);
- static PyObject *
- os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- pid_t pid;
- int policy;
- PyObject *param_obj;
- if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO:sched_setscheduler",
- &pid, &policy, ¶m_obj)) {
- goto exit;
- }
- return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
- #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
- PyDoc_STRVAR(os_sched_getparam__doc__,
- "sched_getparam($module, pid, /)\n"
- "--\n"
- "\n"
- "Returns scheduling parameters for the process identified by pid.\n"
- "\n"
- "If pid is 0, returns parameters for the calling process.\n"
- "Return value is an instance of sched_param.");
- #define OS_SCHED_GETPARAM_METHODDEF \
- {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
- static PyObject *
- os_sched_getparam_impl(PyObject *module, pid_t pid);
- static PyObject *
- os_sched_getparam(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- pid_t pid;
- if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
- goto exit;
- }
- return_value = os_sched_getparam_impl(module, pid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
- #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
- PyDoc_STRVAR(os_sched_setparam__doc__,
- "sched_setparam($module, pid, param, /)\n"
- "--\n"
- "\n"
- "Set scheduling parameters for the process identified by pid.\n"
- "\n"
- "If pid is 0, sets parameters for the calling process.\n"
- "param should be an instance of sched_param.");
- #define OS_SCHED_SETPARAM_METHODDEF \
- {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__},
- static PyObject *
- os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj);
- static PyObject *
- os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- pid_t pid;
- PyObject *param_obj;
- if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setparam",
- &pid, ¶m_obj)) {
- goto exit;
- }
- return_value = os_sched_setparam_impl(module, pid, param_obj);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
- #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
- PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
- "sched_rr_get_interval($module, pid, /)\n"
- "--\n"
- "\n"
- "Return the round-robin quantum for the process identified by pid, in seconds.\n"
- "\n"
- "Value returned is a float.");
- #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
- {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
- static double
- os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
- static PyObject *
- os_sched_rr_get_interval(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- pid_t pid;
- double _return_value;
- if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
- goto exit;
- }
- _return_value = os_sched_rr_get_interval_impl(module, pid);
- if ((_return_value == -1.0) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyFloat_FromDouble(_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
- #if defined(HAVE_SCHED_H)
- PyDoc_STRVAR(os_sched_yield__doc__,
- "sched_yield($module, /)\n"
- "--\n"
- "\n"
- "Voluntarily relinquish the CPU.");
- #define OS_SCHED_YIELD_METHODDEF \
- {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
- static PyObject *
- os_sched_yield_impl(PyObject *module);
- static PyObject *
- os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_sched_yield_impl(module);
- }
- #endif /* defined(HAVE_SCHED_H) */
- #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
- PyDoc_STRVAR(os_sched_setaffinity__doc__,
- "sched_setaffinity($module, pid, mask, /)\n"
- "--\n"
- "\n"
- "Set the CPU affinity of the process identified by pid to mask.\n"
- "\n"
- "mask should be an iterable of integers identifying CPUs.");
- #define OS_SCHED_SETAFFINITY_METHODDEF \
- {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__},
- static PyObject *
- os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
- static PyObject *
- os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- pid_t pid;
- PyObject *mask;
- if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
- &pid, &mask)) {
- goto exit;
- }
- return_value = os_sched_setaffinity_impl(module, pid, mask);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
- #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
- PyDoc_STRVAR(os_sched_getaffinity__doc__,
- "sched_getaffinity($module, pid, /)\n"
- "--\n"
- "\n"
- "Return the affinity of the process identified by pid (or the current process if zero).\n"
- "\n"
- "The affinity is returned as a set of CPU identifiers.");
- #define OS_SCHED_GETAFFINITY_METHODDEF \
- {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
- static PyObject *
- os_sched_getaffinity_impl(PyObject *module, pid_t pid);
- static PyObject *
- os_sched_getaffinity(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- pid_t pid;
- if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
- goto exit;
- }
- return_value = os_sched_getaffinity_impl(module, pid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
- #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
- PyDoc_STRVAR(os_openpty__doc__,
- "openpty($module, /)\n"
- "--\n"
- "\n"
- "Open a pseudo-terminal.\n"
- "\n"
- "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
- "for both the master and slave ends.");
- #define OS_OPENPTY_METHODDEF \
- {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
- static PyObject *
- os_openpty_impl(PyObject *module);
- static PyObject *
- os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_openpty_impl(module);
- }
- #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
- #if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY))
- PyDoc_STRVAR(os_login_tty__doc__,
- "login_tty($module, fd, /)\n"
- "--\n"
- "\n"
- "Prepare the tty of which fd is a file descriptor for a new login session.\n"
- "\n"
- "Make the calling process a session leader; make the tty the\n"
- "controlling tty, the stdin, the stdout, and the stderr of the\n"
- "calling process; close fd.");
- #define OS_LOGIN_TTY_METHODDEF \
- {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__},
- static PyObject *
- os_login_tty_impl(PyObject *module, int fd);
- static PyObject *
- os_login_tty(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int fd;
- if (!_PyLong_FileDescriptor_Converter(arg, &fd)) {
- goto exit;
- }
- return_value = os_login_tty_impl(module, fd);
- exit:
- return return_value;
- }
- #endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */
- #if defined(HAVE_FORKPTY)
- PyDoc_STRVAR(os_forkpty__doc__,
- "forkpty($module, /)\n"
- "--\n"
- "\n"
- "Fork a new process with a new pseudo-terminal as controlling tty.\n"
- "\n"
- "Returns a tuple of (pid, master_fd).\n"
- "Like fork(), return pid of 0 to the child process,\n"
- "and pid of child to the parent process.\n"
- "To both, return fd of newly opened pseudo-terminal.");
- #define OS_FORKPTY_METHODDEF \
- {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
- static PyObject *
- os_forkpty_impl(PyObject *module);
- static PyObject *
- os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_forkpty_impl(module);
- }
- #endif /* defined(HAVE_FORKPTY) */
- #if defined(HAVE_GETEGID)
- PyDoc_STRVAR(os_getegid__doc__,
- "getegid($module, /)\n"
- "--\n"
- "\n"
- "Return the current process\'s effective group id.");
- #define OS_GETEGID_METHODDEF \
- {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
- static PyObject *
- os_getegid_impl(PyObject *module);
- static PyObject *
- os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getegid_impl(module);
- }
- #endif /* defined(HAVE_GETEGID) */
- #if defined(HAVE_GETEUID)
- PyDoc_STRVAR(os_geteuid__doc__,
- "geteuid($module, /)\n"
- "--\n"
- "\n"
- "Return the current process\'s effective user id.");
- #define OS_GETEUID_METHODDEF \
- {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
- static PyObject *
- os_geteuid_impl(PyObject *module);
- static PyObject *
- os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_geteuid_impl(module);
- }
- #endif /* defined(HAVE_GETEUID) */
- #if defined(HAVE_GETGID)
- PyDoc_STRVAR(os_getgid__doc__,
- "getgid($module, /)\n"
- "--\n"
- "\n"
- "Return the current process\'s group id.");
- #define OS_GETGID_METHODDEF \
- {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
- static PyObject *
- os_getgid_impl(PyObject *module);
- static PyObject *
- os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getgid_impl(module);
- }
- #endif /* defined(HAVE_GETGID) */
- #if defined(HAVE_GETPID)
- PyDoc_STRVAR(os_getpid__doc__,
- "getpid($module, /)\n"
- "--\n"
- "\n"
- "Return the current process id.");
- #define OS_GETPID_METHODDEF \
- {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
- static PyObject *
- os_getpid_impl(PyObject *module);
- static PyObject *
- os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getpid_impl(module);
- }
- #endif /* defined(HAVE_GETPID) */
- #if defined(HAVE_GETGROUPLIST) && defined(__APPLE__)
- PyDoc_STRVAR(os_getgrouplist__doc__,
- "getgrouplist($module, user, group, /)\n"
- "--\n"
- "\n"
- "Returns a list of groups to which a user belongs.\n"
- "\n"
- " user\n"
- " username to lookup\n"
- " group\n"
- " base group id of the user");
- #define OS_GETGROUPLIST_METHODDEF \
- {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
- static PyObject *
- os_getgrouplist_impl(PyObject *module, const char *user, int basegid);
- static PyObject *
- os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- const char *user;
- int basegid;
- if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
- goto exit;
- }
- Py_ssize_t user_length;
- user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
- if (user == NULL) {
- goto exit;
- }
- if (strlen(user) != (size_t)user_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
- basegid = _PyLong_AsInt(args[1]);
- if (basegid == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_getgrouplist_impl(module, user, basegid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */
- #if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__)
- PyDoc_STRVAR(os_getgrouplist__doc__,
- "getgrouplist($module, user, group, /)\n"
- "--\n"
- "\n"
- "Returns a list of groups to which a user belongs.\n"
- "\n"
- " user\n"
- " username to lookup\n"
- " group\n"
- " base group id of the user");
- #define OS_GETGROUPLIST_METHODDEF \
- {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
- static PyObject *
- os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid);
- static PyObject *
- os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- const char *user;
- gid_t basegid;
- if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
- goto exit;
- }
- Py_ssize_t user_length;
- user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
- if (user == NULL) {
- goto exit;
- }
- if (strlen(user) != (size_t)user_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
- if (!_Py_Gid_Converter(args[1], &basegid)) {
- goto exit;
- }
- return_value = os_getgrouplist_impl(module, user, basegid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */
- #if defined(HAVE_GETGROUPS)
- PyDoc_STRVAR(os_getgroups__doc__,
- "getgroups($module, /)\n"
- "--\n"
- "\n"
- "Return list of supplemental group IDs for the process.");
- #define OS_GETGROUPS_METHODDEF \
- {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
- static PyObject *
- os_getgroups_impl(PyObject *module);
- static PyObject *
- os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getgroups_impl(module);
- }
- #endif /* defined(HAVE_GETGROUPS) */
- #if defined(HAVE_INITGROUPS) && defined(__APPLE__)
- PyDoc_STRVAR(os_initgroups__doc__,
- "initgroups($module, username, gid, /)\n"
- "--\n"
- "\n"
- "Initialize the group access list.\n"
- "\n"
- "Call the system initgroups() to initialize the group access list with all of\n"
- "the groups of which the specified username is a member, plus the specified\n"
- "group id.");
- #define OS_INITGROUPS_METHODDEF \
- {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
- static PyObject *
- os_initgroups_impl(PyObject *module, PyObject *oname, int gid);
- static PyObject *
- os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- PyObject *oname = NULL;
- int gid;
- if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
- goto exit;
- }
- if (!PyUnicode_FSConverter(args[0], &oname)) {
- goto exit;
- }
- gid = _PyLong_AsInt(args[1]);
- if (gid == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_initgroups_impl(module, oname, gid);
- exit:
- /* Cleanup for oname */
- Py_XDECREF(oname);
- return return_value;
- }
- #endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */
- #if defined(HAVE_INITGROUPS) && !defined(__APPLE__)
- PyDoc_STRVAR(os_initgroups__doc__,
- "initgroups($module, username, gid, /)\n"
- "--\n"
- "\n"
- "Initialize the group access list.\n"
- "\n"
- "Call the system initgroups() to initialize the group access list with all of\n"
- "the groups of which the specified username is a member, plus the specified\n"
- "group id.");
- #define OS_INITGROUPS_METHODDEF \
- {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
- static PyObject *
- os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid);
- static PyObject *
- os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- PyObject *oname = NULL;
- gid_t gid;
- if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
- goto exit;
- }
- if (!PyUnicode_FSConverter(args[0], &oname)) {
- goto exit;
- }
- if (!_Py_Gid_Converter(args[1], &gid)) {
- goto exit;
- }
- return_value = os_initgroups_impl(module, oname, gid);
- exit:
- /* Cleanup for oname */
- Py_XDECREF(oname);
- return return_value;
- }
- #endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */
- #if defined(HAVE_GETPGID)
- PyDoc_STRVAR(os_getpgid__doc__,
- "getpgid($module, /, pid)\n"
- "--\n"
- "\n"
- "Call the system call getpgid(), and return the result.");
- #define OS_GETPGID_METHODDEF \
- {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
- static PyObject *
- os_getpgid_impl(PyObject *module, pid_t pid);
- static PyObject *
- os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(pid), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"pid", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .format = "" _Py_PARSE_PID ":getpgid",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- pid_t pid;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- &pid)) {
- goto exit;
- }
- return_value = os_getpgid_impl(module, pid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_GETPGID) */
- #if defined(HAVE_GETPGRP)
- PyDoc_STRVAR(os_getpgrp__doc__,
- "getpgrp($module, /)\n"
- "--\n"
- "\n"
- "Return the current process group id.");
- #define OS_GETPGRP_METHODDEF \
- {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
- static PyObject *
- os_getpgrp_impl(PyObject *module);
- static PyObject *
- os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getpgrp_impl(module);
- }
- #endif /* defined(HAVE_GETPGRP) */
- #if defined(HAVE_SETPGRP)
- PyDoc_STRVAR(os_setpgrp__doc__,
- "setpgrp($module, /)\n"
- "--\n"
- "\n"
- "Make the current process the leader of its process group.");
- #define OS_SETPGRP_METHODDEF \
- {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
- static PyObject *
- os_setpgrp_impl(PyObject *module);
- static PyObject *
- os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_setpgrp_impl(module);
- }
- #endif /* defined(HAVE_SETPGRP) */
- #if defined(HAVE_GETPPID)
- PyDoc_STRVAR(os_getppid__doc__,
- "getppid($module, /)\n"
- "--\n"
- "\n"
- "Return the parent\'s process id.\n"
- "\n"
- "If the parent process has already exited, Windows machines will still\n"
- "return its id; others systems will return the id of the \'init\' process (1).");
- #define OS_GETPPID_METHODDEF \
- {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
- static PyObject *
- os_getppid_impl(PyObject *module);
- static PyObject *
- os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getppid_impl(module);
- }
- #endif /* defined(HAVE_GETPPID) */
- #if defined(HAVE_GETLOGIN)
- PyDoc_STRVAR(os_getlogin__doc__,
- "getlogin($module, /)\n"
- "--\n"
- "\n"
- "Return the actual login name.");
- #define OS_GETLOGIN_METHODDEF \
- {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
- static PyObject *
- os_getlogin_impl(PyObject *module);
- static PyObject *
- os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getlogin_impl(module);
- }
- #endif /* defined(HAVE_GETLOGIN) */
- #if defined(HAVE_GETUID)
- PyDoc_STRVAR(os_getuid__doc__,
- "getuid($module, /)\n"
- "--\n"
- "\n"
- "Return the current process\'s user id.");
- #define OS_GETUID_METHODDEF \
- {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
- static PyObject *
- os_getuid_impl(PyObject *module);
- static PyObject *
- os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getuid_impl(module);
- }
- #endif /* defined(HAVE_GETUID) */
- #if defined(HAVE_KILL)
- PyDoc_STRVAR(os_kill__doc__,
- "kill($module, pid, signal, /)\n"
- "--\n"
- "\n"
- "Kill a process with a signal.");
- #define OS_KILL_METHODDEF \
- {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__},
- static PyObject *
- os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
- static PyObject *
- os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- pid_t pid;
- Py_ssize_t signal;
- if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
- &pid, &signal)) {
- goto exit;
- }
- return_value = os_kill_impl(module, pid, signal);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_KILL) */
- #if defined(HAVE_KILLPG)
- PyDoc_STRVAR(os_killpg__doc__,
- "killpg($module, pgid, signal, /)\n"
- "--\n"
- "\n"
- "Kill a process group with a signal.");
- #define OS_KILLPG_METHODDEF \
- {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__},
- static PyObject *
- os_killpg_impl(PyObject *module, pid_t pgid, int signal);
- static PyObject *
- os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- pid_t pgid;
- int signal;
- if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
- &pgid, &signal)) {
- goto exit;
- }
- return_value = os_killpg_impl(module, pgid, signal);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_KILLPG) */
- #if defined(HAVE_PLOCK)
- PyDoc_STRVAR(os_plock__doc__,
- "plock($module, op, /)\n"
- "--\n"
- "\n"
- "Lock program segments into memory.\");");
- #define OS_PLOCK_METHODDEF \
- {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
- static PyObject *
- os_plock_impl(PyObject *module, int op);
- static PyObject *
- os_plock(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int op;
- op = _PyLong_AsInt(arg);
- if (op == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_plock_impl(module, op);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_PLOCK) */
- #if defined(HAVE_SETUID)
- PyDoc_STRVAR(os_setuid__doc__,
- "setuid($module, uid, /)\n"
- "--\n"
- "\n"
- "Set the current process\'s user id.");
- #define OS_SETUID_METHODDEF \
- {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
- static PyObject *
- os_setuid_impl(PyObject *module, uid_t uid);
- static PyObject *
- os_setuid(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- uid_t uid;
- if (!_Py_Uid_Converter(arg, &uid)) {
- goto exit;
- }
- return_value = os_setuid_impl(module, uid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SETUID) */
- #if defined(HAVE_SETEUID)
- PyDoc_STRVAR(os_seteuid__doc__,
- "seteuid($module, euid, /)\n"
- "--\n"
- "\n"
- "Set the current process\'s effective user id.");
- #define OS_SETEUID_METHODDEF \
- {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
- static PyObject *
- os_seteuid_impl(PyObject *module, uid_t euid);
- static PyObject *
- os_seteuid(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- uid_t euid;
- if (!_Py_Uid_Converter(arg, &euid)) {
- goto exit;
- }
- return_value = os_seteuid_impl(module, euid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SETEUID) */
- #if defined(HAVE_SETEGID)
- PyDoc_STRVAR(os_setegid__doc__,
- "setegid($module, egid, /)\n"
- "--\n"
- "\n"
- "Set the current process\'s effective group id.");
- #define OS_SETEGID_METHODDEF \
- {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
- static PyObject *
- os_setegid_impl(PyObject *module, gid_t egid);
- static PyObject *
- os_setegid(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- gid_t egid;
- if (!_Py_Gid_Converter(arg, &egid)) {
- goto exit;
- }
- return_value = os_setegid_impl(module, egid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SETEGID) */
- #if defined(HAVE_SETREUID)
- PyDoc_STRVAR(os_setreuid__doc__,
- "setreuid($module, ruid, euid, /)\n"
- "--\n"
- "\n"
- "Set the current process\'s real and effective user ids.");
- #define OS_SETREUID_METHODDEF \
- {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__},
- static PyObject *
- os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
- static PyObject *
- os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- uid_t ruid;
- uid_t euid;
- if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
- goto exit;
- }
- if (!_Py_Uid_Converter(args[0], &ruid)) {
- goto exit;
- }
- if (!_Py_Uid_Converter(args[1], &euid)) {
- goto exit;
- }
- return_value = os_setreuid_impl(module, ruid, euid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SETREUID) */
- #if defined(HAVE_SETREGID)
- PyDoc_STRVAR(os_setregid__doc__,
- "setregid($module, rgid, egid, /)\n"
- "--\n"
- "\n"
- "Set the current process\'s real and effective group ids.");
- #define OS_SETREGID_METHODDEF \
- {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__},
- static PyObject *
- os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
- static PyObject *
- os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- gid_t rgid;
- gid_t egid;
- if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
- goto exit;
- }
- if (!_Py_Gid_Converter(args[0], &rgid)) {
- goto exit;
- }
- if (!_Py_Gid_Converter(args[1], &egid)) {
- goto exit;
- }
- return_value = os_setregid_impl(module, rgid, egid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SETREGID) */
- #if defined(HAVE_SETGID)
- PyDoc_STRVAR(os_setgid__doc__,
- "setgid($module, gid, /)\n"
- "--\n"
- "\n"
- "Set the current process\'s group id.");
- #define OS_SETGID_METHODDEF \
- {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
- static PyObject *
- os_setgid_impl(PyObject *module, gid_t gid);
- static PyObject *
- os_setgid(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- gid_t gid;
- if (!_Py_Gid_Converter(arg, &gid)) {
- goto exit;
- }
- return_value = os_setgid_impl(module, gid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SETGID) */
- #if defined(HAVE_SETGROUPS)
- PyDoc_STRVAR(os_setgroups__doc__,
- "setgroups($module, groups, /)\n"
- "--\n"
- "\n"
- "Set the groups of the current process to list.");
- #define OS_SETGROUPS_METHODDEF \
- {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
- #endif /* defined(HAVE_SETGROUPS) */
- #if defined(HAVE_WAIT3)
- PyDoc_STRVAR(os_wait3__doc__,
- "wait3($module, /, options)\n"
- "--\n"
- "\n"
- "Wait for completion of a child process.\n"
- "\n"
- "Returns a tuple of information about the child process:\n"
- " (pid, status, rusage)");
- #define OS_WAIT3_METHODDEF \
- {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
- static PyObject *
- os_wait3_impl(PyObject *module, int options);
- static PyObject *
- os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(options), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"options", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "wait3",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int options;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- options = _PyLong_AsInt(args[0]);
- if (options == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_wait3_impl(module, options);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_WAIT3) */
- #if defined(HAVE_WAIT4)
- PyDoc_STRVAR(os_wait4__doc__,
- "wait4($module, /, pid, options)\n"
- "--\n"
- "\n"
- "Wait for completion of a specific child process.\n"
- "\n"
- "Returns a tuple of information about the child process:\n"
- " (pid, status, rusage)");
- #define OS_WAIT4_METHODDEF \
- {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
- static PyObject *
- os_wait4_impl(PyObject *module, pid_t pid, int options);
- static PyObject *
- os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(pid), &_Py_ID(options), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"pid", "options", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .format = "" _Py_PARSE_PID "i:wait4",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- pid_t pid;
- int options;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- &pid, &options)) {
- goto exit;
- }
- return_value = os_wait4_impl(module, pid, options);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_WAIT4) */
- #if (defined(HAVE_WAITID) && !defined(__APPLE__))
- PyDoc_STRVAR(os_waitid__doc__,
- "waitid($module, idtype, id, options, /)\n"
- "--\n"
- "\n"
- "Returns the result of waiting for a process or processes.\n"
- "\n"
- " idtype\n"
- " Must be one of be P_PID, P_PGID or P_ALL.\n"
- " id\n"
- " The id to wait on.\n"
- " options\n"
- " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
- " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
- "\n"
- "Returns either waitid_result or None if WNOHANG is specified and there are\n"
- "no children in a waitable state.");
- #define OS_WAITID_METHODDEF \
- {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__},
- static PyObject *
- os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
- static PyObject *
- os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- idtype_t idtype;
- id_t id;
- int options;
- if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
- &idtype, &id, &options)) {
- goto exit;
- }
- return_value = os_waitid_impl(module, idtype, id, options);
- exit:
- return return_value;
- }
- #endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
- #if defined(HAVE_WAITPID)
- PyDoc_STRVAR(os_waitpid__doc__,
- "waitpid($module, pid, options, /)\n"
- "--\n"
- "\n"
- "Wait for completion of a given child process.\n"
- "\n"
- "Returns a tuple of information regarding the child process:\n"
- " (pid, status)\n"
- "\n"
- "The options argument is ignored on Windows.");
- #define OS_WAITPID_METHODDEF \
- {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
- static PyObject *
- os_waitpid_impl(PyObject *module, pid_t pid, int options);
- static PyObject *
- os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- pid_t pid;
- int options;
- if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
- &pid, &options)) {
- goto exit;
- }
- return_value = os_waitpid_impl(module, pid, options);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_WAITPID) */
- #if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT)
- PyDoc_STRVAR(os_waitpid__doc__,
- "waitpid($module, pid, options, /)\n"
- "--\n"
- "\n"
- "Wait for completion of a given process.\n"
- "\n"
- "Returns a tuple of information regarding the process:\n"
- " (pid, status << 8)\n"
- "\n"
- "The options argument is ignored on Windows.");
- #define OS_WAITPID_METHODDEF \
- {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
- static PyObject *
- os_waitpid_impl(PyObject *module, intptr_t pid, int options);
- static PyObject *
- os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- intptr_t pid;
- int options;
- if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
- &pid, &options)) {
- goto exit;
- }
- return_value = os_waitpid_impl(module, pid, options);
- exit:
- return return_value;
- }
- #endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */
- #if defined(HAVE_WAIT)
- PyDoc_STRVAR(os_wait__doc__,
- "wait($module, /)\n"
- "--\n"
- "\n"
- "Wait for completion of a child process.\n"
- "\n"
- "Returns a tuple of information about the child process:\n"
- " (pid, status)");
- #define OS_WAIT_METHODDEF \
- {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
- static PyObject *
- os_wait_impl(PyObject *module);
- static PyObject *
- os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_wait_impl(module);
- }
- #endif /* defined(HAVE_WAIT) */
- #if (defined(__linux__) && defined(__NR_pidfd_open))
- PyDoc_STRVAR(os_pidfd_open__doc__,
- "pidfd_open($module, /, pid, flags=0)\n"
- "--\n"
- "\n"
- "Return a file descriptor referring to the process *pid*.\n"
- "\n"
- "The descriptor can be used to perform process management without races and\n"
- "signals.");
- #define OS_PIDFD_OPEN_METHODDEF \
- {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__},
- static PyObject *
- os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags);
- static PyObject *
- os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(pid), &_Py_ID(flags), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"pid", "flags", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .format = "" _Py_PARSE_PID "|O&:pidfd_open",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- pid_t pid;
- unsigned int flags = 0;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- &pid, _PyLong_UnsignedInt_Converter, &flags)) {
- goto exit;
- }
- return_value = os_pidfd_open_impl(module, pid, flags);
- exit:
- return return_value;
- }
- #endif /* (defined(__linux__) && defined(__NR_pidfd_open)) */
- #if defined(HAVE_SETNS)
- PyDoc_STRVAR(os_setns__doc__,
- "setns($module, /, fd, nstype=0)\n"
- "--\n"
- "\n"
- "Move the calling thread into different namespaces.\n"
- "\n"
- " fd\n"
- " A file descriptor to a namespace.\n"
- " nstype\n"
- " Type of namespace.");
- #define OS_SETNS_METHODDEF \
- {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__},
- static PyObject *
- os_setns_impl(PyObject *module, int fd, int nstype);
- static PyObject *
- os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"fd", "nstype", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "setns",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- int fd;
- int nstype = 0;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- nstype = _PyLong_AsInt(args[1]);
- if (nstype == -1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional_pos:
- return_value = os_setns_impl(module, fd, nstype);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SETNS) */
- #if defined(HAVE_UNSHARE)
- PyDoc_STRVAR(os_unshare__doc__,
- "unshare($module, /, flags)\n"
- "--\n"
- "\n"
- "Disassociate parts of a process (or thread) execution context.\n"
- "\n"
- " flags\n"
- " Namespaces to be unshared.");
- #define OS_UNSHARE_METHODDEF \
- {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__},
- static PyObject *
- os_unshare_impl(PyObject *module, int flags);
- static PyObject *
- os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(flags), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"flags", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "unshare",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int flags;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- flags = _PyLong_AsInt(args[0]);
- if (flags == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_unshare_impl(module, flags);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_UNSHARE) */
- #if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
- PyDoc_STRVAR(os_readlink__doc__,
- "readlink($module, /, path, *, dir_fd=None)\n"
- "--\n"
- "\n"
- "Return a string representing the path to which the symbolic link points.\n"
- "\n"
- "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
- "and path should be relative; path will then be relative to that directory.\n"
- "\n"
- "dir_fd may not be implemented on your platform. If it is unavailable,\n"
- "using it will raise a NotImplementedError.");
- #define OS_READLINK_METHODDEF \
- {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
- static PyObject *
- os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
- static PyObject *
- os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "dir_fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "readlink",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 0);
- int dir_fd = DEFAULT_DIR_FD;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_readlink_impl(module, &path, dir_fd);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
- #if defined(HAVE_SYMLINK)
- PyDoc_STRVAR(os_symlink__doc__,
- "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
- "--\n"
- "\n"
- "Create a symbolic link pointing to src named dst.\n"
- "\n"
- "target_is_directory is required on Windows if the target is to be\n"
- " interpreted as a directory. (On Windows, symlink requires\n"
- " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
- " target_is_directory is ignored on non-Windows platforms.\n"
- "\n"
- "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that directory.\n"
- "dir_fd may not be implemented on your platform.\n"
- " If it is unavailable, using it will raise a NotImplementedError.");
- #define OS_SYMLINK_METHODDEF \
- {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
- static PyObject *
- os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
- int target_is_directory, int dir_fd);
- static PyObject *
- os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 4
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "symlink",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[4];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
- path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0);
- path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0);
- int target_is_directory = 0;
- int dir_fd = DEFAULT_DIR_FD;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &src)) {
- goto exit;
- }
- if (!path_converter(args[1], &dst)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[2]) {
- target_is_directory = PyObject_IsTrue(args[2]);
- if (target_is_directory < 0) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- skip_optional_pos:
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
- exit:
- /* Cleanup for src */
- path_cleanup(&src);
- /* Cleanup for dst */
- path_cleanup(&dst);
- return return_value;
- }
- #endif /* defined(HAVE_SYMLINK) */
- #if defined(HAVE_TIMES)
- PyDoc_STRVAR(os_times__doc__,
- "times($module, /)\n"
- "--\n"
- "\n"
- "Return a collection containing process timing information.\n"
- "\n"
- "The object returned behaves like a named tuple with these fields:\n"
- " (utime, stime, cutime, cstime, elapsed_time)\n"
- "All fields are floating-point numbers.");
- #define OS_TIMES_METHODDEF \
- {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
- static PyObject *
- os_times_impl(PyObject *module);
- static PyObject *
- os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_times_impl(module);
- }
- #endif /* defined(HAVE_TIMES) */
- #if defined(HAVE_GETSID)
- PyDoc_STRVAR(os_getsid__doc__,
- "getsid($module, pid, /)\n"
- "--\n"
- "\n"
- "Call the system call getsid(pid) and return the result.");
- #define OS_GETSID_METHODDEF \
- {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
- static PyObject *
- os_getsid_impl(PyObject *module, pid_t pid);
- static PyObject *
- os_getsid(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- pid_t pid;
- if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
- goto exit;
- }
- return_value = os_getsid_impl(module, pid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_GETSID) */
- #if defined(HAVE_SETSID)
- PyDoc_STRVAR(os_setsid__doc__,
- "setsid($module, /)\n"
- "--\n"
- "\n"
- "Call the system call setsid().");
- #define OS_SETSID_METHODDEF \
- {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
- static PyObject *
- os_setsid_impl(PyObject *module);
- static PyObject *
- os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_setsid_impl(module);
- }
- #endif /* defined(HAVE_SETSID) */
- #if defined(HAVE_SETPGID)
- PyDoc_STRVAR(os_setpgid__doc__,
- "setpgid($module, pid, pgrp, /)\n"
- "--\n"
- "\n"
- "Call the system call setpgid(pid, pgrp).");
- #define OS_SETPGID_METHODDEF \
- {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__},
- static PyObject *
- os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
- static PyObject *
- os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- pid_t pid;
- pid_t pgrp;
- if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
- &pid, &pgrp)) {
- goto exit;
- }
- return_value = os_setpgid_impl(module, pid, pgrp);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SETPGID) */
- #if defined(HAVE_TCGETPGRP)
- PyDoc_STRVAR(os_tcgetpgrp__doc__,
- "tcgetpgrp($module, fd, /)\n"
- "--\n"
- "\n"
- "Return the process group associated with the terminal specified by fd.");
- #define OS_TCGETPGRP_METHODDEF \
- {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
- static PyObject *
- os_tcgetpgrp_impl(PyObject *module, int fd);
- static PyObject *
- os_tcgetpgrp(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int fd;
- fd = _PyLong_AsInt(arg);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_tcgetpgrp_impl(module, fd);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_TCGETPGRP) */
- #if defined(HAVE_TCSETPGRP)
- PyDoc_STRVAR(os_tcsetpgrp__doc__,
- "tcsetpgrp($module, fd, pgid, /)\n"
- "--\n"
- "\n"
- "Set the process group associated with the terminal specified by fd.");
- #define OS_TCSETPGRP_METHODDEF \
- {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__},
- static PyObject *
- os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
- static PyObject *
- os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- pid_t pgid;
- if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
- &fd, &pgid)) {
- goto exit;
- }
- return_value = os_tcsetpgrp_impl(module, fd, pgid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_TCSETPGRP) */
- PyDoc_STRVAR(os_open__doc__,
- "open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
- "--\n"
- "\n"
- "Open a file for low level IO. Returns a file descriptor (integer).\n"
- "\n"
- "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that directory.\n"
- "dir_fd may not be implemented on your platform.\n"
- " If it is unavailable, using it will raise a NotImplementedError.");
- #define OS_OPEN_METHODDEF \
- {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
- static int
- os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
- static PyObject *
- os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 4
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "open",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[4];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
- path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0);
- int flags;
- int mode = 511;
- int dir_fd = DEFAULT_DIR_FD;
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- flags = _PyLong_AsInt(args[1]);
- if (flags == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[2]) {
- mode = _PyLong_AsInt(args[2]);
- if (mode == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- skip_optional_pos:
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
- goto exit;
- }
- skip_optional_kwonly:
- _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromLong((long)_return_value);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- PyDoc_STRVAR(os_close__doc__,
- "close($module, /, fd)\n"
- "--\n"
- "\n"
- "Close a file descriptor.");
- #define OS_CLOSE_METHODDEF \
- {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
- static PyObject *
- os_close_impl(PyObject *module, int fd);
- static PyObject *
- os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "close",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int fd;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_close_impl(module, fd);
- exit:
- return return_value;
- }
- PyDoc_STRVAR(os_closerange__doc__,
- "closerange($module, fd_low, fd_high, /)\n"
- "--\n"
- "\n"
- "Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
- #define OS_CLOSERANGE_METHODDEF \
- {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__},
- static PyObject *
- os_closerange_impl(PyObject *module, int fd_low, int fd_high);
- static PyObject *
- os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd_low;
- int fd_high;
- if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
- goto exit;
- }
- fd_low = _PyLong_AsInt(args[0]);
- if (fd_low == -1 && PyErr_Occurred()) {
- goto exit;
- }
- fd_high = _PyLong_AsInt(args[1]);
- if (fd_high == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_closerange_impl(module, fd_low, fd_high);
- exit:
- return return_value;
- }
- PyDoc_STRVAR(os_dup__doc__,
- "dup($module, fd, /)\n"
- "--\n"
- "\n"
- "Return a duplicate of a file descriptor.");
- #define OS_DUP_METHODDEF \
- {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
- static int
- os_dup_impl(PyObject *module, int fd);
- static PyObject *
- os_dup(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int fd;
- int _return_value;
- fd = _PyLong_AsInt(arg);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_dup_impl(module, fd);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- #if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS)))
- PyDoc_STRVAR(os_dup2__doc__,
- "dup2($module, /, fd, fd2, inheritable=True)\n"
- "--\n"
- "\n"
- "Duplicate file descriptor.");
- #define OS_DUP2_METHODDEF \
- {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
- static int
- os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
- static PyObject *
- os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "dup2",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
- int fd;
- int fd2;
- int inheritable = 1;
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- fd2 = _PyLong_AsInt(args[1]);
- if (fd2 == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- inheritable = PyObject_IsTrue(args[2]);
- if (inheritable < 0) {
- goto exit;
- }
- skip_optional_pos:
- _return_value = os_dup2_impl(module, fd, fd2, inheritable);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- #endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */
- #if defined(HAVE_LOCKF)
- PyDoc_STRVAR(os_lockf__doc__,
- "lockf($module, fd, command, length, /)\n"
- "--\n"
- "\n"
- "Apply, test or remove a POSIX lock on an open file descriptor.\n"
- "\n"
- " fd\n"
- " An open file descriptor.\n"
- " command\n"
- " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
- " length\n"
- " The number of bytes to lock, starting at the current position.");
- #define OS_LOCKF_METHODDEF \
- {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__},
- static PyObject *
- os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
- static PyObject *
- os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- int command;
- Py_off_t length;
- if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- command = _PyLong_AsInt(args[1]);
- if (command == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!Py_off_t_converter(args[2], &length)) {
- goto exit;
- }
- return_value = os_lockf_impl(module, fd, command, length);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_LOCKF) */
- PyDoc_STRVAR(os_lseek__doc__,
- "lseek($module, fd, position, whence, /)\n"
- "--\n"
- "\n"
- "Set the position of a file descriptor. Return the new position.\n"
- "\n"
- " fd\n"
- " An open file descriptor, as returned by os.open().\n"
- " position\n"
- " Position, interpreted relative to \'whence\'.\n"
- " whence\n"
- " The relative position to seek from. Valid values are:\n"
- " - SEEK_SET: seek from the start of the file.\n"
- " - SEEK_CUR: seek from the current file position.\n"
- " - SEEK_END: seek from the end of the file.\n"
- "\n"
- "The return value is the number of bytes relative to the beginning of the file.");
- #define OS_LSEEK_METHODDEF \
- {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__},
- static Py_off_t
- os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
- static PyObject *
- os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- Py_off_t position;
- int how;
- Py_off_t _return_value;
- if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!Py_off_t_converter(args[1], &position)) {
- goto exit;
- }
- how = _PyLong_AsInt(args[2]);
- if (how == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_lseek_impl(module, fd, position, how);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromPy_off_t(_return_value);
- exit:
- return return_value;
- }
- PyDoc_STRVAR(os_read__doc__,
- "read($module, fd, length, /)\n"
- "--\n"
- "\n"
- "Read from a file descriptor. Returns a bytes object.");
- #define OS_READ_METHODDEF \
- {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__},
- static PyObject *
- os_read_impl(PyObject *module, int fd, Py_ssize_t length);
- static PyObject *
- os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- Py_ssize_t length;
- if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- {
- Py_ssize_t ival = -1;
- PyObject *iobj = _PyNumber_Index(args[1]);
- if (iobj != NULL) {
- ival = PyLong_AsSsize_t(iobj);
- Py_DECREF(iobj);
- }
- if (ival == -1 && PyErr_Occurred()) {
- goto exit;
- }
- length = ival;
- }
- return_value = os_read_impl(module, fd, length);
- exit:
- return return_value;
- }
- #if defined(HAVE_READV)
- PyDoc_STRVAR(os_readv__doc__,
- "readv($module, fd, buffers, /)\n"
- "--\n"
- "\n"
- "Read from a file descriptor fd into an iterable of buffers.\n"
- "\n"
- "The buffers should be mutable buffers accepting bytes.\n"
- "readv will transfer data into each buffer until it is full\n"
- "and then move on to the next buffer in the sequence to hold\n"
- "the rest of the data.\n"
- "\n"
- "readv returns the total number of bytes read,\n"
- "which may be less than the total capacity of all the buffers.");
- #define OS_READV_METHODDEF \
- {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__},
- static Py_ssize_t
- os_readv_impl(PyObject *module, int fd, PyObject *buffers);
- static PyObject *
- os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- PyObject *buffers;
- Py_ssize_t _return_value;
- if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- buffers = args[1];
- _return_value = os_readv_impl(module, fd, buffers);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromSsize_t(_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_READV) */
- #if defined(HAVE_PREAD)
- PyDoc_STRVAR(os_pread__doc__,
- "pread($module, fd, length, offset, /)\n"
- "--\n"
- "\n"
- "Read a number of bytes from a file descriptor starting at a particular offset.\n"
- "\n"
- "Read length bytes from file descriptor fd, starting at offset bytes from\n"
- "the beginning of the file. The file offset remains unchanged.");
- #define OS_PREAD_METHODDEF \
- {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__},
- static PyObject *
- os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset);
- static PyObject *
- os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- Py_ssize_t length;
- Py_off_t offset;
- if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- {
- Py_ssize_t ival = -1;
- PyObject *iobj = _PyNumber_Index(args[1]);
- if (iobj != NULL) {
- ival = PyLong_AsSsize_t(iobj);
- Py_DECREF(iobj);
- }
- if (ival == -1 && PyErr_Occurred()) {
- goto exit;
- }
- length = ival;
- }
- if (!Py_off_t_converter(args[2], &offset)) {
- goto exit;
- }
- return_value = os_pread_impl(module, fd, length, offset);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_PREAD) */
- #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
- PyDoc_STRVAR(os_preadv__doc__,
- "preadv($module, fd, buffers, offset, flags=0, /)\n"
- "--\n"
- "\n"
- "Reads from a file descriptor into a number of mutable bytes-like objects.\n"
- "\n"
- "Combines the functionality of readv() and pread(). As readv(), it will\n"
- "transfer data into each buffer until it is full and then move on to the next\n"
- "buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
- "specifies the file offset at which the input operation is to be performed. It\n"
- "will return the total number of bytes read (which can be less than the total\n"
- "capacity of all the objects).\n"
- "\n"
- "The flags argument contains a bitwise OR of zero or more of the following flags:\n"
- "\n"
- "- RWF_HIPRI\n"
- "- RWF_NOWAIT\n"
- "\n"
- "Using non-zero flags requires Linux 4.6 or newer.");
- #define OS_PREADV_METHODDEF \
- {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__},
- static Py_ssize_t
- os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
- int flags);
- static PyObject *
- os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- PyObject *buffers;
- Py_off_t offset;
- int flags = 0;
- Py_ssize_t _return_value;
- if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- buffers = args[1];
- if (!Py_off_t_converter(args[2], &offset)) {
- goto exit;
- }
- if (nargs < 4) {
- goto skip_optional;
- }
- flags = _PyLong_AsInt(args[3]);
- if (flags == -1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional:
- _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromSsize_t(_return_value);
- exit:
- return return_value;
- }
- #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
- PyDoc_STRVAR(os_write__doc__,
- "write($module, fd, data, /)\n"
- "--\n"
- "\n"
- "Write a bytes object to a file descriptor.");
- #define OS_WRITE_METHODDEF \
- {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__},
- static Py_ssize_t
- os_write_impl(PyObject *module, int fd, Py_buffer *data);
- static PyObject *
- os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- Py_buffer data = {NULL, NULL};
- Py_ssize_t _return_value;
- if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("write", "argument 2", "contiguous buffer", args[1]);
- goto exit;
- }
- _return_value = os_write_impl(module, fd, &data);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromSsize_t(_return_value);
- exit:
- /* Cleanup for data */
- if (data.obj) {
- PyBuffer_Release(&data);
- }
- return return_value;
- }
- #if defined(HAVE_SENDFILE) && defined(__APPLE__)
- PyDoc_STRVAR(os_sendfile__doc__,
- "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
- " trailers=(), flags=0)\n"
- "--\n"
- "\n"
- "Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
- #define OS_SENDFILE_METHODDEF \
- {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
- static PyObject *
- os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
- Py_off_t sbytes, PyObject *headers, PyObject *trailers,
- int flags);
- static PyObject *
- os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 7
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .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), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "sendfile",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[7];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
- int out_fd;
- int in_fd;
- Py_off_t offset;
- Py_off_t sbytes;
- PyObject *headers = NULL;
- PyObject *trailers = NULL;
- int flags = 0;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 7, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- out_fd = _PyLong_AsInt(args[0]);
- if (out_fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- in_fd = _PyLong_AsInt(args[1]);
- if (in_fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!Py_off_t_converter(args[2], &offset)) {
- goto exit;
- }
- if (!Py_off_t_converter(args[3], &sbytes)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[4]) {
- headers = args[4];
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- if (args[5]) {
- trailers = args[5];
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- flags = _PyLong_AsInt(args[6]);
- if (flags == -1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional_pos:
- return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */
- #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__))
- PyDoc_STRVAR(os_sendfile__doc__,
- "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
- " trailers=(), flags=0)\n"
- "--\n"
- "\n"
- "Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
- #define OS_SENDFILE_METHODDEF \
- {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
- static PyObject *
- os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
- Py_ssize_t count, PyObject *headers, PyObject *trailers,
- int flags);
- static PyObject *
- os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 7
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .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), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "sendfile",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[7];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
- int out_fd;
- int in_fd;
- Py_off_t offset;
- Py_ssize_t count;
- PyObject *headers = NULL;
- PyObject *trailers = NULL;
- int flags = 0;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 7, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- out_fd = _PyLong_AsInt(args[0]);
- if (out_fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- in_fd = _PyLong_AsInt(args[1]);
- if (in_fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!Py_off_t_converter(args[2], &offset)) {
- goto exit;
- }
- {
- Py_ssize_t ival = -1;
- PyObject *iobj = _PyNumber_Index(args[3]);
- if (iobj != NULL) {
- ival = PyLong_AsSsize_t(iobj);
- Py_DECREF(iobj);
- }
- if (ival == -1 && PyErr_Occurred()) {
- goto exit;
- }
- count = ival;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[4]) {
- headers = args[4];
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- if (args[5]) {
- trailers = args[5];
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- flags = _PyLong_AsInt(args[6]);
- if (flags == -1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional_pos:
- return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */
- #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__))
- PyDoc_STRVAR(os_sendfile__doc__,
- "sendfile($module, /, out_fd, in_fd, offset, count)\n"
- "--\n"
- "\n"
- "Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
- #define OS_SENDFILE_METHODDEF \
- {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
- static PyObject *
- os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
- Py_ssize_t count);
- static PyObject *
- os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 4
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "sendfile",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[4];
- int out_fd;
- int in_fd;
- PyObject *offobj;
- Py_ssize_t count;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 4, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- out_fd = _PyLong_AsInt(args[0]);
- if (out_fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- in_fd = _PyLong_AsInt(args[1]);
- if (in_fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- offobj = args[2];
- {
- Py_ssize_t ival = -1;
- PyObject *iobj = _PyNumber_Index(args[3]);
- if (iobj != NULL) {
- ival = PyLong_AsSsize_t(iobj);
- Py_DECREF(iobj);
- }
- if (ival == -1 && PyErr_Occurred()) {
- goto exit;
- }
- count = ival;
- }
- return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */
- #if defined(__APPLE__)
- PyDoc_STRVAR(os__fcopyfile__doc__,
- "_fcopyfile($module, in_fd, out_fd, flags, /)\n"
- "--\n"
- "\n"
- "Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
- #define OS__FCOPYFILE_METHODDEF \
- {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__},
- static PyObject *
- os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags);
- static PyObject *
- os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int in_fd;
- int out_fd;
- int flags;
- if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
- goto exit;
- }
- in_fd = _PyLong_AsInt(args[0]);
- if (in_fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- out_fd = _PyLong_AsInt(args[1]);
- if (out_fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- flags = _PyLong_AsInt(args[2]);
- if (flags == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags);
- exit:
- return return_value;
- }
- #endif /* defined(__APPLE__) */
- PyDoc_STRVAR(os_fstat__doc__,
- "fstat($module, /, fd)\n"
- "--\n"
- "\n"
- "Perform a stat system call on the given file descriptor.\n"
- "\n"
- "Like stat(), but for an open file descriptor.\n"
- "Equivalent to os.stat(fd).");
- #define OS_FSTAT_METHODDEF \
- {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
- static PyObject *
- os_fstat_impl(PyObject *module, int fd);
- static PyObject *
- os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "fstat",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int fd;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_fstat_impl(module, fd);
- exit:
- return return_value;
- }
- PyDoc_STRVAR(os_isatty__doc__,
- "isatty($module, fd, /)\n"
- "--\n"
- "\n"
- "Return True if the fd is connected to a terminal.\n"
- "\n"
- "Return True if the file descriptor is an open file descriptor\n"
- "connected to the slave end of a terminal.");
- #define OS_ISATTY_METHODDEF \
- {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
- static int
- os_isatty_impl(PyObject *module, int fd);
- static PyObject *
- os_isatty(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int fd;
- int _return_value;
- fd = _PyLong_AsInt(arg);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_isatty_impl(module, fd);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- #if defined(HAVE_PIPE)
- PyDoc_STRVAR(os_pipe__doc__,
- "pipe($module, /)\n"
- "--\n"
- "\n"
- "Create a pipe.\n"
- "\n"
- "Returns a tuple of two file descriptors:\n"
- " (read_fd, write_fd)");
- #define OS_PIPE_METHODDEF \
- {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
- static PyObject *
- os_pipe_impl(PyObject *module);
- static PyObject *
- os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_pipe_impl(module);
- }
- #endif /* defined(HAVE_PIPE) */
- #if defined(HAVE_PIPE2)
- PyDoc_STRVAR(os_pipe2__doc__,
- "pipe2($module, flags, /)\n"
- "--\n"
- "\n"
- "Create a pipe with flags set atomically.\n"
- "\n"
- "Returns a tuple of two file descriptors:\n"
- " (read_fd, write_fd)\n"
- "\n"
- "flags can be constructed by ORing together one or more of these values:\n"
- "O_NONBLOCK, O_CLOEXEC.");
- #define OS_PIPE2_METHODDEF \
- {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
- static PyObject *
- os_pipe2_impl(PyObject *module, int flags);
- static PyObject *
- os_pipe2(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int flags;
- flags = _PyLong_AsInt(arg);
- if (flags == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_pipe2_impl(module, flags);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_PIPE2) */
- #if defined(HAVE_WRITEV)
- PyDoc_STRVAR(os_writev__doc__,
- "writev($module, fd, buffers, /)\n"
- "--\n"
- "\n"
- "Iterate over buffers, and write the contents of each to a file descriptor.\n"
- "\n"
- "Returns the total number of bytes written.\n"
- "buffers must be a sequence of bytes-like objects.");
- #define OS_WRITEV_METHODDEF \
- {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__},
- static Py_ssize_t
- os_writev_impl(PyObject *module, int fd, PyObject *buffers);
- static PyObject *
- os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- PyObject *buffers;
- Py_ssize_t _return_value;
- if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- buffers = args[1];
- _return_value = os_writev_impl(module, fd, buffers);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromSsize_t(_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_WRITEV) */
- #if defined(HAVE_PWRITE)
- PyDoc_STRVAR(os_pwrite__doc__,
- "pwrite($module, fd, buffer, offset, /)\n"
- "--\n"
- "\n"
- "Write bytes to a file descriptor starting at a particular offset.\n"
- "\n"
- "Write buffer to fd, starting at offset bytes from the beginning of\n"
- "the file. Returns the number of bytes writte. Does not change the\n"
- "current file offset.");
- #define OS_PWRITE_METHODDEF \
- {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__},
- static Py_ssize_t
- os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
- static PyObject *
- os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- Py_buffer buffer = {NULL, NULL};
- Py_off_t offset;
- Py_ssize_t _return_value;
- if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&buffer, 'C')) {
- _PyArg_BadArgument("pwrite", "argument 2", "contiguous buffer", args[1]);
- goto exit;
- }
- if (!Py_off_t_converter(args[2], &offset)) {
- goto exit;
- }
- _return_value = os_pwrite_impl(module, fd, &buffer, offset);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromSsize_t(_return_value);
- exit:
- /* Cleanup for buffer */
- if (buffer.obj) {
- PyBuffer_Release(&buffer);
- }
- return return_value;
- }
- #endif /* defined(HAVE_PWRITE) */
- #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
- PyDoc_STRVAR(os_pwritev__doc__,
- "pwritev($module, fd, buffers, offset, flags=0, /)\n"
- "--\n"
- "\n"
- "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
- "\n"
- "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
- "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
- "buffer is written before proceeding to second, and so on. The operating system may\n"
- "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
- "This function writes the contents of each object to the file descriptor and returns\n"
- "the total number of bytes written.\n"
- "\n"
- "The flags argument contains a bitwise OR of zero or more of the following flags:\n"
- "\n"
- "- RWF_DSYNC\n"
- "- RWF_SYNC\n"
- "- RWF_APPEND\n"
- "\n"
- "Using non-zero flags requires Linux 4.7 or newer.");
- #define OS_PWRITEV_METHODDEF \
- {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__},
- static Py_ssize_t
- os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
- int flags);
- static PyObject *
- os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- PyObject *buffers;
- Py_off_t offset;
- int flags = 0;
- Py_ssize_t _return_value;
- if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- buffers = args[1];
- if (!Py_off_t_converter(args[2], &offset)) {
- goto exit;
- }
- if (nargs < 4) {
- goto skip_optional;
- }
- flags = _PyLong_AsInt(args[3]);
- if (flags == -1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional:
- _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromSsize_t(_return_value);
- exit:
- return return_value;
- }
- #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
- #if defined(HAVE_COPY_FILE_RANGE)
- PyDoc_STRVAR(os_copy_file_range__doc__,
- "copy_file_range($module, /, src, dst, count, offset_src=None,\n"
- " offset_dst=None)\n"
- "--\n"
- "\n"
- "Copy count bytes from one file descriptor to another.\n"
- "\n"
- " src\n"
- " Source file descriptor.\n"
- " dst\n"
- " Destination file descriptor.\n"
- " count\n"
- " Number of bytes to copy.\n"
- " offset_src\n"
- " Starting offset in src.\n"
- " offset_dst\n"
- " Starting offset in dst.\n"
- "\n"
- "If offset_src is None, then src is read from the current position;\n"
- "respectively for offset_dst.");
- #define OS_COPY_FILE_RANGE_METHODDEF \
- {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__},
- static PyObject *
- os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count,
- PyObject *offset_src, PyObject *offset_dst);
- static PyObject *
- os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 5
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "copy_file_range",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[5];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
- int src;
- int dst;
- Py_ssize_t count;
- PyObject *offset_src = Py_None;
- PyObject *offset_dst = Py_None;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 5, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- src = _PyLong_AsInt(args[0]);
- if (src == -1 && PyErr_Occurred()) {
- goto exit;
- }
- dst = _PyLong_AsInt(args[1]);
- if (dst == -1 && PyErr_Occurred()) {
- goto exit;
- }
- {
- Py_ssize_t ival = -1;
- PyObject *iobj = _PyNumber_Index(args[2]);
- if (iobj != NULL) {
- ival = PyLong_AsSsize_t(iobj);
- Py_DECREF(iobj);
- }
- if (ival == -1 && PyErr_Occurred()) {
- goto exit;
- }
- count = ival;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[3]) {
- offset_src = args[3];
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- offset_dst = args[4];
- skip_optional_pos:
- return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_COPY_FILE_RANGE) */
- #if ((defined(HAVE_SPLICE) && !defined(_AIX)))
- PyDoc_STRVAR(os_splice__doc__,
- "splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n"
- " flags=0)\n"
- "--\n"
- "\n"
- "Transfer count bytes from one pipe to a descriptor or vice versa.\n"
- "\n"
- " src\n"
- " Source file descriptor.\n"
- " dst\n"
- " Destination file descriptor.\n"
- " count\n"
- " Number of bytes to copy.\n"
- " offset_src\n"
- " Starting offset in src.\n"
- " offset_dst\n"
- " Starting offset in dst.\n"
- " flags\n"
- " Flags to modify the semantics of the call.\n"
- "\n"
- "If offset_src is None, then src is read from the current position;\n"
- "respectively for offset_dst. The offset associated to the file\n"
- "descriptor that refers to a pipe must be None.");
- #define OS_SPLICE_METHODDEF \
- {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__},
- static PyObject *
- os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count,
- PyObject *offset_src, PyObject *offset_dst,
- unsigned int flags);
- static PyObject *
- os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 6
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "splice",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[6];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
- int src;
- int dst;
- Py_ssize_t count;
- PyObject *offset_src = Py_None;
- PyObject *offset_dst = Py_None;
- unsigned int flags = 0;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 6, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- src = _PyLong_AsInt(args[0]);
- if (src == -1 && PyErr_Occurred()) {
- goto exit;
- }
- dst = _PyLong_AsInt(args[1]);
- if (dst == -1 && PyErr_Occurred()) {
- goto exit;
- }
- {
- Py_ssize_t ival = -1;
- PyObject *iobj = _PyNumber_Index(args[2]);
- if (iobj != NULL) {
- ival = PyLong_AsSsize_t(iobj);
- Py_DECREF(iobj);
- }
- if (ival == -1 && PyErr_Occurred()) {
- goto exit;
- }
- count = ival;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[3]) {
- offset_src = args[3];
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- if (args[4]) {
- offset_dst = args[4];
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) {
- goto exit;
- }
- skip_optional_pos:
- return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags);
- exit:
- return return_value;
- }
- #endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */
- #if defined(HAVE_MKFIFO)
- PyDoc_STRVAR(os_mkfifo__doc__,
- "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
- "--\n"
- "\n"
- "Create a \"fifo\" (a POSIX named pipe).\n"
- "\n"
- "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that directory.\n"
- "dir_fd may not be implemented on your platform.\n"
- " If it is unavailable, using it will raise a NotImplementedError.");
- #define OS_MKFIFO_METHODDEF \
- {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
- static PyObject *
- os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
- static PyObject *
- os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "mkfifo",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0);
- int mode = 438;
- int dir_fd = DEFAULT_DIR_FD;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[1]) {
- mode = _PyLong_AsInt(args[1]);
- if (mode == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- skip_optional_pos:
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(HAVE_MKFIFO) */
- #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
- PyDoc_STRVAR(os_mknod__doc__,
- "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
- "--\n"
- "\n"
- "Create a node in the file system.\n"
- "\n"
- "Create a node in the file system (file, device special file or named pipe)\n"
- "at path. mode specifies both the permissions to use and the\n"
- "type of node to be created, being combined (bitwise OR) with one of\n"
- "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
- "device defines the newly created device special file (probably using\n"
- "os.makedev()). Otherwise device is ignored.\n"
- "\n"
- "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
- " and path should be relative; path will then be relative to that directory.\n"
- "dir_fd may not be implemented on your platform.\n"
- " If it is unavailable, using it will raise a NotImplementedError.");
- #define OS_MKNOD_METHODDEF \
- {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
- static PyObject *
- os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
- int dir_fd);
- static PyObject *
- os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 4
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "mknod",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[4];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0);
- int mode = 384;
- dev_t device = 0;
- int dir_fd = DEFAULT_DIR_FD;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[1]) {
- mode = _PyLong_AsInt(args[1]);
- if (mode == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- if (args[2]) {
- if (!_Py_Dev_Converter(args[2], &device)) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- skip_optional_pos:
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
- #if defined(HAVE_DEVICE_MACROS)
- PyDoc_STRVAR(os_major__doc__,
- "major($module, device, /)\n"
- "--\n"
- "\n"
- "Extracts a device major number from a raw device number.");
- #define OS_MAJOR_METHODDEF \
- {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
- static PyObject *
- os_major_impl(PyObject *module, dev_t device);
- static PyObject *
- os_major(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- dev_t device;
- if (!_Py_Dev_Converter(arg, &device)) {
- goto exit;
- }
- return_value = os_major_impl(module, device);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_DEVICE_MACROS) */
- #if defined(HAVE_DEVICE_MACROS)
- PyDoc_STRVAR(os_minor__doc__,
- "minor($module, device, /)\n"
- "--\n"
- "\n"
- "Extracts a device minor number from a raw device number.");
- #define OS_MINOR_METHODDEF \
- {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
- static PyObject *
- os_minor_impl(PyObject *module, dev_t device);
- static PyObject *
- os_minor(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- dev_t device;
- if (!_Py_Dev_Converter(arg, &device)) {
- goto exit;
- }
- return_value = os_minor_impl(module, device);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_DEVICE_MACROS) */
- #if defined(HAVE_DEVICE_MACROS)
- PyDoc_STRVAR(os_makedev__doc__,
- "makedev($module, major, minor, /)\n"
- "--\n"
- "\n"
- "Composes a raw device number from the major and minor device numbers.");
- #define OS_MAKEDEV_METHODDEF \
- {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__},
- static dev_t
- os_makedev_impl(PyObject *module, dev_t major, dev_t minor);
- static PyObject *
- os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- dev_t major;
- dev_t minor;
- dev_t _return_value;
- if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
- goto exit;
- }
- if (!_Py_Dev_Converter(args[0], &major)) {
- goto exit;
- }
- if (!_Py_Dev_Converter(args[1], &minor)) {
- goto exit;
- }
- _return_value = os_makedev_impl(module, major, minor);
- if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = _PyLong_FromDev(_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_DEVICE_MACROS) */
- #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
- PyDoc_STRVAR(os_ftruncate__doc__,
- "ftruncate($module, fd, length, /)\n"
- "--\n"
- "\n"
- "Truncate a file, specified by file descriptor, to a specific length.");
- #define OS_FTRUNCATE_METHODDEF \
- {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__},
- static PyObject *
- os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
- static PyObject *
- os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- Py_off_t length;
- if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!Py_off_t_converter(args[1], &length)) {
- goto exit;
- }
- return_value = os_ftruncate_impl(module, fd, length);
- exit:
- return return_value;
- }
- #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
- #if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
- PyDoc_STRVAR(os_truncate__doc__,
- "truncate($module, /, path, length)\n"
- "--\n"
- "\n"
- "Truncate a file, specified by path, to a specific length.\n"
- "\n"
- "On some platforms, path may also be specified as an open file descriptor.\n"
- " If this functionality is unavailable, using it raises an exception.");
- #define OS_TRUNCATE_METHODDEF \
- {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
- static PyObject *
- os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
- static PyObject *
- os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(length), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "length", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "truncate",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE);
- Py_off_t length;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!Py_off_t_converter(args[1], &length)) {
- goto exit;
- }
- return_value = os_truncate_impl(module, &path, length);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
- #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__))
- PyDoc_STRVAR(os_posix_fallocate__doc__,
- "posix_fallocate($module, fd, offset, length, /)\n"
- "--\n"
- "\n"
- "Ensure a file has allocated at least a particular number of bytes on disk.\n"
- "\n"
- "Ensure that the file specified by fd encompasses a range of bytes\n"
- "starting at offset bytes from the beginning and continuing for length bytes.");
- #define OS_POSIX_FALLOCATE_METHODDEF \
- {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__},
- static PyObject *
- os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
- Py_off_t length);
- static PyObject *
- os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- Py_off_t offset;
- Py_off_t length;
- if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!Py_off_t_converter(args[1], &offset)) {
- goto exit;
- }
- if (!Py_off_t_converter(args[2], &length)) {
- goto exit;
- }
- return_value = os_posix_fallocate_impl(module, fd, offset, length);
- exit:
- return return_value;
- }
- #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) */
- #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
- PyDoc_STRVAR(os_posix_fadvise__doc__,
- "posix_fadvise($module, fd, offset, length, advice, /)\n"
- "--\n"
- "\n"
- "Announce an intention to access data in a specific pattern.\n"
- "\n"
- "Announce an intention to access data in a specific pattern, thus allowing\n"
- "the kernel to make optimizations.\n"
- "The advice applies to the region of the file specified by fd starting at\n"
- "offset and continuing for length bytes.\n"
- "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
- "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
- "POSIX_FADV_DONTNEED.");
- #define OS_POSIX_FADVISE_METHODDEF \
- {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__},
- static PyObject *
- os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
- Py_off_t length, int advice);
- static PyObject *
- os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- Py_off_t offset;
- Py_off_t length;
- int advice;
- if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!Py_off_t_converter(args[1], &offset)) {
- goto exit;
- }
- if (!Py_off_t_converter(args[2], &length)) {
- goto exit;
- }
- advice = _PyLong_AsInt(args[3]);
- if (advice == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
- exit:
- return return_value;
- }
- #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os_putenv__doc__,
- "putenv($module, name, value, /)\n"
- "--\n"
- "\n"
- "Change or add an environment variable.");
- #define OS_PUTENV_METHODDEF \
- {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
- static PyObject *
- os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
- static PyObject *
- os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- PyObject *name;
- PyObject *value;
- if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("putenv", "argument 1", "str", args[0]);
- goto exit;
- }
- if (PyUnicode_READY(args[0]) == -1) {
- goto exit;
- }
- name = args[0];
- if (!PyUnicode_Check(args[1])) {
- _PyArg_BadArgument("putenv", "argument 2", "str", args[1]);
- goto exit;
- }
- if (PyUnicode_READY(args[1]) == -1) {
- goto exit;
- }
- value = args[1];
- return_value = os_putenv_impl(module, name, value);
- exit:
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if !defined(MS_WINDOWS)
- PyDoc_STRVAR(os_putenv__doc__,
- "putenv($module, name, value, /)\n"
- "--\n"
- "\n"
- "Change or add an environment variable.");
- #define OS_PUTENV_METHODDEF \
- {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
- static PyObject *
- os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
- static PyObject *
- os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- PyObject *name = NULL;
- PyObject *value = NULL;
- if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
- goto exit;
- }
- if (!PyUnicode_FSConverter(args[0], &name)) {
- goto exit;
- }
- if (!PyUnicode_FSConverter(args[1], &value)) {
- goto exit;
- }
- return_value = os_putenv_impl(module, name, value);
- exit:
- /* Cleanup for name */
- Py_XDECREF(name);
- /* Cleanup for value */
- Py_XDECREF(value);
- return return_value;
- }
- #endif /* !defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os_unsetenv__doc__,
- "unsetenv($module, name, /)\n"
- "--\n"
- "\n"
- "Delete an environment variable.");
- #define OS_UNSETENV_METHODDEF \
- {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
- static PyObject *
- os_unsetenv_impl(PyObject *module, PyObject *name);
- static PyObject *
- os_unsetenv(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- PyObject *name;
- if (!PyUnicode_Check(arg)) {
- _PyArg_BadArgument("unsetenv", "argument", "str", arg);
- goto exit;
- }
- if (PyUnicode_READY(arg) == -1) {
- goto exit;
- }
- name = arg;
- return_value = os_unsetenv_impl(module, name);
- exit:
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if !defined(MS_WINDOWS)
- PyDoc_STRVAR(os_unsetenv__doc__,
- "unsetenv($module, name, /)\n"
- "--\n"
- "\n"
- "Delete an environment variable.");
- #define OS_UNSETENV_METHODDEF \
- {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
- static PyObject *
- os_unsetenv_impl(PyObject *module, PyObject *name);
- static PyObject *
- os_unsetenv(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- PyObject *name = NULL;
- if (!PyUnicode_FSConverter(arg, &name)) {
- goto exit;
- }
- return_value = os_unsetenv_impl(module, name);
- exit:
- /* Cleanup for name */
- Py_XDECREF(name);
- return return_value;
- }
- #endif /* !defined(MS_WINDOWS) */
- PyDoc_STRVAR(os_strerror__doc__,
- "strerror($module, code, /)\n"
- "--\n"
- "\n"
- "Translate an error code to a message string.");
- #define OS_STRERROR_METHODDEF \
- {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
- static PyObject *
- os_strerror_impl(PyObject *module, int code);
- static PyObject *
- os_strerror(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int code;
- code = _PyLong_AsInt(arg);
- if (code == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_strerror_impl(module, code);
- exit:
- return return_value;
- }
- #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
- PyDoc_STRVAR(os_WCOREDUMP__doc__,
- "WCOREDUMP($module, status, /)\n"
- "--\n"
- "\n"
- "Return True if the process returning status was dumped to a core file.");
- #define OS_WCOREDUMP_METHODDEF \
- {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
- static int
- os_WCOREDUMP_impl(PyObject *module, int status);
- static PyObject *
- os_WCOREDUMP(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int status;
- int _return_value;
- status = _PyLong_AsInt(arg);
- if (status == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_WCOREDUMP_impl(module, status);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
- #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
- PyDoc_STRVAR(os_WIFCONTINUED__doc__,
- "WIFCONTINUED($module, /, status)\n"
- "--\n"
- "\n"
- "Return True if a particular process was continued from a job control stop.\n"
- "\n"
- "Return True if the process returning status was continued from a\n"
- "job control stop.");
- #define OS_WIFCONTINUED_METHODDEF \
- {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
- static int
- os_WIFCONTINUED_impl(PyObject *module, int status);
- static PyObject *
- os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(status), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"status", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "WIFCONTINUED",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int status;
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- status = _PyLong_AsInt(args[0]);
- if (status == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_WIFCONTINUED_impl(module, status);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
- #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
- PyDoc_STRVAR(os_WIFSTOPPED__doc__,
- "WIFSTOPPED($module, /, status)\n"
- "--\n"
- "\n"
- "Return True if the process returning status was stopped.");
- #define OS_WIFSTOPPED_METHODDEF \
- {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
- static int
- os_WIFSTOPPED_impl(PyObject *module, int status);
- static PyObject *
- os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(status), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"status", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "WIFSTOPPED",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int status;
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- status = _PyLong_AsInt(args[0]);
- if (status == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_WIFSTOPPED_impl(module, status);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
- #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
- PyDoc_STRVAR(os_WIFSIGNALED__doc__,
- "WIFSIGNALED($module, /, status)\n"
- "--\n"
- "\n"
- "Return True if the process returning status was terminated by a signal.");
- #define OS_WIFSIGNALED_METHODDEF \
- {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
- static int
- os_WIFSIGNALED_impl(PyObject *module, int status);
- static PyObject *
- os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(status), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"status", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "WIFSIGNALED",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int status;
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- status = _PyLong_AsInt(args[0]);
- if (status == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_WIFSIGNALED_impl(module, status);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
- #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
- PyDoc_STRVAR(os_WIFEXITED__doc__,
- "WIFEXITED($module, /, status)\n"
- "--\n"
- "\n"
- "Return True if the process returning status exited via the exit() system call.");
- #define OS_WIFEXITED_METHODDEF \
- {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
- static int
- os_WIFEXITED_impl(PyObject *module, int status);
- static PyObject *
- os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(status), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"status", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "WIFEXITED",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int status;
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- status = _PyLong_AsInt(args[0]);
- if (status == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_WIFEXITED_impl(module, status);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
- #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
- PyDoc_STRVAR(os_WEXITSTATUS__doc__,
- "WEXITSTATUS($module, /, status)\n"
- "--\n"
- "\n"
- "Return the process return code from status.");
- #define OS_WEXITSTATUS_METHODDEF \
- {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
- static int
- os_WEXITSTATUS_impl(PyObject *module, int status);
- static PyObject *
- os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(status), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"status", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "WEXITSTATUS",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int status;
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- status = _PyLong_AsInt(args[0]);
- if (status == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_WEXITSTATUS_impl(module, status);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
- #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
- PyDoc_STRVAR(os_WTERMSIG__doc__,
- "WTERMSIG($module, /, status)\n"
- "--\n"
- "\n"
- "Return the signal that terminated the process that provided the status value.");
- #define OS_WTERMSIG_METHODDEF \
- {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
- static int
- os_WTERMSIG_impl(PyObject *module, int status);
- static PyObject *
- os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(status), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"status", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "WTERMSIG",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int status;
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- status = _PyLong_AsInt(args[0]);
- if (status == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_WTERMSIG_impl(module, status);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
- #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
- PyDoc_STRVAR(os_WSTOPSIG__doc__,
- "WSTOPSIG($module, /, status)\n"
- "--\n"
- "\n"
- "Return the signal that stopped the process that provided the status value.");
- #define OS_WSTOPSIG_METHODDEF \
- {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
- static int
- os_WSTOPSIG_impl(PyObject *module, int status);
- static PyObject *
- os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(status), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"status", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "WSTOPSIG",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int status;
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- status = _PyLong_AsInt(args[0]);
- if (status == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_WSTOPSIG_impl(module, status);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
- #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
- PyDoc_STRVAR(os_fstatvfs__doc__,
- "fstatvfs($module, fd, /)\n"
- "--\n"
- "\n"
- "Perform an fstatvfs system call on the given fd.\n"
- "\n"
- "Equivalent to statvfs(fd).");
- #define OS_FSTATVFS_METHODDEF \
- {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
- static PyObject *
- os_fstatvfs_impl(PyObject *module, int fd);
- static PyObject *
- os_fstatvfs(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int fd;
- fd = _PyLong_AsInt(arg);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_fstatvfs_impl(module, fd);
- exit:
- return return_value;
- }
- #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
- #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
- PyDoc_STRVAR(os_statvfs__doc__,
- "statvfs($module, /, path)\n"
- "--\n"
- "\n"
- "Perform a statvfs system call on the given path.\n"
- "\n"
- "path may always be specified as a string.\n"
- "On some platforms, path may also be specified as an open file descriptor.\n"
- " If this functionality is unavailable, using it raises an exception.");
- #define OS_STATVFS_METHODDEF \
- {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
- static PyObject *
- os_statvfs_impl(PyObject *module, path_t *path);
- static PyObject *
- os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "statvfs",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- return_value = os_statvfs_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os__getdiskusage__doc__,
- "_getdiskusage($module, /, path)\n"
- "--\n"
- "\n"
- "Return disk usage statistics about the given path as a (total, free) tuple.");
- #define OS__GETDISKUSAGE_METHODDEF \
- {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
- static PyObject *
- os__getdiskusage_impl(PyObject *module, path_t *path);
- static PyObject *
- os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_getdiskusage",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- return_value = os__getdiskusage_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(HAVE_FPATHCONF)
- PyDoc_STRVAR(os_fpathconf__doc__,
- "fpathconf($module, fd, name, /)\n"
- "--\n"
- "\n"
- "Return the configuration limit name for the file descriptor fd.\n"
- "\n"
- "If there is no limit, return -1.");
- #define OS_FPATHCONF_METHODDEF \
- {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__},
- static long
- os_fpathconf_impl(PyObject *module, int fd, int name);
- static PyObject *
- os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- int name;
- long _return_value;
- if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
- goto exit;
- }
- if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
- goto exit;
- }
- if (!conv_path_confname(args[1], &name)) {
- goto exit;
- }
- _return_value = os_fpathconf_impl(module, fd, name);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromLong(_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_FPATHCONF) */
- #if defined(HAVE_PATHCONF)
- PyDoc_STRVAR(os_pathconf__doc__,
- "pathconf($module, /, path, name)\n"
- "--\n"
- "\n"
- "Return the configuration limit name for the file or directory path.\n"
- "\n"
- "If there is no limit, return -1.\n"
- "On some platforms, path may also be specified as an open file descriptor.\n"
- " If this functionality is unavailable, using it raises an exception.");
- #define OS_PATHCONF_METHODDEF \
- {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
- static long
- os_pathconf_impl(PyObject *module, path_t *path, int name);
- static PyObject *
- os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(name), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "name", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "pathconf",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF);
- int name;
- long _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!conv_path_confname(args[1], &name)) {
- goto exit;
- }
- _return_value = os_pathconf_impl(module, &path, name);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromLong(_return_value);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(HAVE_PATHCONF) */
- #if defined(HAVE_CONFSTR)
- PyDoc_STRVAR(os_confstr__doc__,
- "confstr($module, name, /)\n"
- "--\n"
- "\n"
- "Return a string-valued system configuration variable.");
- #define OS_CONFSTR_METHODDEF \
- {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
- static PyObject *
- os_confstr_impl(PyObject *module, int name);
- static PyObject *
- os_confstr(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int name;
- if (!conv_confstr_confname(arg, &name)) {
- goto exit;
- }
- return_value = os_confstr_impl(module, name);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_CONFSTR) */
- #if defined(HAVE_SYSCONF)
- PyDoc_STRVAR(os_sysconf__doc__,
- "sysconf($module, name, /)\n"
- "--\n"
- "\n"
- "Return an integer-valued system configuration variable.");
- #define OS_SYSCONF_METHODDEF \
- {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
- static long
- os_sysconf_impl(PyObject *module, int name);
- static PyObject *
- os_sysconf(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int name;
- long _return_value;
- if (!conv_sysconf_confname(arg, &name)) {
- goto exit;
- }
- _return_value = os_sysconf_impl(module, name);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromLong(_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SYSCONF) */
- PyDoc_STRVAR(os_abort__doc__,
- "abort($module, /)\n"
- "--\n"
- "\n"
- "Abort the interpreter immediately.\n"
- "\n"
- "This function \'dumps core\' or otherwise fails in the hardest way possible\n"
- "on the hosting operating system. This function never returns.");
- #define OS_ABORT_METHODDEF \
- {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
- static PyObject *
- os_abort_impl(PyObject *module);
- static PyObject *
- os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_abort_impl(module);
- }
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os_startfile__doc__,
- "startfile($module, /, filepath, operation=<unrepresentable>,\n"
- " arguments=<unrepresentable>, cwd=None, show_cmd=1)\n"
- "--\n"
- "\n"
- "Start a file with its associated application.\n"
- "\n"
- "When \"operation\" is not specified or \"open\", this acts like\n"
- "double-clicking the file in Explorer, or giving the file name as an\n"
- "argument to the DOS \"start\" command: the file is opened with whatever\n"
- "application (if any) its extension is associated.\n"
- "When another \"operation\" is given, it specifies what should be done with\n"
- "the file. A typical operation is \"print\".\n"
- "\n"
- "\"arguments\" is passed to the application, but should be omitted if the\n"
- "file is a document.\n"
- "\n"
- "\"cwd\" is the working directory for the operation. If \"filepath\" is\n"
- "relative, it will be resolved against this directory. This argument\n"
- "should usually be an absolute path.\n"
- "\n"
- "\"show_cmd\" can be used to override the recommended visibility option.\n"
- "See the Windows ShellExecute documentation for values.\n"
- "\n"
- "startfile returns as soon as the associated application is launched.\n"
- "There is no option to wait for the application to close, and no way\n"
- "to retrieve the application\'s exit status.\n"
- "\n"
- "The filepath is relative to the current directory. If you want to use\n"
- "an absolute path, make sure the first character is not a slash (\"/\");\n"
- "the underlying Win32 ShellExecute function doesn\'t work if it is.");
- #define OS_STARTFILE_METHODDEF \
- {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
- static PyObject *
- os_startfile_impl(PyObject *module, path_t *filepath,
- const Py_UNICODE *operation, const Py_UNICODE *arguments,
- path_t *cwd, int show_cmd);
- static PyObject *
- os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 5
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "startfile",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[5];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0);
- const Py_UNICODE *operation = NULL;
- const Py_UNICODE *arguments = NULL;
- path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0);
- int show_cmd = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 5, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &filepath)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[1]) {
- if (!PyUnicode_Check(args[1])) {
- _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]);
- goto exit;
- }
- operation = PyUnicode_AsWideCharString(args[1], NULL);
- if (operation == NULL) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- if (args[2]) {
- if (!PyUnicode_Check(args[2])) {
- _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]);
- goto exit;
- }
- arguments = PyUnicode_AsWideCharString(args[2], NULL);
- if (arguments == NULL) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- if (args[3]) {
- if (!path_converter(args[3], &cwd)) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- show_cmd = _PyLong_AsInt(args[4]);
- if (show_cmd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional_pos:
- return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd);
- exit:
- /* Cleanup for filepath */
- path_cleanup(&filepath);
- /* Cleanup for operation */
- PyMem_Free((void *)operation);
- /* Cleanup for arguments */
- PyMem_Free((void *)arguments);
- /* Cleanup for cwd */
- path_cleanup(&cwd);
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(HAVE_GETLOADAVG)
- PyDoc_STRVAR(os_getloadavg__doc__,
- "getloadavg($module, /)\n"
- "--\n"
- "\n"
- "Return average recent system load information.\n"
- "\n"
- "Return the number of processes in the system run queue averaged over\n"
- "the last 1, 5, and 15 minutes as a tuple of three floats.\n"
- "Raises OSError if the load average was unobtainable.");
- #define OS_GETLOADAVG_METHODDEF \
- {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
- static PyObject *
- os_getloadavg_impl(PyObject *module);
- static PyObject *
- os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getloadavg_impl(module);
- }
- #endif /* defined(HAVE_GETLOADAVG) */
- PyDoc_STRVAR(os_device_encoding__doc__,
- "device_encoding($module, /, fd)\n"
- "--\n"
- "\n"
- "Return a string describing the encoding of a terminal\'s file descriptor.\n"
- "\n"
- "The file descriptor must be attached to a terminal.\n"
- "If the device is not a terminal, return None.");
- #define OS_DEVICE_ENCODING_METHODDEF \
- {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
- static PyObject *
- os_device_encoding_impl(PyObject *module, int fd);
- static PyObject *
- os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "device_encoding",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int fd;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_device_encoding_impl(module, fd);
- exit:
- return return_value;
- }
- #if defined(HAVE_SETRESUID)
- PyDoc_STRVAR(os_setresuid__doc__,
- "setresuid($module, ruid, euid, suid, /)\n"
- "--\n"
- "\n"
- "Set the current process\'s real, effective, and saved user ids.");
- #define OS_SETRESUID_METHODDEF \
- {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__},
- static PyObject *
- os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
- static PyObject *
- os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- uid_t ruid;
- uid_t euid;
- uid_t suid;
- if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
- goto exit;
- }
- if (!_Py_Uid_Converter(args[0], &ruid)) {
- goto exit;
- }
- if (!_Py_Uid_Converter(args[1], &euid)) {
- goto exit;
- }
- if (!_Py_Uid_Converter(args[2], &suid)) {
- goto exit;
- }
- return_value = os_setresuid_impl(module, ruid, euid, suid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SETRESUID) */
- #if defined(HAVE_SETRESGID)
- PyDoc_STRVAR(os_setresgid__doc__,
- "setresgid($module, rgid, egid, sgid, /)\n"
- "--\n"
- "\n"
- "Set the current process\'s real, effective, and saved group ids.");
- #define OS_SETRESGID_METHODDEF \
- {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__},
- static PyObject *
- os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
- static PyObject *
- os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- gid_t rgid;
- gid_t egid;
- gid_t sgid;
- if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
- goto exit;
- }
- if (!_Py_Gid_Converter(args[0], &rgid)) {
- goto exit;
- }
- if (!_Py_Gid_Converter(args[1], &egid)) {
- goto exit;
- }
- if (!_Py_Gid_Converter(args[2], &sgid)) {
- goto exit;
- }
- return_value = os_setresgid_impl(module, rgid, egid, sgid);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_SETRESGID) */
- #if defined(HAVE_GETRESUID)
- PyDoc_STRVAR(os_getresuid__doc__,
- "getresuid($module, /)\n"
- "--\n"
- "\n"
- "Return a tuple of the current process\'s real, effective, and saved user ids.");
- #define OS_GETRESUID_METHODDEF \
- {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
- static PyObject *
- os_getresuid_impl(PyObject *module);
- static PyObject *
- os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getresuid_impl(module);
- }
- #endif /* defined(HAVE_GETRESUID) */
- #if defined(HAVE_GETRESGID)
- PyDoc_STRVAR(os_getresgid__doc__,
- "getresgid($module, /)\n"
- "--\n"
- "\n"
- "Return a tuple of the current process\'s real, effective, and saved group ids.");
- #define OS_GETRESGID_METHODDEF \
- {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
- static PyObject *
- os_getresgid_impl(PyObject *module);
- static PyObject *
- os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_getresgid_impl(module);
- }
- #endif /* defined(HAVE_GETRESGID) */
- #if defined(USE_XATTRS)
- PyDoc_STRVAR(os_getxattr__doc__,
- "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Return the value of extended attribute attribute on path.\n"
- "\n"
- "path may be either a string, a path-like object, or an open file descriptor.\n"
- "If follow_symlinks is False, and the last element of the path is a symbolic\n"
- " link, getxattr will examine the symbolic link itself instead of the file\n"
- " the link points to.");
- #define OS_GETXATTR_METHODDEF \
- {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
- static PyObject *
- os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
- int follow_symlinks);
- static PyObject *
- os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "getxattr",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
- path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1);
- path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0);
- int follow_symlinks = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!path_converter(args[1], &attribute)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- follow_symlinks = PyObject_IsTrue(args[2]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- /* Cleanup for attribute */
- path_cleanup(&attribute);
- return return_value;
- }
- #endif /* defined(USE_XATTRS) */
- #if defined(USE_XATTRS)
- PyDoc_STRVAR(os_setxattr__doc__,
- "setxattr($module, /, path, attribute, value, flags=0, *,\n"
- " follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Set extended attribute attribute on path to value.\n"
- "\n"
- "path may be either a string, a path-like object, or an open file descriptor.\n"
- "If follow_symlinks is False, and the last element of the path is a symbolic\n"
- " link, setxattr will modify the symbolic link itself instead of the file\n"
- " the link points to.");
- #define OS_SETXATTR_METHODDEF \
- {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
- static PyObject *
- os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
- Py_buffer *value, int flags, int follow_symlinks);
- static PyObject *
- os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 5
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "setxattr",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[5];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
- path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1);
- path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0);
- Py_buffer value = {NULL, NULL};
- int flags = 0;
- int follow_symlinks = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!path_converter(args[1], &attribute)) {
- goto exit;
- }
- if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&value, 'C')) {
- _PyArg_BadArgument("setxattr", "argument 'value'", "contiguous buffer", args[2]);
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[3]) {
- flags = _PyLong_AsInt(args[3]);
- if (flags == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- skip_optional_pos:
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- follow_symlinks = PyObject_IsTrue(args[4]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- /* Cleanup for attribute */
- path_cleanup(&attribute);
- /* Cleanup for value */
- if (value.obj) {
- PyBuffer_Release(&value);
- }
- return return_value;
- }
- #endif /* defined(USE_XATTRS) */
- #if defined(USE_XATTRS)
- PyDoc_STRVAR(os_removexattr__doc__,
- "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Remove extended attribute attribute on path.\n"
- "\n"
- "path may be either a string, a path-like object, or an open file descriptor.\n"
- "If follow_symlinks is False, and the last element of the path is a symbolic\n"
- " link, removexattr will modify the symbolic link itself instead of the file\n"
- " the link points to.");
- #define OS_REMOVEXATTR_METHODDEF \
- {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
- static PyObject *
- os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
- int follow_symlinks);
- static PyObject *
- os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "removexattr",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
- path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1);
- path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0);
- int follow_symlinks = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!path_converter(args[1], &attribute)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- follow_symlinks = PyObject_IsTrue(args[2]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- /* Cleanup for attribute */
- path_cleanup(&attribute);
- return return_value;
- }
- #endif /* defined(USE_XATTRS) */
- #if defined(USE_XATTRS)
- PyDoc_STRVAR(os_listxattr__doc__,
- "listxattr($module, /, path=None, *, follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Return a list of extended attributes on path.\n"
- "\n"
- "path may be either None, a string, a path-like object, or an open file descriptor.\n"
- "if path is None, listxattr will examine the current directory.\n"
- "If follow_symlinks is False, and the last element of the path is a symbolic\n"
- " link, listxattr will examine the symbolic link itself instead of the file\n"
- " the link points to.");
- #define OS_LISTXATTR_METHODDEF \
- {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
- static PyObject *
- os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
- static PyObject *
- os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "listxattr",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
- path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1);
- int follow_symlinks = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[0]) {
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- skip_optional_pos:
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- follow_symlinks = PyObject_IsTrue(args[1]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_listxattr_impl(module, &path, follow_symlinks);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* defined(USE_XATTRS) */
- PyDoc_STRVAR(os_urandom__doc__,
- "urandom($module, size, /)\n"
- "--\n"
- "\n"
- "Return a bytes object containing random bytes suitable for cryptographic use.");
- #define OS_URANDOM_METHODDEF \
- {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
- static PyObject *
- os_urandom_impl(PyObject *module, Py_ssize_t size);
- static PyObject *
- os_urandom(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- Py_ssize_t size;
- {
- Py_ssize_t ival = -1;
- PyObject *iobj = _PyNumber_Index(arg);
- if (iobj != NULL) {
- ival = PyLong_AsSsize_t(iobj);
- Py_DECREF(iobj);
- }
- if (ival == -1 && PyErr_Occurred()) {
- goto exit;
- }
- size = ival;
- }
- return_value = os_urandom_impl(module, size);
- exit:
- return return_value;
- }
- #if defined(HAVE_MEMFD_CREATE)
- PyDoc_STRVAR(os_memfd_create__doc__,
- "memfd_create($module, /, name, flags=MFD_CLOEXEC)\n"
- "--\n"
- "\n");
- #define OS_MEMFD_CREATE_METHODDEF \
- {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__},
- static PyObject *
- os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags);
- static PyObject *
- os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(name), &_Py_ID(flags), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"name", "flags", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "memfd_create",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- PyObject *name = NULL;
- unsigned int flags = MFD_CLOEXEC;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!PyUnicode_FSConverter(args[0], &name)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- flags = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
- if (flags == (unsigned int)-1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional_pos:
- return_value = os_memfd_create_impl(module, name, flags);
- exit:
- /* Cleanup for name */
- Py_XDECREF(name);
- return return_value;
- }
- #endif /* defined(HAVE_MEMFD_CREATE) */
- #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
- PyDoc_STRVAR(os_eventfd__doc__,
- "eventfd($module, /, initval, flags=EFD_CLOEXEC)\n"
- "--\n"
- "\n"
- "Creates and returns an event notification file descriptor.");
- #define OS_EVENTFD_METHODDEF \
- {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__},
- static PyObject *
- os_eventfd_impl(PyObject *module, unsigned int initval, int flags);
- static PyObject *
- os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(initval), &_Py_ID(flags), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"initval", "flags", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "eventfd",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- unsigned int initval;
- int flags = EFD_CLOEXEC;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- flags = _PyLong_AsInt(args[1]);
- if (flags == -1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional_pos:
- return_value = os_eventfd_impl(module, initval, flags);
- exit:
- return return_value;
- }
- #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
- #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
- PyDoc_STRVAR(os_eventfd_read__doc__,
- "eventfd_read($module, /, fd)\n"
- "--\n"
- "\n"
- "Read eventfd value");
- #define OS_EVENTFD_READ_METHODDEF \
- {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__},
- static PyObject *
- os_eventfd_read_impl(PyObject *module, int fd);
- static PyObject *
- os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(fd), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"fd", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "eventfd_read",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- int fd;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
- goto exit;
- }
- return_value = os_eventfd_read_impl(module, fd);
- exit:
- return return_value;
- }
- #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
- #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
- PyDoc_STRVAR(os_eventfd_write__doc__,
- "eventfd_write($module, /, fd, value)\n"
- "--\n"
- "\n"
- "Write eventfd value.");
- #define OS_EVENTFD_WRITE_METHODDEF \
- {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__},
- static PyObject *
- os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value);
- static PyObject *
- os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(fd), &_Py_ID(value), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"fd", "value", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "eventfd_write",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- int fd;
- unsigned long long value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
- goto exit;
- }
- if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) {
- goto exit;
- }
- return_value = os_eventfd_write_impl(module, fd, value);
- exit:
- return return_value;
- }
- #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
- #if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL))
- PyDoc_STRVAR(os_get_terminal_size__doc__,
- "get_terminal_size($module, fd=<unrepresentable>, /)\n"
- "--\n"
- "\n"
- "Return the size of the terminal window as (columns, lines).\n"
- "\n"
- "The optional argument fd (default standard output) specifies\n"
- "which file descriptor should be queried.\n"
- "\n"
- "If the file descriptor is not connected to a terminal, an OSError\n"
- "is thrown.\n"
- "\n"
- "This function will only be defined if an implementation is\n"
- "available for this system.\n"
- "\n"
- "shutil.get_terminal_size is the high-level function which should\n"
- "normally be used, os.get_terminal_size is the low-level implementation.");
- #define OS_GET_TERMINAL_SIZE_METHODDEF \
- {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__},
- static PyObject *
- os_get_terminal_size_impl(PyObject *module, int fd);
- static PyObject *
- os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd = fileno(stdout);
- if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) {
- goto exit;
- }
- if (nargs < 1) {
- goto skip_optional;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional:
- return_value = os_get_terminal_size_impl(module, fd);
- exit:
- return return_value;
- }
- #endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */
- PyDoc_STRVAR(os_cpu_count__doc__,
- "cpu_count($module, /)\n"
- "--\n"
- "\n"
- "Return the number of CPUs in the system; return None if indeterminable.\n"
- "\n"
- "This number is not equivalent to the number of CPUs the current process can\n"
- "use. The number of usable CPUs can be obtained with\n"
- "``len(os.sched_getaffinity(0))``");
- #define OS_CPU_COUNT_METHODDEF \
- {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
- static PyObject *
- os_cpu_count_impl(PyObject *module);
- static PyObject *
- os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
- {
- return os_cpu_count_impl(module);
- }
- PyDoc_STRVAR(os_get_inheritable__doc__,
- "get_inheritable($module, fd, /)\n"
- "--\n"
- "\n"
- "Get the close-on-exe flag of the specified file descriptor.");
- #define OS_GET_INHERITABLE_METHODDEF \
- {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
- static int
- os_get_inheritable_impl(PyObject *module, int fd);
- static PyObject *
- os_get_inheritable(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int fd;
- int _return_value;
- fd = _PyLong_AsInt(arg);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_get_inheritable_impl(module, fd);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- PyDoc_STRVAR(os_set_inheritable__doc__,
- "set_inheritable($module, fd, inheritable, /)\n"
- "--\n"
- "\n"
- "Set the inheritable flag of the specified file descriptor.");
- #define OS_SET_INHERITABLE_METHODDEF \
- {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__},
- static PyObject *
- os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
- static PyObject *
- os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- int inheritable;
- if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- inheritable = _PyLong_AsInt(args[1]);
- if (inheritable == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = os_set_inheritable_impl(module, fd, inheritable);
- exit:
- return return_value;
- }
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os_get_handle_inheritable__doc__,
- "get_handle_inheritable($module, handle, /)\n"
- "--\n"
- "\n"
- "Get the close-on-exe flag of the specified file descriptor.");
- #define OS_GET_HANDLE_INHERITABLE_METHODDEF \
- {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
- static int
- os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
- static PyObject *
- os_get_handle_inheritable(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- intptr_t handle;
- int _return_value;
- if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
- goto exit;
- }
- _return_value = os_get_handle_inheritable_impl(module, handle);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- #if defined(MS_WINDOWS)
- PyDoc_STRVAR(os_set_handle_inheritable__doc__,
- "set_handle_inheritable($module, handle, inheritable, /)\n"
- "--\n"
- "\n"
- "Set the inheritable flag of the specified handle.");
- #define OS_SET_HANDLE_INHERITABLE_METHODDEF \
- {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__},
- static PyObject *
- os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
- int inheritable);
- static PyObject *
- os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- intptr_t handle;
- int inheritable;
- if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
- &handle, &inheritable)) {
- goto exit;
- }
- return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
- exit:
- return return_value;
- }
- #endif /* defined(MS_WINDOWS) */
- PyDoc_STRVAR(os_get_blocking__doc__,
- "get_blocking($module, fd, /)\n"
- "--\n"
- "\n"
- "Get the blocking mode of the file descriptor.\n"
- "\n"
- "Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
- #define OS_GET_BLOCKING_METHODDEF \
- {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
- static int
- os_get_blocking_impl(PyObject *module, int fd);
- static PyObject *
- os_get_blocking(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- int fd;
- int _return_value;
- fd = _PyLong_AsInt(arg);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- _return_value = os_get_blocking_impl(module, fd);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- PyDoc_STRVAR(os_set_blocking__doc__,
- "set_blocking($module, fd, blocking, /)\n"
- "--\n"
- "\n"
- "Set the blocking mode of the specified file descriptor.\n"
- "\n"
- "Set the O_NONBLOCK flag if blocking is False,\n"
- "clear the O_NONBLOCK flag otherwise.");
- #define OS_SET_BLOCKING_METHODDEF \
- {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__},
- static PyObject *
- os_set_blocking_impl(PyObject *module, int fd, int blocking);
- static PyObject *
- os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- int fd;
- int blocking;
- if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
- goto exit;
- }
- fd = _PyLong_AsInt(args[0]);
- if (fd == -1 && PyErr_Occurred()) {
- goto exit;
- }
- blocking = PyObject_IsTrue(args[1]);
- if (blocking < 0) {
- goto exit;
- }
- return_value = os_set_blocking_impl(module, fd, blocking);
- exit:
- return return_value;
- }
- PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
- "is_symlink($self, /)\n"
- "--\n"
- "\n"
- "Return True if the entry is a symbolic link; cached per entry.");
- #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
- {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__},
- static int
- os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class);
- static PyObject *
- os_DirEntry_is_symlink(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- int _return_value;
- if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
- PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments");
- goto exit;
- }
- _return_value = os_DirEntry_is_symlink_impl(self, defining_class);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- PyDoc_STRVAR(os_DirEntry_is_junction__doc__,
- "is_junction($self, /)\n"
- "--\n"
- "\n"
- "Return True if the entry is a junction; cached per entry.");
- #define OS_DIRENTRY_IS_JUNCTION_METHODDEF \
- {"is_junction", _PyCFunction_CAST(os_DirEntry_is_junction), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_junction__doc__},
- static int
- os_DirEntry_is_junction_impl(DirEntry *self, PyTypeObject *defining_class);
- static PyObject *
- os_DirEntry_is_junction(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- int _return_value;
- if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
- PyErr_SetString(PyExc_TypeError, "is_junction() takes no arguments");
- goto exit;
- }
- _return_value = os_DirEntry_is_junction_impl(self, defining_class);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- PyDoc_STRVAR(os_DirEntry_stat__doc__,
- "stat($self, /, *, follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Return stat_result object for the entry; cached per entry.");
- #define OS_DIRENTRY_STAT_METHODDEF \
- {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
- static PyObject *
- os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class,
- int follow_symlinks);
- static PyObject *
- os_DirEntry_stat(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "stat",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
- int follow_symlinks = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- follow_symlinks = PyObject_IsTrue(args[0]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = os_DirEntry_stat_impl(self, defining_class, follow_symlinks);
- exit:
- return return_value;
- }
- PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
- "is_dir($self, /, *, follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Return True if the entry is a directory; cached per entry.");
- #define OS_DIRENTRY_IS_DIR_METHODDEF \
- {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
- static int
- os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class,
- int follow_symlinks);
- static PyObject *
- os_DirEntry_is_dir(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "is_dir",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
- int follow_symlinks = 1;
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- follow_symlinks = PyObject_IsTrue(args[0]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- _return_value = os_DirEntry_is_dir_impl(self, defining_class, follow_symlinks);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- PyDoc_STRVAR(os_DirEntry_is_file__doc__,
- "is_file($self, /, *, follow_symlinks=True)\n"
- "--\n"
- "\n"
- "Return True if the entry is a file; cached per entry.");
- #define OS_DIRENTRY_IS_FILE_METHODDEF \
- {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
- static int
- os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class,
- int follow_symlinks);
- static PyObject *
- os_DirEntry_is_file(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(follow_symlinks), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"follow_symlinks", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "is_file",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
- int follow_symlinks = 1;
- int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- follow_symlinks = PyObject_IsTrue(args[0]);
- if (follow_symlinks < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- _return_value = os_DirEntry_is_file_impl(self, defining_class, follow_symlinks);
- if ((_return_value == -1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyBool_FromLong((long)_return_value);
- exit:
- return return_value;
- }
- PyDoc_STRVAR(os_DirEntry_inode__doc__,
- "inode($self, /)\n"
- "--\n"
- "\n"
- "Return inode of the entry; cached per entry.");
- #define OS_DIRENTRY_INODE_METHODDEF \
- {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
- static PyObject *
- os_DirEntry_inode_impl(DirEntry *self);
- static PyObject *
- os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
- {
- return os_DirEntry_inode_impl(self);
- }
- PyDoc_STRVAR(os_DirEntry___fspath____doc__,
- "__fspath__($self, /)\n"
- "--\n"
- "\n"
- "Returns the path for the entry.");
- #define OS_DIRENTRY___FSPATH___METHODDEF \
- {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
- static PyObject *
- os_DirEntry___fspath___impl(DirEntry *self);
- static PyObject *
- os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
- {
- return os_DirEntry___fspath___impl(self);
- }
- PyDoc_STRVAR(os_scandir__doc__,
- "scandir($module, /, path=None)\n"
- "--\n"
- "\n"
- "Return an iterator of DirEntry objects for given path.\n"
- "\n"
- "path can be specified as either str, bytes, or a path-like object. If path\n"
- "is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
- "all other circumstances they will be str.\n"
- "\n"
- "If path is None, uses the path=\'.\'.");
- #define OS_SCANDIR_METHODDEF \
- {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
- static PyObject *
- os_scandir_impl(PyObject *module, path_t *path);
- static PyObject *
- os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "scandir",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
- path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- skip_optional_pos:
- return_value = os_scandir_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- PyDoc_STRVAR(os_fspath__doc__,
- "fspath($module, /, path)\n"
- "--\n"
- "\n"
- "Return the file system path representation of the object.\n"
- "\n"
- "If the object is str or bytes, then allow it to pass through as-is. If the\n"
- "object defines __fspath__(), then return the result of that method. All other\n"
- "types raise a TypeError.");
- #define OS_FSPATH_METHODDEF \
- {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
- static PyObject *
- os_fspath_impl(PyObject *module, PyObject *path);
- static PyObject *
- os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "fspath",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- PyObject *path;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- path = args[0];
- return_value = os_fspath_impl(module, path);
- exit:
- return return_value;
- }
- #if defined(HAVE_GETRANDOM_SYSCALL)
- PyDoc_STRVAR(os_getrandom__doc__,
- "getrandom($module, /, size, flags=0)\n"
- "--\n"
- "\n"
- "Obtain a series of random bytes.");
- #define OS_GETRANDOM_METHODDEF \
- {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
- static PyObject *
- os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
- static PyObject *
- os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(size), &_Py_ID(flags), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"size", "flags", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "getrandom",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- Py_ssize_t size;
- int flags = 0;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- {
- Py_ssize_t ival = -1;
- PyObject *iobj = _PyNumber_Index(args[0]);
- if (iobj != NULL) {
- ival = PyLong_AsSsize_t(iobj);
- Py_DECREF(iobj);
- }
- if (ival == -1 && PyErr_Occurred()) {
- goto exit;
- }
- size = ival;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- flags = _PyLong_AsInt(args[1]);
- if (flags == -1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional_pos:
- return_value = os_getrandom_impl(module, size, flags);
- exit:
- return return_value;
- }
- #endif /* defined(HAVE_GETRANDOM_SYSCALL) */
- #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
- PyDoc_STRVAR(os__add_dll_directory__doc__,
- "_add_dll_directory($module, /, path)\n"
- "--\n"
- "\n"
- "Add a path to the DLL search path.\n"
- "\n"
- "This search path is used when resolving dependencies for imported\n"
- "extension modules (the module itself is resolved through sys.path),\n"
- "and also by ctypes.\n"
- "\n"
- "Returns an opaque value that may be passed to os.remove_dll_directory\n"
- "to remove this directory from the search path.");
- #define OS__ADD_DLL_DIRECTORY_METHODDEF \
- {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__},
- static PyObject *
- os__add_dll_directory_impl(PyObject *module, path_t *path);
- static PyObject *
- os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_add_dll_directory",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
- goto exit;
- }
- return_value = os__add_dll_directory_impl(module, &path);
- exit:
- /* Cleanup for path */
- path_cleanup(&path);
- return return_value;
- }
- #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
- #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
- PyDoc_STRVAR(os__remove_dll_directory__doc__,
- "_remove_dll_directory($module, /, cookie)\n"
- "--\n"
- "\n"
- "Removes a path from the DLL search path.\n"
- "\n"
- "The parameter is an opaque value that was returned from\n"
- "os.add_dll_directory. You can only remove directories that you added\n"
- "yourself.");
- #define OS__REMOVE_DLL_DIRECTORY_METHODDEF \
- {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__},
- static PyObject *
- os__remove_dll_directory_impl(PyObject *module, PyObject *cookie);
- static PyObject *
- os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(cookie), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"cookie", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_remove_dll_directory",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- PyObject *cookie;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- cookie = args[0];
- return_value = os__remove_dll_directory_impl(module, cookie);
- exit:
- return return_value;
- }
- #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
- #if (defined(WIFEXITED) || defined(MS_WINDOWS))
- PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__,
- "waitstatus_to_exitcode($module, /, status)\n"
- "--\n"
- "\n"
- "Convert a wait status to an exit code.\n"
- "\n"
- "On Unix:\n"
- "\n"
- "* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n"
- "* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n"
- "* Otherwise, raise a ValueError.\n"
- "\n"
- "On Windows, return status shifted right by 8 bits.\n"
- "\n"
- "On Unix, if the process is being traced or if waitpid() was called with\n"
- "WUNTRACED option, the caller must first check if WIFSTOPPED(status) is true.\n"
- "This function must not be called if WIFSTOPPED(status) is true.");
- #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF \
- {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__},
- static PyObject *
- os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj);
- static PyObject *
- os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(status), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"status", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "waitstatus_to_exitcode",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
- PyObject *status_obj;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- status_obj = args[0];
- return_value = os_waitstatus_to_exitcode_impl(module, status_obj);
- exit:
- return return_value;
- }
- #endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */
- #ifndef OS_TTYNAME_METHODDEF
- #define OS_TTYNAME_METHODDEF
- #endif /* !defined(OS_TTYNAME_METHODDEF) */
- #ifndef OS_CTERMID_METHODDEF
- #define OS_CTERMID_METHODDEF
- #endif /* !defined(OS_CTERMID_METHODDEF) */
- #ifndef OS_FCHDIR_METHODDEF
- #define OS_FCHDIR_METHODDEF
- #endif /* !defined(OS_FCHDIR_METHODDEF) */
- #ifndef OS_FCHMOD_METHODDEF
- #define OS_FCHMOD_METHODDEF
- #endif /* !defined(OS_FCHMOD_METHODDEF) */
- #ifndef OS_LCHMOD_METHODDEF
- #define OS_LCHMOD_METHODDEF
- #endif /* !defined(OS_LCHMOD_METHODDEF) */
- #ifndef OS_CHFLAGS_METHODDEF
- #define OS_CHFLAGS_METHODDEF
- #endif /* !defined(OS_CHFLAGS_METHODDEF) */
- #ifndef OS_LCHFLAGS_METHODDEF
- #define OS_LCHFLAGS_METHODDEF
- #endif /* !defined(OS_LCHFLAGS_METHODDEF) */
- #ifndef OS_CHROOT_METHODDEF
- #define OS_CHROOT_METHODDEF
- #endif /* !defined(OS_CHROOT_METHODDEF) */
- #ifndef OS_FSYNC_METHODDEF
- #define OS_FSYNC_METHODDEF
- #endif /* !defined(OS_FSYNC_METHODDEF) */
- #ifndef OS_SYNC_METHODDEF
- #define OS_SYNC_METHODDEF
- #endif /* !defined(OS_SYNC_METHODDEF) */
- #ifndef OS_FDATASYNC_METHODDEF
- #define OS_FDATASYNC_METHODDEF
- #endif /* !defined(OS_FDATASYNC_METHODDEF) */
- #ifndef OS_CHOWN_METHODDEF
- #define OS_CHOWN_METHODDEF
- #endif /* !defined(OS_CHOWN_METHODDEF) */
- #ifndef OS_FCHOWN_METHODDEF
- #define OS_FCHOWN_METHODDEF
- #endif /* !defined(OS_FCHOWN_METHODDEF) */
- #ifndef OS_LCHOWN_METHODDEF
- #define OS_LCHOWN_METHODDEF
- #endif /* !defined(OS_LCHOWN_METHODDEF) */
- #ifndef OS_LINK_METHODDEF
- #define OS_LINK_METHODDEF
- #endif /* !defined(OS_LINK_METHODDEF) */
- #ifndef OS_LISTDRIVES_METHODDEF
- #define OS_LISTDRIVES_METHODDEF
- #endif /* !defined(OS_LISTDRIVES_METHODDEF) */
- #ifndef OS_LISTVOLUMES_METHODDEF
- #define OS_LISTVOLUMES_METHODDEF
- #endif /* !defined(OS_LISTVOLUMES_METHODDEF) */
- #ifndef OS_LISTMOUNTS_METHODDEF
- #define OS_LISTMOUNTS_METHODDEF
- #endif /* !defined(OS_LISTMOUNTS_METHODDEF) */
- #ifndef OS__PATH_ISDEVDRIVE_METHODDEF
- #define OS__PATH_ISDEVDRIVE_METHODDEF
- #endif /* !defined(OS__PATH_ISDEVDRIVE_METHODDEF) */
- #ifndef OS__GETFULLPATHNAME_METHODDEF
- #define OS__GETFULLPATHNAME_METHODDEF
- #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
- #ifndef OS__GETFINALPATHNAME_METHODDEF
- #define OS__GETFINALPATHNAME_METHODDEF
- #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
- #ifndef OS__GETVOLUMEPATHNAME_METHODDEF
- #define OS__GETVOLUMEPATHNAME_METHODDEF
- #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
- #ifndef OS__PATH_SPLITROOT_METHODDEF
- #define OS__PATH_SPLITROOT_METHODDEF
- #endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */
- #ifndef OS__PATH_EXISTS_METHODDEF
- #define OS__PATH_EXISTS_METHODDEF
- #endif /* !defined(OS__PATH_EXISTS_METHODDEF) */
- #ifndef OS__PATH_ISDIR_METHODDEF
- #define OS__PATH_ISDIR_METHODDEF
- #endif /* !defined(OS__PATH_ISDIR_METHODDEF) */
- #ifndef OS__PATH_ISFILE_METHODDEF
- #define OS__PATH_ISFILE_METHODDEF
- #endif /* !defined(OS__PATH_ISFILE_METHODDEF) */
- #ifndef OS__PATH_ISLINK_METHODDEF
- #define OS__PATH_ISLINK_METHODDEF
- #endif /* !defined(OS__PATH_ISLINK_METHODDEF) */
- #ifndef OS_NICE_METHODDEF
- #define OS_NICE_METHODDEF
- #endif /* !defined(OS_NICE_METHODDEF) */
- #ifndef OS_GETPRIORITY_METHODDEF
- #define OS_GETPRIORITY_METHODDEF
- #endif /* !defined(OS_GETPRIORITY_METHODDEF) */
- #ifndef OS_SETPRIORITY_METHODDEF
- #define OS_SETPRIORITY_METHODDEF
- #endif /* !defined(OS_SETPRIORITY_METHODDEF) */
- #ifndef OS_SYSTEM_METHODDEF
- #define OS_SYSTEM_METHODDEF
- #endif /* !defined(OS_SYSTEM_METHODDEF) */
- #ifndef OS_UMASK_METHODDEF
- #define OS_UMASK_METHODDEF
- #endif /* !defined(OS_UMASK_METHODDEF) */
- #ifndef OS_UNAME_METHODDEF
- #define OS_UNAME_METHODDEF
- #endif /* !defined(OS_UNAME_METHODDEF) */
- #ifndef OS_EXECV_METHODDEF
- #define OS_EXECV_METHODDEF
- #endif /* !defined(OS_EXECV_METHODDEF) */
- #ifndef OS_EXECVE_METHODDEF
- #define OS_EXECVE_METHODDEF
- #endif /* !defined(OS_EXECVE_METHODDEF) */
- #ifndef OS_POSIX_SPAWN_METHODDEF
- #define OS_POSIX_SPAWN_METHODDEF
- #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
- #ifndef OS_POSIX_SPAWNP_METHODDEF
- #define OS_POSIX_SPAWNP_METHODDEF
- #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */
- #ifndef OS_SPAWNV_METHODDEF
- #define OS_SPAWNV_METHODDEF
- #endif /* !defined(OS_SPAWNV_METHODDEF) */
- #ifndef OS_SPAWNVE_METHODDEF
- #define OS_SPAWNVE_METHODDEF
- #endif /* !defined(OS_SPAWNVE_METHODDEF) */
- #ifndef OS_REGISTER_AT_FORK_METHODDEF
- #define OS_REGISTER_AT_FORK_METHODDEF
- #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
- #ifndef OS_FORK1_METHODDEF
- #define OS_FORK1_METHODDEF
- #endif /* !defined(OS_FORK1_METHODDEF) */
- #ifndef OS_FORK_METHODDEF
- #define OS_FORK_METHODDEF
- #endif /* !defined(OS_FORK_METHODDEF) */
- #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
- #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
- #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
- #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
- #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
- #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
- #ifndef OS_SCHED_GETSCHEDULER_METHODDEF
- #define OS_SCHED_GETSCHEDULER_METHODDEF
- #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
- #ifndef OS_SCHED_SETSCHEDULER_METHODDEF
- #define OS_SCHED_SETSCHEDULER_METHODDEF
- #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
- #ifndef OS_SCHED_GETPARAM_METHODDEF
- #define OS_SCHED_GETPARAM_METHODDEF
- #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
- #ifndef OS_SCHED_SETPARAM_METHODDEF
- #define OS_SCHED_SETPARAM_METHODDEF
- #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
- #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
- #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
- #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
- #ifndef OS_SCHED_YIELD_METHODDEF
- #define OS_SCHED_YIELD_METHODDEF
- #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
- #ifndef OS_SCHED_SETAFFINITY_METHODDEF
- #define OS_SCHED_SETAFFINITY_METHODDEF
- #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
- #ifndef OS_SCHED_GETAFFINITY_METHODDEF
- #define OS_SCHED_GETAFFINITY_METHODDEF
- #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
- #ifndef OS_OPENPTY_METHODDEF
- #define OS_OPENPTY_METHODDEF
- #endif /* !defined(OS_OPENPTY_METHODDEF) */
- #ifndef OS_LOGIN_TTY_METHODDEF
- #define OS_LOGIN_TTY_METHODDEF
- #endif /* !defined(OS_LOGIN_TTY_METHODDEF) */
- #ifndef OS_FORKPTY_METHODDEF
- #define OS_FORKPTY_METHODDEF
- #endif /* !defined(OS_FORKPTY_METHODDEF) */
- #ifndef OS_GETEGID_METHODDEF
- #define OS_GETEGID_METHODDEF
- #endif /* !defined(OS_GETEGID_METHODDEF) */
- #ifndef OS_GETEUID_METHODDEF
- #define OS_GETEUID_METHODDEF
- #endif /* !defined(OS_GETEUID_METHODDEF) */
- #ifndef OS_GETGID_METHODDEF
- #define OS_GETGID_METHODDEF
- #endif /* !defined(OS_GETGID_METHODDEF) */
- #ifndef OS_GETPID_METHODDEF
- #define OS_GETPID_METHODDEF
- #endif /* !defined(OS_GETPID_METHODDEF) */
- #ifndef OS_GETGROUPLIST_METHODDEF
- #define OS_GETGROUPLIST_METHODDEF
- #endif /* !defined(OS_GETGROUPLIST_METHODDEF) */
- #ifndef OS_GETGROUPS_METHODDEF
- #define OS_GETGROUPS_METHODDEF
- #endif /* !defined(OS_GETGROUPS_METHODDEF) */
- #ifndef OS_INITGROUPS_METHODDEF
- #define OS_INITGROUPS_METHODDEF
- #endif /* !defined(OS_INITGROUPS_METHODDEF) */
- #ifndef OS_GETPGID_METHODDEF
- #define OS_GETPGID_METHODDEF
- #endif /* !defined(OS_GETPGID_METHODDEF) */
- #ifndef OS_GETPGRP_METHODDEF
- #define OS_GETPGRP_METHODDEF
- #endif /* !defined(OS_GETPGRP_METHODDEF) */
- #ifndef OS_SETPGRP_METHODDEF
- #define OS_SETPGRP_METHODDEF
- #endif /* !defined(OS_SETPGRP_METHODDEF) */
- #ifndef OS_GETPPID_METHODDEF
- #define OS_GETPPID_METHODDEF
- #endif /* !defined(OS_GETPPID_METHODDEF) */
- #ifndef OS_GETLOGIN_METHODDEF
- #define OS_GETLOGIN_METHODDEF
- #endif /* !defined(OS_GETLOGIN_METHODDEF) */
- #ifndef OS_GETUID_METHODDEF
- #define OS_GETUID_METHODDEF
- #endif /* !defined(OS_GETUID_METHODDEF) */
- #ifndef OS_KILL_METHODDEF
- #define OS_KILL_METHODDEF
- #endif /* !defined(OS_KILL_METHODDEF) */
- #ifndef OS_KILLPG_METHODDEF
- #define OS_KILLPG_METHODDEF
- #endif /* !defined(OS_KILLPG_METHODDEF) */
- #ifndef OS_PLOCK_METHODDEF
- #define OS_PLOCK_METHODDEF
- #endif /* !defined(OS_PLOCK_METHODDEF) */
- #ifndef OS_SETUID_METHODDEF
- #define OS_SETUID_METHODDEF
- #endif /* !defined(OS_SETUID_METHODDEF) */
- #ifndef OS_SETEUID_METHODDEF
- #define OS_SETEUID_METHODDEF
- #endif /* !defined(OS_SETEUID_METHODDEF) */
- #ifndef OS_SETEGID_METHODDEF
- #define OS_SETEGID_METHODDEF
- #endif /* !defined(OS_SETEGID_METHODDEF) */
- #ifndef OS_SETREUID_METHODDEF
- #define OS_SETREUID_METHODDEF
- #endif /* !defined(OS_SETREUID_METHODDEF) */
- #ifndef OS_SETREGID_METHODDEF
- #define OS_SETREGID_METHODDEF
- #endif /* !defined(OS_SETREGID_METHODDEF) */
- #ifndef OS_SETGID_METHODDEF
- #define OS_SETGID_METHODDEF
- #endif /* !defined(OS_SETGID_METHODDEF) */
- #ifndef OS_SETGROUPS_METHODDEF
- #define OS_SETGROUPS_METHODDEF
- #endif /* !defined(OS_SETGROUPS_METHODDEF) */
- #ifndef OS_WAIT3_METHODDEF
- #define OS_WAIT3_METHODDEF
- #endif /* !defined(OS_WAIT3_METHODDEF) */
- #ifndef OS_WAIT4_METHODDEF
- #define OS_WAIT4_METHODDEF
- #endif /* !defined(OS_WAIT4_METHODDEF) */
- #ifndef OS_WAITID_METHODDEF
- #define OS_WAITID_METHODDEF
- #endif /* !defined(OS_WAITID_METHODDEF) */
- #ifndef OS_WAITPID_METHODDEF
- #define OS_WAITPID_METHODDEF
- #endif /* !defined(OS_WAITPID_METHODDEF) */
- #ifndef OS_WAIT_METHODDEF
- #define OS_WAIT_METHODDEF
- #endif /* !defined(OS_WAIT_METHODDEF) */
- #ifndef OS_PIDFD_OPEN_METHODDEF
- #define OS_PIDFD_OPEN_METHODDEF
- #endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */
- #ifndef OS_SETNS_METHODDEF
- #define OS_SETNS_METHODDEF
- #endif /* !defined(OS_SETNS_METHODDEF) */
- #ifndef OS_UNSHARE_METHODDEF
- #define OS_UNSHARE_METHODDEF
- #endif /* !defined(OS_UNSHARE_METHODDEF) */
- #ifndef OS_READLINK_METHODDEF
- #define OS_READLINK_METHODDEF
- #endif /* !defined(OS_READLINK_METHODDEF) */
- #ifndef OS_SYMLINK_METHODDEF
- #define OS_SYMLINK_METHODDEF
- #endif /* !defined(OS_SYMLINK_METHODDEF) */
- #ifndef OS_TIMES_METHODDEF
- #define OS_TIMES_METHODDEF
- #endif /* !defined(OS_TIMES_METHODDEF) */
- #ifndef OS_GETSID_METHODDEF
- #define OS_GETSID_METHODDEF
- #endif /* !defined(OS_GETSID_METHODDEF) */
- #ifndef OS_SETSID_METHODDEF
- #define OS_SETSID_METHODDEF
- #endif /* !defined(OS_SETSID_METHODDEF) */
- #ifndef OS_SETPGID_METHODDEF
- #define OS_SETPGID_METHODDEF
- #endif /* !defined(OS_SETPGID_METHODDEF) */
- #ifndef OS_TCGETPGRP_METHODDEF
- #define OS_TCGETPGRP_METHODDEF
- #endif /* !defined(OS_TCGETPGRP_METHODDEF) */
- #ifndef OS_TCSETPGRP_METHODDEF
- #define OS_TCSETPGRP_METHODDEF
- #endif /* !defined(OS_TCSETPGRP_METHODDEF) */
- #ifndef OS_DUP2_METHODDEF
- #define OS_DUP2_METHODDEF
- #endif /* !defined(OS_DUP2_METHODDEF) */
- #ifndef OS_LOCKF_METHODDEF
- #define OS_LOCKF_METHODDEF
- #endif /* !defined(OS_LOCKF_METHODDEF) */
- #ifndef OS_READV_METHODDEF
- #define OS_READV_METHODDEF
- #endif /* !defined(OS_READV_METHODDEF) */
- #ifndef OS_PREAD_METHODDEF
- #define OS_PREAD_METHODDEF
- #endif /* !defined(OS_PREAD_METHODDEF) */
- #ifndef OS_PREADV_METHODDEF
- #define OS_PREADV_METHODDEF
- #endif /* !defined(OS_PREADV_METHODDEF) */
- #ifndef OS_SENDFILE_METHODDEF
- #define OS_SENDFILE_METHODDEF
- #endif /* !defined(OS_SENDFILE_METHODDEF) */
- #ifndef OS__FCOPYFILE_METHODDEF
- #define OS__FCOPYFILE_METHODDEF
- #endif /* !defined(OS__FCOPYFILE_METHODDEF) */
- #ifndef OS_PIPE_METHODDEF
- #define OS_PIPE_METHODDEF
- #endif /* !defined(OS_PIPE_METHODDEF) */
- #ifndef OS_PIPE2_METHODDEF
- #define OS_PIPE2_METHODDEF
- #endif /* !defined(OS_PIPE2_METHODDEF) */
- #ifndef OS_WRITEV_METHODDEF
- #define OS_WRITEV_METHODDEF
- #endif /* !defined(OS_WRITEV_METHODDEF) */
- #ifndef OS_PWRITE_METHODDEF
- #define OS_PWRITE_METHODDEF
- #endif /* !defined(OS_PWRITE_METHODDEF) */
- #ifndef OS_PWRITEV_METHODDEF
- #define OS_PWRITEV_METHODDEF
- #endif /* !defined(OS_PWRITEV_METHODDEF) */
- #ifndef OS_COPY_FILE_RANGE_METHODDEF
- #define OS_COPY_FILE_RANGE_METHODDEF
- #endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */
- #ifndef OS_SPLICE_METHODDEF
- #define OS_SPLICE_METHODDEF
- #endif /* !defined(OS_SPLICE_METHODDEF) */
- #ifndef OS_MKFIFO_METHODDEF
- #define OS_MKFIFO_METHODDEF
- #endif /* !defined(OS_MKFIFO_METHODDEF) */
- #ifndef OS_MKNOD_METHODDEF
- #define OS_MKNOD_METHODDEF
- #endif /* !defined(OS_MKNOD_METHODDEF) */
- #ifndef OS_MAJOR_METHODDEF
- #define OS_MAJOR_METHODDEF
- #endif /* !defined(OS_MAJOR_METHODDEF) */
- #ifndef OS_MINOR_METHODDEF
- #define OS_MINOR_METHODDEF
- #endif /* !defined(OS_MINOR_METHODDEF) */
- #ifndef OS_MAKEDEV_METHODDEF
- #define OS_MAKEDEV_METHODDEF
- #endif /* !defined(OS_MAKEDEV_METHODDEF) */
- #ifndef OS_FTRUNCATE_METHODDEF
- #define OS_FTRUNCATE_METHODDEF
- #endif /* !defined(OS_FTRUNCATE_METHODDEF) */
- #ifndef OS_TRUNCATE_METHODDEF
- #define OS_TRUNCATE_METHODDEF
- #endif /* !defined(OS_TRUNCATE_METHODDEF) */
- #ifndef OS_POSIX_FALLOCATE_METHODDEF
- #define OS_POSIX_FALLOCATE_METHODDEF
- #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
- #ifndef OS_POSIX_FADVISE_METHODDEF
- #define OS_POSIX_FADVISE_METHODDEF
- #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
- #ifndef OS_PUTENV_METHODDEF
- #define OS_PUTENV_METHODDEF
- #endif /* !defined(OS_PUTENV_METHODDEF) */
- #ifndef OS_UNSETENV_METHODDEF
- #define OS_UNSETENV_METHODDEF
- #endif /* !defined(OS_UNSETENV_METHODDEF) */
- #ifndef OS_WCOREDUMP_METHODDEF
- #define OS_WCOREDUMP_METHODDEF
- #endif /* !defined(OS_WCOREDUMP_METHODDEF) */
- #ifndef OS_WIFCONTINUED_METHODDEF
- #define OS_WIFCONTINUED_METHODDEF
- #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
- #ifndef OS_WIFSTOPPED_METHODDEF
- #define OS_WIFSTOPPED_METHODDEF
- #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
- #ifndef OS_WIFSIGNALED_METHODDEF
- #define OS_WIFSIGNALED_METHODDEF
- #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
- #ifndef OS_WIFEXITED_METHODDEF
- #define OS_WIFEXITED_METHODDEF
- #endif /* !defined(OS_WIFEXITED_METHODDEF) */
- #ifndef OS_WEXITSTATUS_METHODDEF
- #define OS_WEXITSTATUS_METHODDEF
- #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
- #ifndef OS_WTERMSIG_METHODDEF
- #define OS_WTERMSIG_METHODDEF
- #endif /* !defined(OS_WTERMSIG_METHODDEF) */
- #ifndef OS_WSTOPSIG_METHODDEF
- #define OS_WSTOPSIG_METHODDEF
- #endif /* !defined(OS_WSTOPSIG_METHODDEF) */
- #ifndef OS_FSTATVFS_METHODDEF
- #define OS_FSTATVFS_METHODDEF
- #endif /* !defined(OS_FSTATVFS_METHODDEF) */
- #ifndef OS_STATVFS_METHODDEF
- #define OS_STATVFS_METHODDEF
- #endif /* !defined(OS_STATVFS_METHODDEF) */
- #ifndef OS__GETDISKUSAGE_METHODDEF
- #define OS__GETDISKUSAGE_METHODDEF
- #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
- #ifndef OS_FPATHCONF_METHODDEF
- #define OS_FPATHCONF_METHODDEF
- #endif /* !defined(OS_FPATHCONF_METHODDEF) */
- #ifndef OS_PATHCONF_METHODDEF
- #define OS_PATHCONF_METHODDEF
- #endif /* !defined(OS_PATHCONF_METHODDEF) */
- #ifndef OS_CONFSTR_METHODDEF
- #define OS_CONFSTR_METHODDEF
- #endif /* !defined(OS_CONFSTR_METHODDEF) */
- #ifndef OS_SYSCONF_METHODDEF
- #define OS_SYSCONF_METHODDEF
- #endif /* !defined(OS_SYSCONF_METHODDEF) */
- #ifndef OS_STARTFILE_METHODDEF
- #define OS_STARTFILE_METHODDEF
- #endif /* !defined(OS_STARTFILE_METHODDEF) */
- #ifndef OS_GETLOADAVG_METHODDEF
- #define OS_GETLOADAVG_METHODDEF
- #endif /* !defined(OS_GETLOADAVG_METHODDEF) */
- #ifndef OS_SETRESUID_METHODDEF
- #define OS_SETRESUID_METHODDEF
- #endif /* !defined(OS_SETRESUID_METHODDEF) */
- #ifndef OS_SETRESGID_METHODDEF
- #define OS_SETRESGID_METHODDEF
- #endif /* !defined(OS_SETRESGID_METHODDEF) */
- #ifndef OS_GETRESUID_METHODDEF
- #define OS_GETRESUID_METHODDEF
- #endif /* !defined(OS_GETRESUID_METHODDEF) */
- #ifndef OS_GETRESGID_METHODDEF
- #define OS_GETRESGID_METHODDEF
- #endif /* !defined(OS_GETRESGID_METHODDEF) */
- #ifndef OS_GETXATTR_METHODDEF
- #define OS_GETXATTR_METHODDEF
- #endif /* !defined(OS_GETXATTR_METHODDEF) */
- #ifndef OS_SETXATTR_METHODDEF
- #define OS_SETXATTR_METHODDEF
- #endif /* !defined(OS_SETXATTR_METHODDEF) */
- #ifndef OS_REMOVEXATTR_METHODDEF
- #define OS_REMOVEXATTR_METHODDEF
- #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
- #ifndef OS_LISTXATTR_METHODDEF
- #define OS_LISTXATTR_METHODDEF
- #endif /* !defined(OS_LISTXATTR_METHODDEF) */
- #ifndef OS_MEMFD_CREATE_METHODDEF
- #define OS_MEMFD_CREATE_METHODDEF
- #endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */
- #ifndef OS_EVENTFD_METHODDEF
- #define OS_EVENTFD_METHODDEF
- #endif /* !defined(OS_EVENTFD_METHODDEF) */
- #ifndef OS_EVENTFD_READ_METHODDEF
- #define OS_EVENTFD_READ_METHODDEF
- #endif /* !defined(OS_EVENTFD_READ_METHODDEF) */
- #ifndef OS_EVENTFD_WRITE_METHODDEF
- #define OS_EVENTFD_WRITE_METHODDEF
- #endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */
- #ifndef OS_GET_TERMINAL_SIZE_METHODDEF
- #define OS_GET_TERMINAL_SIZE_METHODDEF
- #endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */
- #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
- #define OS_GET_HANDLE_INHERITABLE_METHODDEF
- #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
- #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
- #define OS_SET_HANDLE_INHERITABLE_METHODDEF
- #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
- #ifndef OS_GETRANDOM_METHODDEF
- #define OS_GETRANDOM_METHODDEF
- #endif /* !defined(OS_GETRANDOM_METHODDEF) */
- #ifndef OS__ADD_DLL_DIRECTORY_METHODDEF
- #define OS__ADD_DLL_DIRECTORY_METHODDEF
- #endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */
- #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
- #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
- #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
- #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
- #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
- #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
- /*[clinic end generated code: output=6f0c08f692891c72 input=a9049054013a1b77]*/
|