Mercurial > cpython-lru_cache-weakref
annotate Mac/Modules/macmodule.c @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | ac235c9e6881 |
| children | ddfcefc0d826 |
| rev | line source |
|---|---|
| 1495 | 1 /*********************************************************** |
|
5079
d6b292a33cfe
Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents:
5071
diff
changeset
|
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
| 2091 | 3 The Netherlands. |
| 1495 | 4 |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
25 /* Mac module implementation */ |
| 1495 | 26 |
| 5071 | 27 #include "Python.h" |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
28 #include "ceval.h" |
| 1495 | 29 |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
30 #include <stdio.h> |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
31 #include <string.h> |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
32 #include <errno.h> |
|
1822
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
33 |
|
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
34 #ifdef THINK_C |
|
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
35 #include "unix.h" |
|
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
36 #undef S_IFMT |
|
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
37 #undef S_IFDIR |
|
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
38 #undef S_IFCHR |
|
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
39 #undef S_IFBLK |
|
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
40 #undef S_IFREG |
|
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
41 #undef S_ISDIR |
|
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
42 #undef S_ISREG |
|
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
43 #endif |
|
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
44 |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
45 #include "macstat.h" |
| 3394 | 46 #ifdef USE_GUSI |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
47 /* Remove defines from macstat.h */ |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
48 #undef S_IFMT |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
49 #undef S_IFDIR |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
50 #undef S_IFREG |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
51 #undef S_IREAD |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
52 #undef S_IWRITE |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
53 #undef S_IEXEC |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
54 |
| 3400 | 55 #include <GUSI.h> |
| 3394 | 56 #include <sys/types.h> |
| 57 #include <stat.h> | |
| 58 #else | |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
59 #define stat macstat |
| 3394 | 60 #endif |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
61 |
|
2250
3bef1aff871b
CodeWarrior 5 has more unixisms (open/close/read/write)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2222
diff
changeset
|
62 #ifdef __MWERKS__ |
|
3bef1aff871b
CodeWarrior 5 has more unixisms (open/close/read/write)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2222
diff
changeset
|
63 #include <unix.h> |
|
3bef1aff871b
CodeWarrior 5 has more unixisms (open/close/read/write)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2222
diff
changeset
|
64 #else |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
65 #include <fcntl.h> |
|
2032
609bfb8ae7f5
Ported to MetroWerks, which misses file-descriptor like functionality.
Jack Jansen <jack.jansen@cwi.nl>
parents:
1822
diff
changeset
|
66 #endif |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
67 |
| 3400 | 68 /* Optional routines, for some compiler/runtime combinations */ |
| 69 #if defined(USE_GUSI) || !defined(__MWERKS__) | |
| 70 #define WEHAVE_FDOPEN | |
| 71 #endif | |
| 72 #if defined(MPW) || defined(USE_GUSI) | |
| 73 #define WEHAVE_DUP | |
| 74 #endif | |
|
2222
bbb56dc3b526
Make malloc stats routine available under MetroWerks
Jack Jansen <jack.jansen@cwi.nl>
parents:
2179
diff
changeset
|
75 |
|
1795
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1692
diff
changeset
|
76 #include "macdefs.h" |
| 3394 | 77 #ifdef USE_GUSI |
| 78 #include <dirent.h> | |
| 79 #else | |
|
1795
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1692
diff
changeset
|
80 #include "dirent.h" |
| 3394 | 81 #endif |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
82 |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
83 #ifndef MAXPATHLEN |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
84 #define MAXPATHLEN 1024 |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
85 #endif |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
86 |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
87 /* Prototypes for Unix simulation on Mac */ |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
88 |
| 3400 | 89 #ifndef USE_GUSI |
| 90 | |
| 5071 | 91 int chdir Py_PROTO((const char *path)); |
| 92 int mkdir Py_PROTO((const char *path, int mode)); | |
| 93 DIR * opendir Py_PROTO((char *)); | |
| 94 void closedir Py_PROTO((DIR *)); | |
| 95 struct dirent * readdir Py_PROTO((DIR *)); | |
| 96 int rmdir Py_PROTO((const char *path)); | |
| 97 int sync Py_PROTO((void)); | |
| 3400 | 98 |
| 99 #if defined(THINK_C) || defined(__SC__) | |
| 5071 | 100 int unlink Py_PROTO((char *)); |
|
1822
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
101 #else |
| 5071 | 102 int unlink Py_PROTO((const char *)); |
|
1822
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
103 #endif |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
104 |
| 3400 | 105 #endif /* USE_GUSI */ |
| 106 | |
| 5071 | 107 char *getwd Py_PROTO((char *)); |
| 108 char *getbootvol Py_PROTO((void)); | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
109 |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
110 |
| 5071 | 111 static PyObject *MacError; /* Exception mac.error */ |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
112 |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
113 /* Set a MAC-specific error from errno, and return NULL */ |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
114 |
| 5071 | 115 static PyObject * |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
116 mac_error() |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
117 { |
| 5071 | 118 return PyErr_SetFromErrno(MacError); |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
119 } |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
120 |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
121 /* MAC generic methods */ |
| 1495 | 122 |
| 5071 | 123 static PyObject * |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
124 mac_1str(args, func) |
| 5071 | 125 PyObject *args; |
| 126 int (*func) Py_FPROTO((const char *)); | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
127 { |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
128 char *path1; |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
129 int res; |
| 5071 | 130 if (!PyArg_Parse(args, "s", &path1)) |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
131 return NULL; |
| 5071 | 132 Py_BEGIN_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
133 res = (*func)(path1); |
| 5071 | 134 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
135 if (res < 0) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
136 return mac_error(); |
| 5071 | 137 Py_INCREF(Py_None); |
| 138 return Py_None; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
139 } |
| 1495 | 140 |
| 5071 | 141 static PyObject * |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
142 mac_2str(args, func) |
| 5071 | 143 PyObject *args; |
| 144 int (*func) Py_FPROTO((const char *, const char *)); | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
145 { |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
146 char *path1, *path2; |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
147 int res; |
| 5071 | 148 if (!PyArg_Parse(args, "(ss)", &path1, &path2)) |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
149 return NULL; |
| 5071 | 150 Py_BEGIN_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
151 res = (*func)(path1, path2); |
| 5071 | 152 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
153 if (res < 0) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
154 return mac_error(); |
| 5071 | 155 Py_INCREF(Py_None); |
| 156 return Py_None; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
157 } |
| 1495 | 158 |
| 5071 | 159 static PyObject * |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
160 mac_strint(args, func) |
| 5071 | 161 PyObject *args; |
| 162 int (*func) Py_FPROTO((const char *, int)); | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
163 { |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
164 char *path; |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
165 int i; |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
166 int res; |
| 5071 | 167 if (!PyArg_Parse(args, "(si)", &path, &i)) |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
168 return NULL; |
| 5071 | 169 Py_BEGIN_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
170 res = (*func)(path, i); |
| 5071 | 171 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
172 if (res < 0) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
173 return mac_error(); |
| 5071 | 174 Py_INCREF(Py_None); |
| 175 return Py_None; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
176 } |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
177 |
| 5071 | 178 static PyObject * |
| 1495 | 179 mac_chdir(self, args) |
| 5071 | 180 PyObject *self; |
| 181 PyObject *args; | |
| 1495 | 182 { |
|
3433
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3405
diff
changeset
|
183 #ifdef USE_GUSI |
| 5071 | 184 PyObject *rv; |
|
3433
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3405
diff
changeset
|
185 |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3405
diff
changeset
|
186 /* Change MacOS's idea of wd too */ |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3405
diff
changeset
|
187 rv = mac_1str(args, chdir); |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3405
diff
changeset
|
188 PyMac_FixGUSIcd(); |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3405
diff
changeset
|
189 return rv; |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3405
diff
changeset
|
190 #else |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
191 return mac_1str(args, chdir); |
|
3433
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3405
diff
changeset
|
192 #endif |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3405
diff
changeset
|
193 |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
194 } |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
195 |
| 5071 | 196 static PyObject * |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
197 mac_close(self, args) |
| 5071 | 198 PyObject *self; |
| 199 PyObject *args; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
200 { |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
201 int fd, res; |
| 5071 | 202 if (!PyArg_Parse(args, "i", &fd)) |
| 1495 | 203 return NULL; |
| 5071 | 204 Py_BEGIN_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
205 res = close(fd); |
| 5071 | 206 Py_END_ALLOW_THREADS |
| 3400 | 207 #ifndef USE_GUSI |
| 208 /* GUSI gives surious errors here? */ | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
209 if (res < 0) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
210 return mac_error(); |
| 3400 | 211 #endif |
| 5071 | 212 Py_INCREF(Py_None); |
| 213 return Py_None; | |
| 1495 | 214 } |
| 215 | |
| 3400 | 216 #ifdef WEHAVE_DUP |
|
1622
812d0811fcf3
Walker's changes fixed so they work in THINK C 5
Guido van Rossum <guido@python.org>
parents:
1620
diff
changeset
|
217 |
| 5071 | 218 static PyObject * |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
219 mac_dup(self, args) |
| 5071 | 220 PyObject *self; |
| 221 PyObject *args; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
222 { |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
223 int fd; |
| 5071 | 224 if (!PyArg_Parse(args, "i", &fd)) |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
225 return NULL; |
| 5071 | 226 Py_BEGIN_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
227 fd = dup(fd); |
| 5071 | 228 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
229 if (fd < 0) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
230 return mac_error(); |
| 5071 | 231 return PyInt_FromLong((long)fd); |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
232 } |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
233 |
| 3400 | 234 #endif |
|
1821
40594f80ab3c
Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1808
diff
changeset
|
235 |
| 3400 | 236 #ifdef WEHAVE_FDOPEN |
| 5071 | 237 static PyObject * |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
238 mac_fdopen(self, args) |
| 5071 | 239 PyObject *self; |
| 240 PyObject *args; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
241 { |
| 5071 | 242 extern int fclose Py_PROTO((FILE *)); |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
243 int fd; |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
244 char *mode; |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
245 FILE *fp; |
| 5071 | 246 if (!PyArg_Parse(args, "(is)", &fd, &mode)) |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
247 return NULL; |
| 5071 | 248 Py_BEGIN_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
249 fp = fdopen(fd, mode); |
| 5071 | 250 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
251 if (fp == NULL) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
252 return mac_error(); |
| 5071 | 253 return PyFile_FromFile(fp, "(fdopen)", mode, fclose); |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
254 } |
|
2032
609bfb8ae7f5
Ported to MetroWerks, which misses file-descriptor like functionality.
Jack Jansen <jack.jansen@cwi.nl>
parents:
1822
diff
changeset
|
255 #endif |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
256 |
| 5071 | 257 static PyObject * |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
258 mac_getbootvol(self, args) |
| 5071 | 259 PyObject *self; |
| 260 PyObject *args; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
261 { |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
262 char *res; |
| 5071 | 263 if (!PyArg_NoArgs(args)) |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
264 return NULL; |
| 5071 | 265 Py_BEGIN_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
266 res = getbootvol(); |
| 5071 | 267 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
268 if (res == NULL) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
269 return mac_error(); |
| 5071 | 270 return PyString_FromString(res); |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
271 } |
| 1495 | 272 |
| 5071 | 273 static PyObject * |
| 1495 | 274 mac_getcwd(self, args) |
| 5071 | 275 PyObject *self; |
| 276 PyObject *args; | |
| 1495 | 277 { |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
278 char path[MAXPATHLEN]; |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
279 char *res; |
| 5071 | 280 if (!PyArg_NoArgs(args)) |
| 1495 | 281 return NULL; |
| 5071 | 282 Py_BEGIN_ALLOW_THREADS |
| 3400 | 283 #ifdef USE_GUSI |
| 284 res = getcwd(path, sizeof path); | |
| 285 #else | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
286 res = getwd(path); |
| 3400 | 287 #endif |
| 5071 | 288 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
289 if (res == NULL) { |
| 5071 | 290 PyErr_SetString(MacError, path); |
| 1495 | 291 return NULL; |
| 292 } | |
| 5071 | 293 return PyString_FromString(res); |
| 1495 | 294 } |
| 295 | |
| 5071 | 296 static PyObject * |
| 1495 | 297 mac_listdir(self, args) |
| 5071 | 298 PyObject *self; |
| 299 PyObject *args; | |
| 1495 | 300 { |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
301 char *name; |
| 5071 | 302 PyObject *d, *v; |
| 1495 | 303 DIR *dirp; |
|
1795
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1692
diff
changeset
|
304 struct dirent *ep; |
| 5071 | 305 if (!PyArg_Parse(args, "s", &name)) |
| 1495 | 306 return NULL; |
| 5071 | 307 Py_BEGIN_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
308 if ((dirp = opendir(name)) == NULL) { |
| 5071 | 309 Py_BLOCK_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
310 return mac_error(); |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
311 } |
| 5071 | 312 if ((d = PyList_New(0)) == NULL) { |
| 1495 | 313 closedir(dirp); |
| 5071 | 314 Py_BLOCK_THREADS |
| 1495 | 315 return NULL; |
| 316 } | |
| 317 while ((ep = readdir(dirp)) != NULL) { | |
| 5071 | 318 v = PyString_FromString(ep->d_name); |
| 1495 | 319 if (v == NULL) { |
| 5071 | 320 Py_DECREF(d); |
| 1495 | 321 d = NULL; |
| 322 break; | |
| 323 } | |
| 5071 | 324 if (PyList_Append(d, v) != 0) { |
| 325 Py_DECREF(v); | |
| 326 Py_DECREF(d); | |
| 1495 | 327 d = NULL; |
| 328 break; | |
| 329 } | |
| 5071 | 330 Py_DECREF(v); |
| 1495 | 331 } |
| 332 closedir(dirp); | |
| 5071 | 333 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
334 |
| 1495 | 335 return d; |
| 336 } | |
| 337 | |
| 5071 | 338 static PyObject * |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
339 mac_lseek(self, args) |
| 5071 | 340 PyObject *self; |
| 341 PyObject *args; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
342 { |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
343 int fd; |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
344 int where; |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
345 int how; |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
346 long res; |
| 5071 | 347 if (!PyArg_Parse(args, "(iii)", &fd, &where, &how)) |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
348 return NULL; |
| 5071 | 349 Py_BEGIN_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
350 res = lseek(fd, (long)where, how); |
| 5071 | 351 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
352 if (res < 0) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
353 return mac_error(); |
| 5071 | 354 return PyInt_FromLong(res); |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
355 } |
| 3394 | 356 |
| 5071 | 357 static PyObject * |
| 1495 | 358 mac_mkdir(self, args) |
| 5071 | 359 PyObject *self; |
| 360 PyObject *args; | |
| 1495 | 361 { |
|
3405
c283447b985f
Mods by Guido: mkdir 2nd arg optional and remove as alias for unlink.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3400
diff
changeset
|
362 int res; |
|
c283447b985f
Mods by Guido: mkdir 2nd arg optional and remove as alias for unlink.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3400
diff
changeset
|
363 char *path; |
|
c283447b985f
Mods by Guido: mkdir 2nd arg optional and remove as alias for unlink.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3400
diff
changeset
|
364 int mode = 0777; /* Unused */ |
| 5071 | 365 if (!PyArg_ParseTuple(args, "s|i", &path, &mode)) |
|
3405
c283447b985f
Mods by Guido: mkdir 2nd arg optional and remove as alias for unlink.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3400
diff
changeset
|
366 return NULL; |
| 5071 | 367 Py_BEGIN_ALLOW_THREADS |
|
3942
38684852376f
GUSI mkdir() lost its dummy second arg
Jack Jansen <jack.jansen@cwi.nl>
parents:
3433
diff
changeset
|
368 #ifdef USE_GUSI |
|
38684852376f
GUSI mkdir() lost its dummy second arg
Jack Jansen <jack.jansen@cwi.nl>
parents:
3433
diff
changeset
|
369 res = mkdir(path); |
|
38684852376f
GUSI mkdir() lost its dummy second arg
Jack Jansen <jack.jansen@cwi.nl>
parents:
3433
diff
changeset
|
370 #else |
|
3405
c283447b985f
Mods by Guido: mkdir 2nd arg optional and remove as alias for unlink.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3400
diff
changeset
|
371 res = mkdir(path, mode); |
|
3942
38684852376f
GUSI mkdir() lost its dummy second arg
Jack Jansen <jack.jansen@cwi.nl>
parents:
3433
diff
changeset
|
372 #endif |
| 5071 | 373 Py_END_ALLOW_THREADS |
|
3405
c283447b985f
Mods by Guido: mkdir 2nd arg optional and remove as alias for unlink.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3400
diff
changeset
|
374 if (res < 0) |
|
c283447b985f
Mods by Guido: mkdir 2nd arg optional and remove as alias for unlink.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3400
diff
changeset
|
375 return mac_error(); |
| 5071 | 376 Py_INCREF(Py_None); |
| 377 return Py_None; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
378 } |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
379 |
| 5071 | 380 static PyObject * |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
381 mac_open(self, args) |
| 5071 | 382 PyObject *self; |
| 383 PyObject *args; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
384 { |
| 1495 | 385 char *path; |
| 386 int mode; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
387 int fd; |
| 5071 | 388 if (!PyArg_Parse(args, "(si)", &path, &mode)) |
| 1495 | 389 return NULL; |
| 5071 | 390 Py_BEGIN_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
391 fd = open(path, mode); |
| 5071 | 392 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
393 if (fd < 0) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
394 return mac_error(); |
| 5071 | 395 return PyInt_FromLong((long)fd); |
| 1495 | 396 } |
| 397 | |
| 5071 | 398 static PyObject * |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
399 mac_read(self, args) |
| 5071 | 400 PyObject *self; |
| 401 PyObject *args; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
402 { |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
403 int fd, size; |
| 5071 | 404 PyObject *buffer; |
| 405 if (!PyArg_Parse(args, "(ii)", &fd, &size)) | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
406 return NULL; |
| 5071 | 407 buffer = PyString_FromStringAndSize((char *)NULL, size); |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
408 if (buffer == NULL) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
409 return NULL; |
| 5071 | 410 Py_BEGIN_ALLOW_THREADS |
| 411 size = read(fd, PyString_AsString(buffer), size); | |
| 412 Py_END_ALLOW_THREADS | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
413 if (size < 0) { |
| 5071 | 414 Py_DECREF(buffer); |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
415 return mac_error(); |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
416 } |
| 5071 | 417 _PyString_Resize(&buffer, size); |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
418 return buffer; |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
419 } |
| 1495 | 420 |
| 5071 | 421 static PyObject * |
| 1495 | 422 mac_rename(self, args) |
| 5071 | 423 PyObject *self; |
| 424 PyObject *args; | |
| 1495 | 425 { |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
426 return mac_2str(args, rename); |
| 1495 | 427 } |
| 428 | |
| 5071 | 429 static PyObject * |
| 1495 | 430 mac_rmdir(self, args) |
| 5071 | 431 PyObject *self; |
| 432 PyObject *args; | |
| 1495 | 433 { |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
434 return mac_1str(args, rmdir); |
| 1495 | 435 } |
| 436 | |
| 5071 | 437 static PyObject * |
| 1495 | 438 mac_stat(self, args) |
| 5071 | 439 PyObject *self; |
| 440 PyObject *args; | |
| 1495 | 441 { |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
442 struct stat st; |
| 1495 | 443 char *path; |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
444 int res; |
| 5071 | 445 if (!PyArg_Parse(args, "s", &path)) |
| 1495 | 446 return NULL; |
| 5071 | 447 Py_BEGIN_ALLOW_THREADS |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
448 res = stat(path, &st); |
| 5071 | 449 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
450 if (res != 0) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
451 return mac_error(); |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
452 #if 1 |
| 5071 | 453 return Py_BuildValue("(lllllllddd)", |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
454 (long)st.st_mode, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
455 (long)st.st_ino, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
456 (long)st.st_dev, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
457 (long)st.st_nlink, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
458 (long)st.st_uid, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
459 (long)st.st_gid, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
460 (long)st.st_size, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
461 (double)st.st_atime, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
462 (double)st.st_mtime, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
463 (double)st.st_ctime); |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
464 #else |
| 5071 | 465 return Py_BuildValue("(llllllllll)", |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
466 (long)st.st_mode, |
|
1821
40594f80ab3c
Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1808
diff
changeset
|
467 (long)st.st_ino, |
|
1795
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1692
diff
changeset
|
468 (long)st.st_dev, |
|
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1692
diff
changeset
|
469 (long)st.st_nlink, |
|
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1692
diff
changeset
|
470 (long)st.st_uid, |
|
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1692
diff
changeset
|
471 (long)st.st_gid, |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
472 (long)st.st_size, |
|
1795
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1692
diff
changeset
|
473 (long)st.st_atime, |
|
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1692
diff
changeset
|
474 (long)st.st_mtime, |
|
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1692
diff
changeset
|
475 (long)st.st_ctime); |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
476 #endif |
| 1495 | 477 } |
| 478 | |
| 5071 | 479 static PyObject * |
|
2929
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
480 mac_xstat(self, args) |
| 5071 | 481 PyObject *self; |
| 482 PyObject *args; | |
|
2929
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
483 { |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
484 struct macstat mst; |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
485 struct stat st; |
|
2929
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
486 char *path; |
|
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
487 int res; |
| 5071 | 488 if (!PyArg_Parse(args, "s", &path)) |
|
2929
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
489 return NULL; |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
490 /* |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
491 ** Convoluted: we want stat() and xstat() to agree, so we call both |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
492 ** stat and macstat, and use the latter only for values not provided by |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
493 ** the former. |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
494 */ |
| 5071 | 495 Py_BEGIN_ALLOW_THREADS |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
496 res = macstat(path, &mst); |
| 5071 | 497 Py_END_ALLOW_THREADS |
|
2929
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
498 if (res != 0) |
|
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
499 return mac_error(); |
| 5071 | 500 Py_BEGIN_ALLOW_THREADS |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
501 res = stat(path, &st); |
| 5071 | 502 Py_END_ALLOW_THREADS |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
503 if (res != 0) |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
504 return mac_error(); |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
505 #if 1 |
| 5071 | 506 return Py_BuildValue("(llllllldddls#s#)", |
| 3394 | 507 (long)st.st_mode, |
| 508 (long)st.st_ino, | |
| 509 (long)st.st_dev, | |
| 510 (long)st.st_nlink, | |
| 511 (long)st.st_uid, | |
| 512 (long)st.st_gid, | |
| 513 (long)st.st_size, | |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
514 (double)st.st_atime, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
515 (double)st.st_mtime, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
516 (double)st.st_ctime, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
517 (long)mst.st_rsize, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
518 mst.st_creator, 4, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
519 mst.st_type, 4); |
| 3394 | 520 #else |
| 5071 | 521 return Py_BuildValue("(llllllllllls#s#)", |
|
2929
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
522 (long)st.st_mode, |
|
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
523 (long)st.st_ino, |
|
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
524 (long)st.st_dev, |
|
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
525 (long)st.st_nlink, |
|
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
526 (long)st.st_uid, |
|
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
527 (long)st.st_gid, |
|
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
528 (long)st.st_size, |
|
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
529 (long)st.st_atime, |
|
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
530 (long)st.st_mtime, |
|
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
531 (long)st.st_ctime, |
|
4414
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
532 (long)mst.st_rsize, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
533 mst.st_creator, 4, |
|
02a68d623805
Fixed xstat to again include resroucefork size, creator, type. Obtain
Jack Jansen <jack.jansen@cwi.nl>
parents:
3942
diff
changeset
|
534 mst.st_type, 4); |
| 3394 | 535 #endif |
|
2929
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
536 } |
|
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
537 |
| 5071 | 538 static PyObject * |
| 1495 | 539 mac_sync(self, args) |
| 5071 | 540 PyObject *self; |
| 541 PyObject *args; | |
| 1495 | 542 { |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
543 int res; |
| 5071 | 544 if (!PyArg_NoArgs(args)) |
| 1495 | 545 return NULL; |
| 5071 | 546 Py_BEGIN_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
547 res = sync(); |
| 5071 | 548 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
549 if (res != 0) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
550 return mac_error(); |
| 5071 | 551 Py_INCREF(Py_None); |
| 552 return Py_None; | |
| 1495 | 553 } |
| 554 | |
| 5071 | 555 static PyObject * |
| 1495 | 556 mac_unlink(self, args) |
| 5071 | 557 PyObject *self; |
| 558 PyObject *args; | |
| 1495 | 559 { |
|
1822
76d0f2b3b9ee
Completed (hopefully) the unification of THINK 6.0 and MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1821
diff
changeset
|
560 return mac_1str(args, (int (*)(const char *))unlink); |
| 1495 | 561 } |
| 562 | |
| 5071 | 563 static PyObject * |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
564 mac_write(self, args) |
| 5071 | 565 PyObject *self; |
| 566 PyObject *args; | |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
567 { |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
568 int fd, size; |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
569 char *buffer; |
|
5429
ac235c9e6881
- Changed the m# format for PyArg_ParseTuple back to s#
Jack Jansen <jack.jansen@cwi.nl>
parents:
5152
diff
changeset
|
570 if (!PyArg_Parse(args, "(is#)", &fd, &buffer, &size)) |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
571 return NULL; |
| 5071 | 572 Py_BEGIN_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
573 size = write(fd, buffer, size); |
| 5071 | 574 Py_END_ALLOW_THREADS |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
575 if (size < 0) |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
576 return mac_error(); |
| 5071 | 577 return PyInt_FromLong((long)size); |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
578 } |
| 1495 | 579 |
|
4468
600f5b8a16cb
Malloc debugging now flagged with USE_MALLOC_DEBUG
Jack Jansen <jack.jansen@cwi.nl>
parents:
4414
diff
changeset
|
580 #ifdef USE_MALLOC_DEBUG |
| 5071 | 581 static PyObject * |
|
2179
8da03decef59
More Pstring() stuff and some cosmetics
Jack Jansen <jack.jansen@cwi.nl>
parents:
2091
diff
changeset
|
582 mac_mstats(self, args) |
| 5071 | 583 PyObject*self; |
| 584 PyObject *args; | |
|
2179
8da03decef59
More Pstring() stuff and some cosmetics
Jack Jansen <jack.jansen@cwi.nl>
parents:
2091
diff
changeset
|
585 { |
|
8da03decef59
More Pstring() stuff and some cosmetics
Jack Jansen <jack.jansen@cwi.nl>
parents:
2091
diff
changeset
|
586 mstats("python"); |
| 5071 | 587 Py_INCREF(Py_None); |
| 588 return Py_None; | |
|
2179
8da03decef59
More Pstring() stuff and some cosmetics
Jack Jansen <jack.jansen@cwi.nl>
parents:
2091
diff
changeset
|
589 } |
|
5141
a4c8b8871376
Comments around identifier after #endif
Jack Jansen <jack.jansen@cwi.nl>
parents:
5079
diff
changeset
|
590 #endif /* USE_MALLOC_DEBUG */ |
|
2179
8da03decef59
More Pstring() stuff and some cosmetics
Jack Jansen <jack.jansen@cwi.nl>
parents:
2091
diff
changeset
|
591 |
| 5071 | 592 static struct PyMethodDef mac_methods[] = { |
| 1495 | 593 {"chdir", mac_chdir}, |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
594 {"close", mac_close}, |
| 3400 | 595 #ifdef WEHAVE_DUP |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
596 {"dup", mac_dup}, |
|
1821
40594f80ab3c
Intermediate version of changes after porting to MPW 3.2
Guido van Rossum <guido@python.org>
parents:
1808
diff
changeset
|
597 #endif |
| 3400 | 598 #ifdef WEHAVE_FDOPEN |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
599 {"fdopen", mac_fdopen}, |
|
2032
609bfb8ae7f5
Ported to MetroWerks, which misses file-descriptor like functionality.
Jack Jansen <jack.jansen@cwi.nl>
parents:
1822
diff
changeset
|
600 #endif |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
601 {"getbootvol", mac_getbootvol}, /* non-standard */ |
| 1495 | 602 {"getcwd", mac_getcwd}, |
|
2391
ecbbaa584f3c
explicitly init flags in methodlist
Guido van Rossum <guido@python.org>
parents:
2359
diff
changeset
|
603 {"listdir", mac_listdir, 0}, |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
604 {"lseek", mac_lseek}, |
|
3405
c283447b985f
Mods by Guido: mkdir 2nd arg optional and remove as alias for unlink.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3400
diff
changeset
|
605 {"mkdir", mac_mkdir, 1}, |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
606 {"open", mac_open}, |
|
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
607 {"read", mac_read}, |
| 1495 | 608 {"rename", mac_rename}, |
| 609 {"rmdir", mac_rmdir}, | |
| 610 {"stat", mac_stat}, | |
|
2929
7d1ecec25c06
add xstat (extended stat, returns resource fork size and creator/type)
Guido van Rossum <guido@python.org>
parents:
2722
diff
changeset
|
611 {"xstat", mac_xstat}, |
| 1495 | 612 {"sync", mac_sync}, |
|
3405
c283447b985f
Mods by Guido: mkdir 2nd arg optional and remove as alias for unlink.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3400
diff
changeset
|
613 {"remove", mac_unlink}, |
| 1495 | 614 {"unlink", mac_unlink}, |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
615 {"write", mac_write}, |
|
4468
600f5b8a16cb
Malloc debugging now flagged with USE_MALLOC_DEBUG
Jack Jansen <jack.jansen@cwi.nl>
parents:
4414
diff
changeset
|
616 #ifdef USE_MALLOC_DEBUG |
|
2179
8da03decef59
More Pstring() stuff and some cosmetics
Jack Jansen <jack.jansen@cwi.nl>
parents:
2091
diff
changeset
|
617 {"mstats", mac_mstats}, |
|
8da03decef59
More Pstring() stuff and some cosmetics
Jack Jansen <jack.jansen@cwi.nl>
parents:
2091
diff
changeset
|
618 #endif |
|
1620
8454579ab52f
As extended by Richard M Walker for MPW
Guido van Rossum <guido@python.org>
parents:
1522
diff
changeset
|
619 |
| 1495 | 620 {NULL, NULL} /* Sentinel */ |
| 621 }; | |
| 622 | |
| 623 | |
| 624 void | |
| 625 initmac() | |
| 626 { | |
| 5071 | 627 PyObject *m, *d; |
| 1495 | 628 |
| 5071 | 629 m = Py_InitModule("mac", mac_methods); |
| 630 d = PyModule_GetDict(m); | |
| 1495 | 631 |
| 632 /* Initialize mac.error exception */ | |
| 5071 | 633 MacError = PyString_FromString("mac.error"); |
| 634 if (MacError == NULL || PyDict_SetItemString(d, "error", MacError) != 0) | |
| 635 Py_FatalError("can't define mac.error"); | |
| 1495 | 636 } |
