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