|
1 | 1 | /* RISCOS module implementation */ |
2 | 2 |
|
3 | | -#include "h.osfscontrol" |
4 | | -#include "h.osgbpb" |
5 | | -#include "h.os" |
6 | | -#include "h.osfile" |
| 3 | +#include "oslib/osfscontrol.h" |
| 4 | +#include "oslib/osgbpb.h" |
| 5 | +#include "oslib/os.h" |
| 6 | +#include "oslib/osfile.h" |
| 7 | +#include "unixstuff.h" |
7 | 8 |
|
8 | 9 | #include "Python.h" |
9 | 10 |
|
10 | 11 | #include <errno.h> |
11 | 12 |
|
12 | 13 | static os_error *e; |
13 | 14 |
|
14 | | -static PyObject *RiscosError; /* Exception riscos.error */ |
| 15 | +/*static PyObject *RiscosError;*/ /* Exception riscos.error */ |
| 16 | + |
| 17 | +static PyObject *riscos_error(char *s) |
| 18 | +{ |
| 19 | + PyErr_SetString(PyExc_OSError, s); |
| 20 | + return NULL; |
| 21 | +} |
15 | 22 |
|
16 | 23 | static PyObject *riscos_oserror(void) |
17 | | -{ PyErr_SetString(RiscosError,e->errmess); |
18 | | - return 0; |
| 24 | +{ |
| 25 | + return riscos_error(e->errmess); |
19 | 26 | } |
20 | 27 |
|
21 | | -static PyObject *riscos_error(char *s) { PyErr_SetString(RiscosError,s);return 0;} |
22 | 28 |
|
23 | 29 | /* RISCOS file commands */ |
24 | 30 |
|
25 | 31 | static PyObject *riscos_remove(PyObject *self,PyObject *args) |
26 | 32 | { char *path1; |
27 | 33 | if (!PyArg_Parse(args, "s", &path1)) return NULL; |
28 | | - if (remove(path1)) return PyErr_SetFromErrno(RiscosError); |
| 34 | + if (remove(path1)) return PyErr_SetFromErrno(PyExc_OSError); |
29 | 35 | Py_INCREF(Py_None); |
30 | 36 | return Py_None; |
31 | 37 | } |
32 | 38 |
|
33 | 39 | static PyObject *riscos_rename(PyObject *self,PyObject *args) |
34 | 40 | { char *path1, *path2; |
35 | 41 | if (!PyArg_Parse(args, "(ss)", &path1, &path2)) return NULL; |
36 | | - if (rename(path1,path2)) return PyErr_SetFromErrno(RiscosError);; |
| 42 | + if (rename(path1,path2)) return PyErr_SetFromErrno(PyExc_OSError); |
37 | 43 | Py_INCREF(Py_None); |
38 | 44 | return Py_None; |
39 | 45 | } |
@@ -211,12 +217,56 @@ static PyObject *riscos_chmod(PyObject *self,PyObject *args) |
211 | 217 | return Py_None; |
212 | 218 | } |
213 | 219 |
|
| 220 | + |
214 | 221 | static PyObject *riscos_utime(PyObject *self,PyObject *args) |
215 | | -{ char *path; |
216 | | - int x,y; |
217 | | - if (!PyArg_Parse(args, "(s(ii))", &path,&x,&y)) return NULL; |
218 | | - e=xosfile_stamp(path); |
219 | | - if(e) return riscos_oserror(); |
| 222 | +{ |
| 223 | + char *path; |
| 224 | + long atime, mtime; |
| 225 | + PyObject* arg; |
| 226 | + |
| 227 | + if (!PyArg_ParseTuple(args, "sO:utime", &path, &arg)) |
| 228 | + return NULL; |
| 229 | + |
| 230 | + if (arg == Py_None) { |
| 231 | + /* optional time values not given */ |
| 232 | + Py_BEGIN_ALLOW_THREADS |
| 233 | + e=xosfile_stamp(path); |
| 234 | + Py_END_ALLOW_THREADS |
| 235 | + if(e) return riscos_oserror(); |
| 236 | + } |
| 237 | + else if (!PyArg_Parse(arg, "(ll)", &atime, &mtime)) { |
| 238 | + PyErr_SetString(PyExc_TypeError, |
| 239 | + "utime() arg 2 must be a tuple (atime, mtime)"); |
| 240 | + return NULL; |
| 241 | + } |
| 242 | + else { |
| 243 | + /* catalogue info*/ |
| 244 | + fileswitch_object_type obj_type; |
| 245 | + bits load_addr, exec_addr; |
| 246 | + int size; |
| 247 | + fileswitch_attr attr; |
| 248 | + |
| 249 | + /* read old catalogue info */ |
| 250 | + Py_BEGIN_ALLOW_THREADS |
| 251 | + e=xosfile_read_no_path(path, &obj_type, &load_addr, &exec_addr, &size, &attr); |
| 252 | + Py_END_ALLOW_THREADS |
| 253 | + if(e) return riscos_oserror(); |
| 254 | + |
| 255 | + /* check if load and exec address really contain filetype and date */ |
| 256 | + if ( (load_addr & 0xFFF00000U) != 0xFFF00000U) |
| 257 | + return riscos_error("can't set date for object with load and exec addresses"); |
| 258 | + |
| 259 | + /* convert argument mtime to RISC OS load and exec address */ |
| 260 | + if(acorntime(&exec_addr, &load_addr, (time_t) mtime)) |
| 261 | + return riscos_oserror(); |
| 262 | + |
| 263 | + /* write new load and exec address */ |
| 264 | + Py_BEGIN_ALLOW_THREADS |
| 265 | + e = xosfile_write(path, load_addr, exec_addr, attr); |
| 266 | + Py_END_ALLOW_THREADS |
| 267 | + if(e) return riscos_oserror(); |
| 268 | + } |
| 269 | + |
220 | 270 | Py_INCREF(Py_None); |
221 | 271 | return Py_None; |
222 | 272 | } |
@@ -328,9 +378,7 @@ initriscos() |
328 | 378 | d = PyModule_GetDict(m); |
329 | 379 |
|
330 | 380 | /* Initialize riscos.error exception */ |
331 | | - RiscosError = PyString_FromString("riscos.error"); |
332 | | - if (RiscosError == NULL || PyDict_SetItemString(d, "error", RiscosError) != 0) |
333 | | - Py_FatalError("can't define riscos.error"); |
| 381 | + PyDict_SetItemString(d, "error", PyExc_OSError); |
334 | 382 |
|
335 | 383 | PyStructSequence_InitType(&StatResultType, &stat_result_desc); |
336 | 384 | PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType); |
|
0 commit comments