Mercurial > cpython-lru_cache-weakref
annotate RISCOS/Modules/riscosmodule.c @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 91dd223829c6 |
| children | ed1ba37a46b7 |
| rev | line source |
|---|---|
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /* RISCOS module implementation */ |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
20652
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
3 #include "oslib/osfscontrol.h" |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
4 #include "oslib/osgbpb.h" |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
5 #include "oslib/os.h" |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
6 #include "oslib/osfile.h" |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
7 #include "unixstuff.h" |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 #include "Python.h" |
|
20726
587b74854f8c
SF patch #475657 (Dietmar Schwertberger)
Guido van Rossum <guido@python.org>
parents:
20652
diff
changeset
|
10 #include "structseq.h" |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 #include <errno.h> |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 static os_error *e; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
|
20652
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
16 /*static PyObject *RiscosError;*/ /* Exception riscos.error */ |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
17 |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
18 static PyObject *riscos_error(char *s) |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
19 { |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
20 PyErr_SetString(PyExc_OSError, s); |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
21 return NULL; |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
22 } |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 static PyObject *riscos_oserror(void) |
|
20652
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
25 { |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
26 return riscos_error(e->errmess); |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 /* RISCOS file commands */ |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 static PyObject *riscos_remove(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 { char *path1; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 if (!PyArg_Parse(args, "s", &path1)) return NULL; |
|
20652
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
35 if (remove(path1)) return PyErr_SetFromErrno(PyExc_OSError); |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 Py_INCREF(Py_None); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 return Py_None; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 static PyObject *riscos_rename(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 { char *path1, *path2; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 if (!PyArg_Parse(args, "(ss)", &path1, &path2)) return NULL; |
|
20652
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
43 if (rename(path1,path2)) return PyErr_SetFromErrno(PyExc_OSError); |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 Py_INCREF(Py_None); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 return Py_None; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 static PyObject *riscos_system(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 { char *command; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 if (!PyArg_Parse(args, "s", &command)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 return PyInt_FromLong(system(command)); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 static PyObject *riscos_chdir(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 { char *path; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 if (!PyArg_Parse(args, "s", &path)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 e=xosfscontrol_dir(path); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 if(e) return riscos_oserror(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 Py_INCREF(Py_None); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 return Py_None; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 static PyObject *canon(char *path) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 { int len; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 PyObject *obj; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 char *buf; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 e=xosfscontrol_canonicalise_path(path,0,0,0,0,&len); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 if(e) return riscos_oserror(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 obj=PyString_FromStringAndSize(NULL,-len); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 if(obj==NULL) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 buf=PyString_AsString(obj); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 e=xosfscontrol_canonicalise_path(path,buf,0,0,1-len,&len); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 if(len!=1) return riscos_error("Error expanding path"); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 if(!e) return obj; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 Py_DECREF(obj); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 return riscos_oserror(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 static PyObject *riscos_getcwd(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 { if(!PyArg_NoArgs(args)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 return canon("@"); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 static PyObject *riscos_expand(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 { char *path; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 if (!PyArg_Parse(args, "s", &path)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 return canon(path); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 static PyObject *riscos_mkdir(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 { char *path; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 int mode; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 if (!PyArg_ParseTuple(args, "s|i", &path, &mode)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 e=xosfile_create_dir(path,0); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 if(e) return riscos_oserror(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 Py_INCREF(Py_None); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 return Py_None; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 static PyObject *riscos_listdir(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 { char *path,buf[256]; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 PyObject *d, *v; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 int c=0,count; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 if (!PyArg_Parse(args, "s", &path)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 d=PyList_New(0); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 if(!d) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 for(;;) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 { e=xosgbpb_dir_entries(path,(osgbpb_string_list*)buf, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 1,c,256,0,&count,&c); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 if(e) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 { Py_DECREF(d);return riscos_oserror(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 if(count) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 { v=PyString_FromString(buf); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 if(!v) { Py_DECREF(d);return 0;} |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 if(PyList_Append(d,v)) {Py_DECREF(d);Py_DECREF(v);return 0;} |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 if(c==-1) break; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 return d; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 |
|
20539
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
123 static char stat_result__doc__[] = |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
124 "stat_result: Result from stat or lstat.\n\n\ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
125 This object may be accessed either as a tuple of\n\ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
126 (mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)\n\ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
127 or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.\n\ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
128 \n\ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
129 RiscOS: The fields st_ftype, st_attrs, and st_obtype are also available.\n\ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
130 \n\ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
131 See os.stat for more information.\n"; |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
132 |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
133 static PyStructSequence_Field stat_result_fields[] = { |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
134 { "st_mode", "protection bits" }, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
135 { "st_ino", "inode" }, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
136 { "st_dev", "device" }, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
137 { "st_nlink", "number of hard links" }, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
138 { "st_uid", "user ID of owner" }, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
139 { "st_gid", "group ID of owner" }, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
140 { "st_size", "total size, in bytes" }, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
141 { "st_atime", "time of last access" }, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
142 { "st_mtime", "time of last modification" }, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
143 { "st_ctime", "time of last change" }, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
144 { "st_ftype", "file type" }, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
145 { "st_attrs", "attributes" }, |
|
20726
587b74854f8c
SF patch #475657 (Dietmar Schwertberger)
Guido van Rossum <guido@python.org>
parents:
20652
diff
changeset
|
146 { "st_obtype", "object type" }, |
|
20539
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
147 { 0 } |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
148 }; |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
149 |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
150 static PyStructSequence_Desc stat_result_desc = { |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
20726
diff
changeset
|
151 "riscos.stat_result", |
|
20539
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
152 stat_result__doc__, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
153 stat_result_fields, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
154 13 |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
155 }; |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
156 |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
157 static PyTypeObject StatResultType; |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
158 |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 static PyObject *riscos_stat(PyObject *self,PyObject *args) |
|
20539
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
160 { |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
161 PyObject *v; |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
162 char *path; |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 int ob,len; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 bits t=0; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 bits ld,ex,at,ft,mode; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 if (!PyArg_Parse(args, "s", &path)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 e=xosfile_read_stamped_no_path(path,&ob,&ld,&ex,&len,&at,&ft); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 if(e) return riscos_oserror(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 switch (ob) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 { case osfile_IS_FILE:mode=0100000;break; /* OCTAL */ |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 case osfile_IS_DIR:mode=040000;break; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 case osfile_IS_IMAGE:mode=0140000;break; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
173 default:return riscos_error("Not found"); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 if(ft!=-1) t=unixtime(ld,ex); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 mode|=(at&7)<<6; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 mode|=((at&112)*9)>>4; |
|
20539
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
178 |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
179 v = PyStructSequence_New(&StatResultType); |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
180 |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
181 PyStructSequence_SET_ITEM(v, 0, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
182 PyInt_FromLong((long) mode)); /*st_mode*/ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
183 PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) 0)); /*st_ino*/ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
184 PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long) 0)); /*st_dev*/ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
185 PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long) 0)); /*st_nlink*/ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
186 PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long) 0)); /*st_uid*/ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
187 PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long) 0)); /*st_gid*/ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
188 PyStructSequence_SET_ITEM(v, 6, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
189 PyInt_FromLong((long) len)); /*st_size*/ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
190 PyStructSequence_SET_ITEM(v, 7, PyInt_FromLong((long) t)); /*st_atime*/ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
191 PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) t)); /*st_mtime*/ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
192 PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) t)); /*st_ctime*/ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
193 PyStructSequence_SET_ITEM(v, 10, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
194 PyInt_FromLong((long) ft)); /*file type*/ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
195 PyStructSequence_SET_ITEM(v, 11, |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
196 PyInt_FromLong((long) at)); /*attributes*/ |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
197 PyStructSequence_SET_ITEM(v, 12, |
|
20726
587b74854f8c
SF patch #475657 (Dietmar Schwertberger)
Guido van Rossum <guido@python.org>
parents:
20652
diff
changeset
|
198 PyInt_FromLong((long) ob)); /*object type*/ |
|
20539
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
199 |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
200 if (PyErr_Occurred()) { |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
201 Py_DECREF(v); |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
202 return NULL; |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
203 } |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
204 |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
205 return v; |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 static PyObject *riscos_chmod(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 { char *path; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 bits mode; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 bits attr; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 attr=(mode&0x700)>>8; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 attr|=(mode&7)<<4; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 if (!PyArg_Parse(args, "(si)", &path,(int*)&mode)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 e=xosfile_write_attr(path,attr); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 if(e) return riscos_oserror(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 Py_INCREF(Py_None); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 return Py_None; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 |
|
20652
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
221 |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 static PyObject *riscos_utime(PyObject *self,PyObject *args) |
|
20652
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
223 { |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
224 char *path; |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
225 long atime, mtime; |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
226 PyObject* arg; |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
227 |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
228 if (!PyArg_ParseTuple(args, "sO:utime", &path, &arg)) |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
229 return NULL; |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
230 |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
231 if (arg == Py_None) { |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
232 /* optional time values not given */ |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
233 Py_BEGIN_ALLOW_THREADS |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
234 e=xosfile_stamp(path); |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
235 Py_END_ALLOW_THREADS |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
236 if(e) return riscos_oserror(); |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
237 } |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
238 else if (!PyArg_Parse(arg, "(ll)", &atime, &mtime)) { |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
239 PyErr_SetString(PyExc_TypeError, |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
240 "utime() arg 2 must be a tuple (atime, mtime)"); |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
241 return NULL; |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
242 } |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
243 else { |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
244 /* catalogue info*/ |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
245 fileswitch_object_type obj_type; |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
246 bits load_addr, exec_addr; |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
247 int size; |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
248 fileswitch_attr attr; |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
249 |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
250 /* read old catalogue info */ |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
251 Py_BEGIN_ALLOW_THREADS |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
252 e=xosfile_read_no_path(path, &obj_type, &load_addr, &exec_addr, &size, &attr); |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
253 Py_END_ALLOW_THREADS |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
254 if(e) return riscos_oserror(); |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
255 |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
256 /* check if load and exec address really contain filetype and date */ |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
257 if ( (load_addr & 0xFFF00000U) != 0xFFF00000U) |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
258 return riscos_error("can't set date for object with load and exec addresses"); |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
259 |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
260 /* convert argument mtime to RISC OS load and exec address */ |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
261 if(acorntime(&exec_addr, &load_addr, (time_t) mtime)) |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
262 return riscos_oserror(); |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
263 |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
264 /* write new load and exec address */ |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
265 Py_BEGIN_ALLOW_THREADS |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
266 e = xosfile_write(path, load_addr, exec_addr, attr); |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
267 Py_END_ALLOW_THREADS |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
268 if(e) return riscos_oserror(); |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
269 } |
|
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
270 |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
271 Py_INCREF(Py_None); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 return Py_None; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
274 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 static PyObject *riscos_settype(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 { char *path,*name; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 int type; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 if (!PyArg_Parse(args, "(si)", &path,&type)) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
279 { PyErr_Clear(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 if (!PyArg_Parse(args, "(ss)", &path,&name)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 e=xosfscontrol_file_type_from_string(name,(bits*)&type); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 if(e) return riscos_oserror(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 e=xosfile_set_type(path,type); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
285 if(e) return riscos_oserror(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
286 Py_INCREF(Py_None); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 return Py_None; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
289 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 static PyObject *riscos_getenv(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 { char *name,*value; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 if(!PyArg_Parse(args,"s",&name)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
293 value=getenv(name); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 if(value) return PyString_FromString(value); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 Py_INCREF(Py_None); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
296 return Py_None; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
298 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
299 static PyObject *riscos_putenv(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 { char *name,*value; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 int len; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 os_var_type type=os_VARTYPE_LITERAL_STRING; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 if(!PyArg_ParseTuple(args,"ss|i",&name,&value,&type)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
304 if(type!=os_VARTYPE_STRING&&type!=os_VARTYPE_MACRO&&type!=os_VARTYPE_EXPANDED |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 &&type!=os_VARTYPE_LITERAL_STRING) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 return riscos_error("Bad putenv type"); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 len=strlen(value); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
308 if(type!=os_VARTYPE_LITERAL_STRING) len++; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 /* Other types need null terminator! */ |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 e=xos_set_var_val(name,(byte*)value,len,0,type,0,0); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
311 if(e) return riscos_oserror(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 Py_INCREF(Py_None); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 return Py_None; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 static PyObject *riscos_delenv(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
317 { char *name; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 if(!PyArg_Parse(args,"s",&name)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 e=xos_set_var_val(name,NULL,-1,0,0,0,0); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 if(e) return riscos_oserror(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 Py_INCREF(Py_None); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 return Py_None; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 static PyObject *riscos_getenvdict(PyObject *self,PyObject *args) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
326 { PyObject *dict; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
327 char value[257]; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
328 char *which="*"; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 int size; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 char *context=NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 if(!PyArg_ParseTuple(args,"|s",&which)) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 dict = PyDict_New(); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 if (!dict) return NULL; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 /* XXX This part ignores errors */ |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 while(!xos_read_var_val(which,value,sizeof(value)-1,(int)context, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 os_VARTYPE_EXPANDED,&size,(int *)&context,0)) |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 { PyObject *v; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 value[size]='\0'; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 v = PyString_FromString(value); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 if (v == NULL) continue; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 PyDict_SetItemString(dict, context, v); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
342 Py_DECREF(v); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
343 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 return dict; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 } |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
346 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
347 static PyMethodDef riscos_methods[] = { |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
348 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 {"unlink", riscos_remove}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 {"remove", riscos_remove}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 {"rename", riscos_rename}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
352 {"system", riscos_system}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 {"rmdir", riscos_remove}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 {"chdir", riscos_chdir}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 {"getcwd", riscos_getcwd}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 {"expand", riscos_expand}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
357 {"mkdir", riscos_mkdir,1}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 {"listdir", riscos_listdir}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 {"stat", riscos_stat}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 {"lstat", riscos_stat}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
361 {"chmod", riscos_chmod}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 {"utime", riscos_utime}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 {"settype", riscos_settype}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 {"getenv", riscos_getenv}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 {"putenv", riscos_putenv}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 {"delenv", riscos_delenv}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 {"getenvdict", riscos_getenvdict,1}, |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 {NULL, NULL} /* Sentinel */ |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 }; |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 void |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 initriscos() |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
375 { |
|
20539
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
376 PyObject *m, *d, *stat_m; |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
377 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 m = Py_InitModule("riscos", riscos_methods); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 d = PyModule_GetDict(m); |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 |
|
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 /* Initialize riscos.error exception */ |
|
20652
2d3cee9f1633
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20539
diff
changeset
|
382 PyDict_SetItemString(d, "error", PyExc_OSError); |
|
20539
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
383 |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
384 PyStructSequence_InitType(&StatResultType, &stat_result_desc); |
|
2d599a36b67a
SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
16941
diff
changeset
|
385 PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType); |
|
16941
a015aed3a1ac
RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 } |
