@@ -46,6 +46,7 @@ func init() {
46
46
47
47
methods := []* py.Method {
48
48
py .MustNewMethod ("_exit" , _exit , 0 , "Immediate program termination." ),
49
+ py .MustNewMethod ("close" , closefd , 0 , closefd_doc ),
49
50
py .MustNewMethod ("fdopen" , fdopen , 0 , fdopen_doc ),
50
51
py .MustNewMethod ("getcwd" , getCwd , 0 , "Get the current working directory" ),
51
52
py .MustNewMethod ("getcwdb" , getCwdb , 0 , "Get the current working directory in a byte slice" ),
@@ -98,6 +99,35 @@ func getEnvVariables() py.StringDict {
98
99
return dict
99
100
}
100
101
102
+ const closefd_doc = `Close a file descriptor`
103
+
104
+ func closefd (self py.Object , args py.Tuple , kwargs py.StringDict ) (py.Object , error ) {
105
+ var (
106
+ pyfd py.Object
107
+ )
108
+ err := py .ParseTupleAndKeywords (args , kwargs , "i" , []string {"fd" }, & pyfd )
109
+ if err != nil {
110
+ return nil , err
111
+ }
112
+
113
+ var (
114
+ fd = uintptr (pyfd .(py.Int ))
115
+ name = strconv .Itoa (int (fd ))
116
+ )
117
+
118
+ f := os .NewFile (fd , name )
119
+ if f == nil {
120
+ return nil , py .ExceptionNewf (py .OSError , "Bad file descriptor" )
121
+ }
122
+
123
+ err = f .Close ()
124
+ if err != nil {
125
+ return nil , err
126
+ }
127
+
128
+ return py .None , nil
129
+ }
130
+
101
131
const fdopen_doc = `# Supply os.fdopen()`
102
132
103
133
func fdopen (self py.Object , args py.Tuple , kwargs py.StringDict ) (py.Object , error ) {
0 commit comments