blob: 55f189d72781e81f08e325af3d2fd1b822722aaa [file] [log] [blame]
Guido van Rossum228d8072001-03-02 05:58:11 +00001/* RISCOS module implementation */
2
Guido van Rossume877f8b2001-10-24 20:13:15 +00003#include "oslib/osfscontrol.h"
4#include "oslib/osgbpb.h"
5#include "oslib/os.h"
6#include "oslib/osfile.h"
7#include "unixstuff.h"
Guido van Rossum228d8072001-03-02 05:58:11 +00008
Martin v. Löwisa94568a2003-05-10 07:36:56 +00009#include <sys/fcntl.h>
10
Guido van Rossum228d8072001-03-02 05:58:11 +000011#include "Python.h"
Guido van Rossumbd67d6f2001-10-27 21:16:16 +000012#include "structseq.h"
Guido van Rossum228d8072001-03-02 05:58:11 +000013
14#include <errno.h>
15
16static os_error *e;
17
Guido van Rossume877f8b2001-10-24 20:13:15 +000018/*static PyObject *RiscosError;*/ /* Exception riscos.error */
Guido van Rossum228d8072001-03-02 05:58:11 +000019
Guido van Rossume877f8b2001-10-24 20:13:15 +000020static PyObject *riscos_error(char *s)
21{
22 PyErr_SetString(PyExc_OSError, s);
23 return NULL;
Guido van Rossum228d8072001-03-02 05:58:11 +000024}
25
Guido van Rossume877f8b2001-10-24 20:13:15 +000026static PyObject *riscos_oserror(void)
27{
28 return riscos_error(e->errmess);
29}
30
Guido van Rossum228d8072001-03-02 05:58:11 +000031
32/* RISCOS file commands */
33
34static PyObject *riscos_remove(PyObject *self,PyObject *args)
35{ char *path1;
36 if (!PyArg_Parse(args, "s", &path1)) return NULL;
Guido van Rossume877f8b2001-10-24 20:13:15 +000037 if (remove(path1)) return PyErr_SetFromErrno(PyExc_OSError);
Guido van Rossum228d8072001-03-02 05:58:11 +000038 Py_INCREF(Py_None);
39 return Py_None;
40}
41
42static PyObject *riscos_rename(PyObject *self,PyObject *args)
43{ char *path1, *path2;
44 if (!PyArg_Parse(args, "(ss)", &path1, &path2)) return NULL;
Guido van Rossume877f8b2001-10-24 20:13:15 +000045 if (rename(path1,path2)) return PyErr_SetFromErrno(PyExc_OSError);
Guido van Rossum228d8072001-03-02 05:58:11 +000046 Py_INCREF(Py_None);
47 return Py_None;
48}
49
50static PyObject *riscos_system(PyObject *self,PyObject *args)
51{ char *command;
52 if (!PyArg_Parse(args, "s", &command)) return NULL;
53 return PyInt_FromLong(system(command));
54}
55
56static PyObject *riscos_chdir(PyObject *self,PyObject *args)
57{ char *path;
58 if (!PyArg_Parse(args, "s", &path)) return NULL;
59 e=xosfscontrol_dir(path);
60 if(e) return riscos_oserror();
61 Py_INCREF(Py_None);
62 return Py_None;
63}
64
65static PyObject *canon(char *path)
66{ int len;
67 PyObject *obj;
68 char *buf;
69 e=xosfscontrol_canonicalise_path(path,0,0,0,0,&len);
70 if(e) return riscos_oserror();
71 obj=PyString_FromStringAndSize(NULL,-len);
72 if(obj==NULL) return NULL;
73 buf=PyString_AsString(obj);
74 e=xosfscontrol_canonicalise_path(path,buf,0,0,1-len,&len);
75 if(len!=1) return riscos_error("Error expanding path");
76 if(!e) return obj;
77 Py_DECREF(obj);
78 return riscos_oserror();
79}
80
81static PyObject *riscos_getcwd(PyObject *self,PyObject *args)
82{ if(!PyArg_NoArgs(args)) return NULL;
83 return canon("@");
84}
85
86static PyObject *riscos_expand(PyObject *self,PyObject *args)
87{ char *path;
88 if (!PyArg_Parse(args, "s", &path)) return NULL;
89 return canon(path);
90}
91
92static PyObject *riscos_mkdir(PyObject *self,PyObject *args)
93{ char *path;
94 int mode;
95 if (!PyArg_ParseTuple(args, "s|i", &path, &mode)) return NULL;
96 e=xosfile_create_dir(path,0);
97 if(e) return riscos_oserror();
98 Py_INCREF(Py_None);
99 return Py_None;
100}
101
102static PyObject *riscos_listdir(PyObject *self,PyObject *args)
103{ char *path,buf[256];
104 PyObject *d, *v;
105 int c=0,count;
106 if (!PyArg_Parse(args, "s", &path)) return NULL;
107 d=PyList_New(0);
108 if(!d) return NULL;
109 for(;;)
110 { e=xosgbpb_dir_entries(path,(osgbpb_string_list*)buf,
111 1,c,256,0,&count,&c);
112 if(e)
113 { Py_DECREF(d);return riscos_oserror();
114 }
115 if(count)
116 { v=PyString_FromString(buf);
117 if(!v) { Py_DECREF(d);return 0;}
118 if(PyList_Append(d,v)) {Py_DECREF(d);Py_DECREF(v);return 0;}
119 }
120 if(c==-1) break;
121 }
122 return d;
123}
124
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000125PyDoc_STRVAR(stat_result__doc__,
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000126"stat_result: Result from stat or lstat.\n\n\
127This object may be accessed either as a tuple of\n\
128 (mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)\n\
129or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.\n\
130\n\
131RiscOS: The fields st_ftype, st_attrs, and st_obtype are also available.\n\
132\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000133See os.stat for more information.");
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000134
135static PyStructSequence_Field stat_result_fields[] = {
136 { "st_mode", "protection bits" },
137 { "st_ino", "inode" },
138 { "st_dev", "device" },
139 { "st_nlink", "number of hard links" },
140 { "st_uid", "user ID of owner" },
141 { "st_gid", "group ID of owner" },
142 { "st_size", "total size, in bytes" },
143 { "st_atime", "time of last access" },
144 { "st_mtime", "time of last modification" },
145 { "st_ctime", "time of last change" },
146 { "st_ftype", "file type" },
147 { "st_attrs", "attributes" },
Guido van Rossumbd67d6f2001-10-27 21:16:16 +0000148 { "st_obtype", "object type" },
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000149 { 0 }
150};
151
152static PyStructSequence_Desc stat_result_desc = {
Guido van Rossum14648392001-12-08 18:02:58 +0000153 "riscos.stat_result",
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000154 stat_result__doc__,
155 stat_result_fields,
156 13
157};
158
159static PyTypeObject StatResultType;
160
Guido van Rossum228d8072001-03-02 05:58:11 +0000161static PyObject *riscos_stat(PyObject *self,PyObject *args)
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000162{
163 PyObject *v;
164 char *path;
Guido van Rossum228d8072001-03-02 05:58:11 +0000165 int ob,len;
166 bits t=0;
167 bits ld,ex,at,ft,mode;
168 if (!PyArg_Parse(args, "s", &path)) return NULL;
169 e=xosfile_read_stamped_no_path(path,&ob,&ld,&ex,&len,&at,&ft);
170 if(e) return riscos_oserror();
171 switch (ob)
172 { case osfile_IS_FILE:mode=0100000;break; /* OCTAL */
173 case osfile_IS_DIR:mode=040000;break;
174 case osfile_IS_IMAGE:mode=0140000;break;
175 default:return riscos_error("Not found");
176 }
177 if(ft!=-1) t=unixtime(ld,ex);
178 mode|=(at&7)<<6;
179 mode|=((at&112)*9)>>4;
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000180
181 v = PyStructSequence_New(&StatResultType);
182
183 PyStructSequence_SET_ITEM(v, 0,
184 PyInt_FromLong((long) mode)); /*st_mode*/
185 PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) 0)); /*st_ino*/
186 PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long) 0)); /*st_dev*/
187 PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long) 0)); /*st_nlink*/
188 PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long) 0)); /*st_uid*/
189 PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long) 0)); /*st_gid*/
190 PyStructSequence_SET_ITEM(v, 6,
191 PyInt_FromLong((long) len)); /*st_size*/
192 PyStructSequence_SET_ITEM(v, 7, PyInt_FromLong((long) t)); /*st_atime*/
193 PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) t)); /*st_mtime*/
194 PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) t)); /*st_ctime*/
195 PyStructSequence_SET_ITEM(v, 10,
196 PyInt_FromLong((long) ft)); /*file type*/
197 PyStructSequence_SET_ITEM(v, 11,
198 PyInt_FromLong((long) at)); /*attributes*/
199 PyStructSequence_SET_ITEM(v, 12,
Guido van Rossumbd67d6f2001-10-27 21:16:16 +0000200 PyInt_FromLong((long) ob)); /*object type*/
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000201
202 if (PyErr_Occurred()) {
203 Py_DECREF(v);
204 return NULL;
205 }
206
207 return v;
Guido van Rossum228d8072001-03-02 05:58:11 +0000208}
209
210static PyObject *riscos_chmod(PyObject *self,PyObject *args)
211{ char *path;
212 bits mode;
213 bits attr;
214 attr=(mode&0x700)>>8;
215 attr|=(mode&7)<<4;
216 if (!PyArg_Parse(args, "(si)", &path,(int*)&mode)) return NULL;
217 e=xosfile_write_attr(path,attr);
218 if(e) return riscos_oserror();
219 Py_INCREF(Py_None);
220 return Py_None;
221}
222
Guido van Rossume877f8b2001-10-24 20:13:15 +0000223
Guido van Rossum228d8072001-03-02 05:58:11 +0000224static PyObject *riscos_utime(PyObject *self,PyObject *args)
Guido van Rossume877f8b2001-10-24 20:13:15 +0000225{
226 char *path;
227 long atime, mtime;
228 PyObject* arg;
229
230 if (!PyArg_ParseTuple(args, "sO:utime", &path, &arg))
231 return NULL;
232
233 if (arg == Py_None) {
234 /* optional time values not given */
235 Py_BEGIN_ALLOW_THREADS
236 e=xosfile_stamp(path);
237 Py_END_ALLOW_THREADS
238 if(e) return riscos_oserror();
239 }
240 else if (!PyArg_Parse(arg, "(ll)", &atime, &mtime)) {
241 PyErr_SetString(PyExc_TypeError,
242 "utime() arg 2 must be a tuple (atime, mtime)");
243 return NULL;
244 }
245 else {
246 /* catalogue info*/
247 fileswitch_object_type obj_type;
248 bits load_addr, exec_addr;
249 int size;
250 fileswitch_attr attr;
251
252 /* read old catalogue info */
253 Py_BEGIN_ALLOW_THREADS
254 e=xosfile_read_no_path(path, &obj_type, &load_addr, &exec_addr, &size, &attr);
255 Py_END_ALLOW_THREADS
256 if(e) return riscos_oserror();
257
258 /* check if load and exec address really contain filetype and date */
259 if ( (load_addr & 0xFFF00000U) != 0xFFF00000U)
260 return riscos_error("can't set date for object with load and exec addresses");
261
262 /* convert argument mtime to RISC OS load and exec address */
263 if(acorntime(&exec_addr, &load_addr, (time_t) mtime))
264 return riscos_oserror();
265
266 /* write new load and exec address */
267 Py_BEGIN_ALLOW_THREADS
268 e = xosfile_write(path, load_addr, exec_addr, attr);
269 Py_END_ALLOW_THREADS
270 if(e) return riscos_oserror();
271 }
272
Guido van Rossum228d8072001-03-02 05:58:11 +0000273 Py_INCREF(Py_None);
274 return Py_None;
275}
276
277static PyObject *riscos_settype(PyObject *self,PyObject *args)
278{ char *path,*name;
279 int type;
280 if (!PyArg_Parse(args, "(si)", &path,&type))
281 { PyErr_Clear();
282 if (!PyArg_Parse(args, "(ss)", &path,&name)) return NULL;
283 e=xosfscontrol_file_type_from_string(name,(bits*)&type);
284 if(e) return riscos_oserror();
285 }
286 e=xosfile_set_type(path,type);
287 if(e) return riscos_oserror();
288 Py_INCREF(Py_None);
289 return Py_None;
290}
291
292static PyObject *riscos_getenv(PyObject *self,PyObject *args)
293{ char *name,*value;
294 if(!PyArg_Parse(args,"s",&name)) return NULL;
295 value=getenv(name);
296 if(value) return PyString_FromString(value);
297 Py_INCREF(Py_None);
298 return Py_None;
299}
300
301static PyObject *riscos_putenv(PyObject *self,PyObject *args)
302{ char *name,*value;
303 int len;
304 os_var_type type=os_VARTYPE_LITERAL_STRING;
305 if(!PyArg_ParseTuple(args,"ss|i",&name,&value,&type)) return NULL;
306 if(type!=os_VARTYPE_STRING&&type!=os_VARTYPE_MACRO&&type!=os_VARTYPE_EXPANDED
307 &&type!=os_VARTYPE_LITERAL_STRING)
308 return riscos_error("Bad putenv type");
309 len=strlen(value);
310 if(type!=os_VARTYPE_LITERAL_STRING) len++;
311 /* Other types need null terminator! */
312 e=xos_set_var_val(name,(byte*)value,len,0,type,0,0);
313 if(e) return riscos_oserror();
314 Py_INCREF(Py_None);
315 return Py_None;
316}
317
318static PyObject *riscos_delenv(PyObject *self,PyObject *args)
319{ char *name;
320 if(!PyArg_Parse(args,"s",&name)) return NULL;
321 e=xos_set_var_val(name,NULL,-1,0,0,0,0);
322 if(e) return riscos_oserror();
323 Py_INCREF(Py_None);
324 return Py_None;
325}
326
327static PyObject *riscos_getenvdict(PyObject *self,PyObject *args)
328{ PyObject *dict;
329 char value[257];
330 char *which="*";
331 int size;
332 char *context=NULL;
333 if(!PyArg_ParseTuple(args,"|s",&which)) return NULL;
334 dict = PyDict_New();
335 if (!dict) return NULL;
336 /* XXX This part ignores errors */
337 while(!xos_read_var_val(which,value,sizeof(value)-1,(int)context,
338 os_VARTYPE_EXPANDED,&size,(int *)&context,0))
339 { PyObject *v;
340 value[size]='\0';
341 v = PyString_FromString(value);
342 if (v == NULL) continue;
343 PyDict_SetItemString(dict, context, v);
344 Py_DECREF(v);
345 }
346 return dict;
347}
348
349static PyMethodDef riscos_methods[] = {
350
351 {"unlink", riscos_remove},
352 {"remove", riscos_remove},
353 {"rename", riscos_rename},
354 {"system", riscos_system},
355 {"rmdir", riscos_remove},
356 {"chdir", riscos_chdir},
357 {"getcwd", riscos_getcwd},
358 {"expand", riscos_expand},
359 {"mkdir", riscos_mkdir,1},
360 {"listdir", riscos_listdir},
361 {"stat", riscos_stat},
362 {"lstat", riscos_stat},
363 {"chmod", riscos_chmod},
364 {"utime", riscos_utime},
365 {"settype", riscos_settype},
366 {"getenv", riscos_getenv},
367 {"putenv", riscos_putenv},
368 {"delenv", riscos_delenv},
369 {"getenvdict", riscos_getenvdict,1},
370 {NULL, NULL} /* Sentinel */
371};
372
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000373static int
374ins(PyObject *module, char *symbol, long value)
375{
376 return PyModule_AddIntConstant(module, symbol, value);
377}
378
379
380static int
381all_ins(PyObject *d)
382{
383#ifdef F_OK
384 if (ins(d, "F_OK", (long)F_OK)) return -1;
385#endif
386#ifdef R_OK
387 if (ins(d, "R_OK", (long)R_OK)) return -1;
388#endif
389#ifdef W_OK
390 if (ins(d, "W_OK", (long)W_OK)) return -1;
391#endif
392#ifdef X_OK
393 if (ins(d, "X_OK", (long)X_OK)) return -1;
394#endif
395#ifdef NGROUPS_MAX
396 if (ins(d, "NGROUPS_MAX", (long)NGROUPS_MAX)) return -1;
397#endif
398#ifdef TMP_MAX
399 if (ins(d, "TMP_MAX", (long)TMP_MAX)) return -1;
400#endif
401#ifdef WCONTINUED
402 if (ins(d, "WCONTINUED", (long)WCONTINUED)) return -1;
403#endif
404#ifdef WNOHANG
405 if (ins(d, "WNOHANG", (long)WNOHANG)) return -1;
406#endif
407#ifdef WUNTRACED
408 if (ins(d, "WUNTRACED", (long)WUNTRACED)) return -1;
409#endif
410#ifdef O_RDONLY
411 if (ins(d, "O_RDONLY", (long)O_RDONLY)) return -1;
412#endif
413#ifdef O_WRONLY
414 if (ins(d, "O_WRONLY", (long)O_WRONLY)) return -1;
415#endif
416#ifdef O_RDWR
417 if (ins(d, "O_RDWR", (long)O_RDWR)) return -1;
418#endif
419#ifdef O_NDELAY
420 if (ins(d, "O_NDELAY", (long)O_NDELAY)) return -1;
421#endif
422#ifdef O_NONBLOCK
423 if (ins(d, "O_NONBLOCK", (long)O_NONBLOCK)) return -1;
424#endif
425#ifdef O_APPEND
426 if (ins(d, "O_APPEND", (long)O_APPEND)) return -1;
427#endif
428#ifdef O_DSYNC
429 if (ins(d, "O_DSYNC", (long)O_DSYNC)) return -1;
430#endif
431#ifdef O_RSYNC
432 if (ins(d, "O_RSYNC", (long)O_RSYNC)) return -1;
433#endif
434#ifdef O_SYNC
435 if (ins(d, "O_SYNC", (long)O_SYNC)) return -1;
436#endif
437#ifdef O_NOCTTY
438 if (ins(d, "O_NOCTTY", (long)O_NOCTTY)) return -1;
439#endif
440#ifdef O_CREAT
441 if (ins(d, "O_CREAT", (long)O_CREAT)) return -1;
442#endif
443#ifdef O_EXCL
444 if (ins(d, "O_EXCL", (long)O_EXCL)) return -1;
445#endif
446#ifdef O_TRUNC
447 if (ins(d, "O_TRUNC", (long)O_TRUNC)) return -1;
448#endif
449#ifdef O_BINARY
450 if (ins(d, "O_BINARY", (long)O_BINARY)) return -1;
451#endif
452#ifdef O_TEXT
453 if (ins(d, "O_TEXT", (long)O_TEXT)) return -1;
454#endif
455#ifdef O_LARGEFILE
456 if (ins(d, "O_LARGEFILE", (long)O_LARGEFILE)) return -1;
457#endif
458
459/* MS Windows */
460#ifdef O_NOINHERIT
461 /* Don't inherit in child processes. */
462 if (ins(d, "O_NOINHERIT", (long)O_NOINHERIT)) return -1;
463#endif
464#ifdef _O_SHORT_LIVED
465 /* Optimize for short life (keep in memory). */
466 /* MS forgot to define this one with a non-underscore form too. */
467 if (ins(d, "O_SHORT_LIVED", (long)_O_SHORT_LIVED)) return -1;
468#endif
469#ifdef O_TEMPORARY
470 /* Automatically delete when last handle is closed. */
471 if (ins(d, "O_TEMPORARY", (long)O_TEMPORARY)) return -1;
472#endif
473#ifdef O_RANDOM
474 /* Optimize for random access. */
475 if (ins(d, "O_RANDOM", (long)O_RANDOM)) return -1;
476#endif
477#ifdef O_SEQUENTIAL
478 /* Optimize for sequential access. */
479 if (ins(d, "O_SEQUENTIAL", (long)O_SEQUENTIAL)) return -1;
480#endif
481
482/* GNU extensions. */
483#ifdef O_DIRECT
484 /* Direct disk access. */
485 if (ins(d, "O_DIRECT", (long)O_DIRECT)) return -1;
486#endif
487#ifdef O_DIRECTORY
488 /* Must be a directory. */
489 if (ins(d, "O_DIRECTORY", (long)O_DIRECTORY)) return -1;
490#endif
491#ifdef O_NOFOLLOW
492 /* Do not follow links. */
493 if (ins(d, "O_NOFOLLOW", (long)O_NOFOLLOW)) return -1;
494#endif
495
496 /* These come from sysexits.h */
497#ifdef EX_OK
498 if (ins(d, "EX_OK", (long)EX_OK)) return -1;
499#endif /* EX_OK */
500#ifdef EX_USAGE
501 if (ins(d, "EX_USAGE", (long)EX_USAGE)) return -1;
502#endif /* EX_USAGE */
503#ifdef EX_DATAERR
504 if (ins(d, "EX_DATAERR", (long)EX_DATAERR)) return -1;
505#endif /* EX_DATAERR */
506#ifdef EX_NOINPUT
507 if (ins(d, "EX_NOINPUT", (long)EX_NOINPUT)) return -1;
508#endif /* EX_NOINPUT */
509#ifdef EX_NOUSER
510 if (ins(d, "EX_NOUSER", (long)EX_NOUSER)) return -1;
511#endif /* EX_NOUSER */
512#ifdef EX_NOHOST
513 if (ins(d, "EX_NOHOST", (long)EX_NOHOST)) return -1;
514#endif /* EX_NOHOST */
515#ifdef EX_UNAVAILABLE
516 if (ins(d, "EX_UNAVAILABLE", (long)EX_UNAVAILABLE)) return -1;
517#endif /* EX_UNAVAILABLE */
518#ifdef EX_SOFTWARE
519 if (ins(d, "EX_SOFTWARE", (long)EX_SOFTWARE)) return -1;
520#endif /* EX_SOFTWARE */
521#ifdef EX_OSERR
522 if (ins(d, "EX_OSERR", (long)EX_OSERR)) return -1;
523#endif /* EX_OSERR */
524#ifdef EX_OSFILE
525 if (ins(d, "EX_OSFILE", (long)EX_OSFILE)) return -1;
526#endif /* EX_OSFILE */
527#ifdef EX_CANTCREAT
528 if (ins(d, "EX_CANTCREAT", (long)EX_CANTCREAT)) return -1;
529#endif /* EX_CANTCREAT */
530#ifdef EX_IOERR
531 if (ins(d, "EX_IOERR", (long)EX_IOERR)) return -1;
532#endif /* EX_IOERR */
533#ifdef EX_TEMPFAIL
534 if (ins(d, "EX_TEMPFAIL", (long)EX_TEMPFAIL)) return -1;
535#endif /* EX_TEMPFAIL */
536#ifdef EX_PROTOCOL
537 if (ins(d, "EX_PROTOCOL", (long)EX_PROTOCOL)) return -1;
538#endif /* EX_PROTOCOL */
539#ifdef EX_NOPERM
540 if (ins(d, "EX_NOPERM", (long)EX_NOPERM)) return -1;
541#endif /* EX_NOPERM */
542#ifdef EX_CONFIG
543 if (ins(d, "EX_CONFIG", (long)EX_CONFIG)) return -1;
544#endif /* EX_CONFIG */
545#ifdef EX_NOTFOUND
546 if (ins(d, "EX_NOTFOUND", (long)EX_NOTFOUND)) return -1;
547#endif /* EX_NOTFOUND */
548
549 return 0;
550}
Guido van Rossum228d8072001-03-02 05:58:11 +0000551
552
553void
554initriscos()
555{
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000556 PyObject *m, *d, *stat_m;
Guido van Rossum228d8072001-03-02 05:58:11 +0000557
558 m = Py_InitModule("riscos", riscos_methods);
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000559
560 if (all_ins(m))
561 return;
562
Guido van Rossum228d8072001-03-02 05:58:11 +0000563 d = PyModule_GetDict(m);
564
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000565 Py_INCREF(PyExc_OSError);
566 PyModule_AddObject(m, "error", PyExc_OSError);
Guido van Rossum98bf58f2001-10-18 20:34:25 +0000567
568 PyStructSequence_InitType(&StatResultType, &stat_result_desc);
569 PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType);
Guido van Rossum228d8072001-03-02 05:58:11 +0000570}