Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 775f4da | 1993-01-09 17:18:52 +0000 | [diff] [blame] | 2 | Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, |
| 3 | Amsterdam, The Netherlands. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 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 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 25 | /* POSIX module implementation */ |
| 26 | |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 27 | #ifdef AMOEBA |
| 28 | #define NO_LSTAT |
| 29 | #define SYSV |
| 30 | #endif |
| 31 | |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 32 | #ifdef MSDOS |
| 33 | #define NO_LSTAT |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 34 | #define NO_UNAME |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 35 | #endif |
| 36 | |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 37 | #ifdef __sgi |
| 38 | #define DO_PG |
| 39 | #endif |
| 40 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 41 | #include <signal.h> |
| 42 | #include <string.h> |
| 43 | #include <setjmp.h> |
| 44 | #include <sys/types.h> |
| 45 | #include <sys/stat.h> |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 46 | |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 47 | #ifdef DO_TIMES |
| 48 | #include <sys/times.h> |
| 49 | #include <sys/param.h> |
| 50 | #include <errno.h> |
| 51 | #endif |
| 52 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 53 | #ifdef SYSV |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 54 | |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 55 | #define UTIME_STRUCT |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 56 | #include <dirent.h> |
| 57 | #define direct dirent |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 58 | #ifdef i386 |
| 59 | #define mode_t int |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 60 | #endif |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 61 | |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 62 | #else /* !SYSV */ |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 63 | |
| 64 | #ifndef MSDOS |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 65 | #include <sys/dir.h> |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 66 | #endif |
| 67 | |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 68 | #endif /* !SYSV */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 69 | |
Guido van Rossum | 50e61dc | 1992-03-27 17:22:31 +0000 | [diff] [blame] | 70 | #ifndef NO_UNISTD |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 71 | #include <unistd.h> /* Take this out and hope the best if it doesn't exist */ |
Guido van Rossum | 50e61dc | 1992-03-27 17:22:31 +0000 | [diff] [blame] | 72 | #endif |
| 73 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 74 | #include "allobjects.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 75 | #include "modsupport.h" |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 76 | #include "ceval.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 77 | |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 78 | #ifdef _SEQUENT_ |
| 79 | #include <unistd.h> |
| 80 | #else /* _SEQUENT_ */ |
Guido van Rossum | a2b7f40 | 1993-01-04 09:09:59 +0000 | [diff] [blame] | 81 | /* XXX Aren't these always declared in unistd.h? */ |
Guido van Rossum | 7f77e2d | 1990-10-30 13:34:38 +0000 | [diff] [blame] | 82 | extern char *strerror PROTO((int)); |
Guido van Rossum | a2b7f40 | 1993-01-04 09:09:59 +0000 | [diff] [blame] | 83 | extern int chmod PROTO((const char *, mode_t)); |
| 84 | extern char *getcwd PROTO((char *, int)); /* XXX or size_t? */ |
| 85 | extern int mkdir PROTO((const char *, mode_t)); |
| 86 | extern int chdir PROTO((const char *)); |
| 87 | extern int link PROTO((const char *, const char *)); |
| 88 | extern int rename PROTO((const char *, const char *)); |
| 89 | extern int rmdir PROTO((const char *)); |
| 90 | extern int stat PROTO((const char *, struct stat *)); |
| 91 | extern int unlink PROTO((const char *)); |
| 92 | extern int pclose PROTO((FILE *)); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 93 | #endif /* _SEQUENT_ */ |
Guido van Rossum | a2b7f40 | 1993-01-04 09:09:59 +0000 | [diff] [blame] | 94 | #ifdef NO_LSTAT |
| 95 | #define lstat stat |
| 96 | #else |
| 97 | extern int lstat PROTO((const char *, struct stat *)); |
| 98 | extern int symlink PROTO((const char *, const char *)); |
| 99 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 100 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 101 | |
| 102 | /* Return a dictionary corresponding to the POSIX environment table */ |
| 103 | |
| 104 | extern char **environ; |
| 105 | |
| 106 | static object * |
| 107 | convertenviron() |
| 108 | { |
| 109 | object *d; |
| 110 | char **e; |
| 111 | d = newdictobject(); |
| 112 | if (d == NULL) |
| 113 | return NULL; |
| 114 | if (environ == NULL) |
| 115 | return d; |
| 116 | /* XXX This part ignores errors */ |
| 117 | for (e = environ; *e != NULL; e++) { |
| 118 | object *v; |
| 119 | char *p = strchr(*e, '='); |
| 120 | if (p == NULL) |
| 121 | continue; |
| 122 | v = newstringobject(p+1); |
| 123 | if (v == NULL) |
| 124 | continue; |
| 125 | *p = '\0'; |
| 126 | (void) dictinsert(d, *e, v); |
| 127 | *p = '='; |
| 128 | DECREF(v); |
| 129 | } |
| 130 | return d; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | static object *PosixError; /* Exception posix.error */ |
| 135 | |
| 136 | /* Set a POSIX-specific error from errno, and return NULL */ |
| 137 | |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 138 | static object * posix_error() { return err_errno(PosixError); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
| 142 | /* POSIX generic methods */ |
| 143 | |
| 144 | static object * |
| 145 | posix_1str(args, func) |
| 146 | object *args; |
| 147 | int (*func) FPROTO((const char *)); |
| 148 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 149 | char *path1; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 150 | int res; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 151 | if (!getstrarg(args, &path1)) |
| 152 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 153 | BGN_SAVE |
| 154 | res = (*func)(path1); |
| 155 | END_SAVE |
| 156 | if (res < 0) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 157 | return posix_error(); |
| 158 | INCREF(None); |
| 159 | return None; |
| 160 | } |
| 161 | |
| 162 | static object * |
| 163 | posix_2str(args, func) |
| 164 | object *args; |
| 165 | int (*func) FPROTO((const char *, const char *)); |
| 166 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 167 | char *path1, *path2; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 168 | int res; |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame^] | 169 | if (!getargs(args, "(ss)", &path1, &path2)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 170 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 171 | BGN_SAVE |
| 172 | res = (*func)(path1, path2); |
| 173 | END_SAVE |
| 174 | if (res < 0) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 175 | return posix_error(); |
| 176 | INCREF(None); |
| 177 | return None; |
| 178 | } |
| 179 | |
| 180 | static object * |
| 181 | posix_strint(args, func) |
| 182 | object *args; |
| 183 | int (*func) FPROTO((const char *, int)); |
| 184 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 185 | char *path; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 186 | int i; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 187 | int res; |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame^] | 188 | if (!getargs(args, "(si)", &path, &i)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 189 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 190 | BGN_SAVE |
| 191 | res = (*func)(path, i); |
| 192 | END_SAVE |
| 193 | if (res < 0) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 194 | return posix_error(); |
| 195 | INCREF(None); |
| 196 | return None; |
| 197 | } |
| 198 | |
| 199 | static object * |
| 200 | posix_do_stat(self, args, statfunc) |
| 201 | object *self; |
| 202 | object *args; |
| 203 | int (*statfunc) FPROTO((const char *, struct stat *)); |
| 204 | { |
| 205 | struct stat st; |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 206 | char *path; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 207 | int res; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 208 | if (!getstrarg(args, &path)) |
| 209 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 210 | BGN_SAVE |
| 211 | res = (*statfunc)(path, &st); |
| 212 | END_SAVE |
| 213 | if (res != 0) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 214 | return posix_error(); |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 215 | return mkvalue("(llllllllll)", |
Guido van Rossum | e537240 | 1993-03-16 12:15:04 +0000 | [diff] [blame] | 216 | (long)st.st_mode, |
| 217 | (long)st.st_ino, |
| 218 | (long)st.st_dev, |
| 219 | (long)st.st_nlink, |
| 220 | (long)st.st_uid, |
| 221 | (long)st.st_gid, |
| 222 | (long)st.st_size, |
| 223 | (long)st.st_atime, |
| 224 | (long)st.st_mtime, |
| 225 | (long)st.st_ctime); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | |
| 229 | /* POSIX methods */ |
| 230 | |
| 231 | static object * |
| 232 | posix_chdir(self, args) |
| 233 | object *self; |
| 234 | object *args; |
| 235 | { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 236 | return posix_1str(args, chdir); |
| 237 | } |
| 238 | |
| 239 | static object * |
| 240 | posix_chmod(self, args) |
| 241 | object *self; |
| 242 | object *args; |
| 243 | { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 244 | return posix_strint(args, chmod); |
| 245 | } |
| 246 | |
| 247 | static object * |
| 248 | posix_getcwd(self, args) |
| 249 | object *self; |
| 250 | object *args; |
| 251 | { |
| 252 | char buf[1026]; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 253 | char *res; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 254 | if (!getnoarg(args)) |
| 255 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 256 | BGN_SAVE |
| 257 | res = getcwd(buf, sizeof buf); |
| 258 | END_SAVE |
| 259 | if (res == NULL) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 260 | return posix_error(); |
| 261 | return newstringobject(buf); |
| 262 | } |
| 263 | |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 264 | #ifndef MSDOS |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 265 | static object * |
| 266 | posix_link(self, args) |
| 267 | object *self; |
| 268 | object *args; |
| 269 | { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 270 | return posix_2str(args, link); |
| 271 | } |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 272 | #endif /* !MSDOS */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 273 | |
| 274 | static object * |
| 275 | posix_listdir(self, args) |
| 276 | object *self; |
| 277 | object *args; |
| 278 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 279 | char *name; |
| 280 | object *d, *v; |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 281 | |
| 282 | #ifdef MSDOS |
| 283 | struct ffblk ep; |
| 284 | int rv; |
| 285 | if (!getstrarg(args, &name)) |
| 286 | return NULL; |
| 287 | |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 288 | if (findfirst(name, &ep, 0) == -1) |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 289 | return posix_error(); |
| 290 | if ((d = newlistobject(0)) == NULL) |
| 291 | return NULL; |
| 292 | do { |
| 293 | v = newstringobject(ep.ff_name); |
| 294 | if (v == NULL) { |
| 295 | DECREF(d); |
| 296 | d = NULL; |
| 297 | break; |
| 298 | } |
| 299 | if (addlistitem(d, v) != 0) { |
| 300 | DECREF(v); |
| 301 | DECREF(d); |
| 302 | d = NULL; |
| 303 | break; |
| 304 | } |
| 305 | DECREF(v); |
| 306 | } while ((rv = findnext(&ep)) == 0); |
| 307 | #else /* !MSDOS */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 308 | DIR *dirp; |
| 309 | struct direct *ep; |
| 310 | if (!getstrarg(args, &name)) |
| 311 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 312 | BGN_SAVE |
| 313 | if ((dirp = opendir(name)) == NULL) { |
| 314 | RET_SAVE |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 315 | return posix_error(); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 316 | } |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 317 | if ((d = newlistobject(0)) == NULL) { |
| 318 | closedir(dirp); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 319 | RET_SAVE |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 320 | return NULL; |
| 321 | } |
| 322 | while ((ep = readdir(dirp)) != NULL) { |
| 323 | v = newstringobject(ep->d_name); |
| 324 | if (v == NULL) { |
| 325 | DECREF(d); |
| 326 | d = NULL; |
| 327 | break; |
| 328 | } |
| 329 | if (addlistitem(d, v) != 0) { |
| 330 | DECREF(v); |
| 331 | DECREF(d); |
| 332 | d = NULL; |
| 333 | break; |
| 334 | } |
| 335 | DECREF(v); |
| 336 | } |
| 337 | closedir(dirp); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 338 | END_SAVE |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 339 | #endif /* !MSDOS */ |
| 340 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 341 | return d; |
| 342 | } |
| 343 | |
| 344 | static object * |
| 345 | posix_mkdir(self, args) |
| 346 | object *self; |
| 347 | object *args; |
| 348 | { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 349 | return posix_strint(args, mkdir); |
| 350 | } |
| 351 | |
Guido van Rossum | 775f4da | 1993-01-09 17:18:52 +0000 | [diff] [blame] | 352 | #ifndef MSDOS |
| 353 | static object * |
| 354 | posix_nice(self, args) |
| 355 | object *self; |
| 356 | object *args; |
| 357 | { |
| 358 | int increment, value; |
| 359 | |
| 360 | if (!getargs(args, "i", &increment)) |
| 361 | return NULL; |
| 362 | value = nice(increment); |
| 363 | if (value == -1) |
| 364 | return posix_error(); |
| 365 | return newintobject((long) value); |
| 366 | } |
| 367 | #endif |
| 368 | |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 369 | #if i386 && ! _SEQUENT_ |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 370 | int |
| 371 | rename(from, to) |
| 372 | char *from; |
| 373 | char *to; |
| 374 | { |
| 375 | int status; |
| 376 | /* XXX Shouldn't this unlink the destination first? */ |
| 377 | status = link(from, to); |
| 378 | if (status != 0) |
| 379 | return status; |
| 380 | return unlink(from); |
| 381 | } |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 382 | #endif /* i386 && ! _SEQUENT_ */ |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 383 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 384 | static object * |
| 385 | posix_rename(self, args) |
| 386 | object *self; |
| 387 | object *args; |
| 388 | { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 389 | return posix_2str(args, rename); |
| 390 | } |
| 391 | |
| 392 | static object * |
| 393 | posix_rmdir(self, args) |
| 394 | object *self; |
| 395 | object *args; |
| 396 | { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 397 | return posix_1str(args, rmdir); |
| 398 | } |
| 399 | |
| 400 | static object * |
| 401 | posix_stat(self, args) |
| 402 | object *self; |
| 403 | object *args; |
| 404 | { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 405 | return posix_do_stat(self, args, stat); |
| 406 | } |
| 407 | |
| 408 | static object * |
| 409 | posix_system(self, args) |
| 410 | object *self; |
| 411 | object *args; |
| 412 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 413 | char *command; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 414 | long sts; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 415 | if (!getstrarg(args, &command)) |
| 416 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 417 | BGN_SAVE |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 418 | sts = system(command); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 419 | END_SAVE |
| 420 | return newintobject(sts); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 423 | #ifndef MSDOS |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 424 | static object * |
| 425 | posix_umask(self, args) |
| 426 | object *self; |
| 427 | object *args; |
| 428 | { |
| 429 | int i; |
| 430 | if (!getintarg(args, &i)) |
| 431 | return NULL; |
| 432 | i = umask(i); |
| 433 | if (i < 0) |
| 434 | return posix_error(); |
| 435 | return newintobject((long)i); |
| 436 | } |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 437 | #endif /* !MSDOS */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 438 | |
| 439 | static object * |
| 440 | posix_unlink(self, args) |
| 441 | object *self; |
| 442 | object *args; |
| 443 | { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 444 | return posix_1str(args, unlink); |
| 445 | } |
| 446 | |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 447 | #ifndef NO_UNAME |
| 448 | #include <sys/utsname.h> |
| 449 | |
Guido van Rossum | a2b7f40 | 1993-01-04 09:09:59 +0000 | [diff] [blame] | 450 | extern int uname PROTO((struct utsname *)); |
| 451 | |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 452 | static object * |
| 453 | posix_uname(self, args) |
| 454 | object *self; |
| 455 | object *args; |
| 456 | { |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 457 | struct utsname u; |
| 458 | object *v; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 459 | int res; |
Guido van Rossum | 50e61dc | 1992-03-27 17:22:31 +0000 | [diff] [blame] | 460 | if (!getnoarg(args)) |
| 461 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 462 | BGN_SAVE |
| 463 | res = uname(&u); |
| 464 | END_SAVE |
| 465 | if (res < 0) |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 466 | return posix_error(); |
Guido van Rossum | e537240 | 1993-03-16 12:15:04 +0000 | [diff] [blame] | 467 | return mkvalue("(sssss)", |
| 468 | u.sysname, |
| 469 | u.nodename, |
| 470 | u.release, |
| 471 | u.version, |
| 472 | u.machine); |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 473 | } |
| 474 | #endif /* NO_UNAME */ |
| 475 | |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 476 | #ifdef UTIME_STRUCT |
| 477 | #include <utime.h> |
| 478 | #endif |
| 479 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 480 | static object * |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 481 | posix_utime(self, args) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 482 | object *self; |
| 483 | object *args; |
| 484 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 485 | char *path; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 486 | int res; |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 487 | |
| 488 | #ifdef UTIME_STRUCT |
| 489 | struct utimbuf buf; |
| 490 | #define ATIME buf.actime |
| 491 | #define MTIME buf.modtime |
| 492 | #define UTIME_ARG &buf |
| 493 | |
| 494 | #else |
| 495 | time_t buf[2]; |
| 496 | #define ATIME buf[0] |
| 497 | #define MTIME buf[1] |
| 498 | #define UTIME_ARG buf |
| 499 | #endif |
| 500 | |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 501 | if (!getargs(args, "(s(ll))", &path, &ATIME, &MTIME)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 502 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 503 | BGN_SAVE |
| 504 | res = utime(path, UTIME_ARG); |
| 505 | END_SAVE |
| 506 | if (res < 0) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 507 | return posix_error(); |
| 508 | INCREF(None); |
| 509 | return None; |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 510 | #undef UTIME_ARG |
| 511 | #undef ATIME |
| 512 | #undef MTIME |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 515 | |
| 516 | #ifndef MSDOS |
| 517 | |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 518 | /* Process operations */ |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 519 | |
| 520 | static object * |
| 521 | posix__exit(self, args) |
| 522 | object *self; |
| 523 | object *args; |
| 524 | { |
| 525 | int sts; |
| 526 | if (!getintarg(args, &sts)) |
| 527 | return NULL; |
| 528 | _exit(sts); |
| 529 | /* NOTREACHED */ |
| 530 | } |
| 531 | |
| 532 | /* XXX To do: exece, execp */ |
| 533 | |
| 534 | static object * |
| 535 | posix_exec(self, args) |
| 536 | object *self; |
| 537 | object *args; |
| 538 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 539 | char *path; |
| 540 | object *argv; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 541 | char **argvlist; |
| 542 | int i, argc; |
| 543 | object *(*getitem) PROTO((object *, int)); |
| 544 | |
| 545 | /* exec has two arguments: (path, argv), where |
| 546 | argv is a list or tuple of strings. */ |
| 547 | |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 548 | if (!getargs(args, "(sO)", &path, &argv)) |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 549 | return NULL; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 550 | if (is_listobject(argv)) { |
| 551 | argc = getlistsize(argv); |
| 552 | getitem = getlistitem; |
| 553 | } |
| 554 | else if (is_tupleobject(argv)) { |
| 555 | argc = gettuplesize(argv); |
| 556 | getitem = gettupleitem; |
| 557 | } |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 558 | else { |
| 559 | badarg: |
| 560 | err_badarg(); |
| 561 | return NULL; |
| 562 | } |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 563 | |
| 564 | argvlist = NEW(char *, argc+1); |
| 565 | if (argvlist == NULL) |
| 566 | return NULL; |
| 567 | for (i = 0; i < argc; i++) { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 568 | if (!getstrarg((*getitem)(argv, i), &argvlist[i])) { |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 569 | DEL(argvlist); |
| 570 | goto badarg; |
| 571 | } |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 572 | } |
| 573 | argvlist[argc] = NULL; |
| 574 | |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 575 | execv(path, argvlist); |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 576 | |
| 577 | /* If we get here it's definitely an error */ |
| 578 | |
| 579 | DEL(argvlist); |
| 580 | return posix_error(); |
| 581 | } |
| 582 | |
| 583 | static object * |
| 584 | posix_fork(self, args) |
| 585 | object *self; |
| 586 | object *args; |
| 587 | { |
| 588 | int pid; |
Guido van Rossum | 50e61dc | 1992-03-27 17:22:31 +0000 | [diff] [blame] | 589 | if (!getnoarg(args)) |
| 590 | return NULL; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 591 | pid = fork(); |
| 592 | if (pid == -1) |
| 593 | return posix_error(); |
| 594 | return newintobject((long)pid); |
| 595 | } |
| 596 | |
| 597 | static object * |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 598 | posix_getegid(self, args) |
| 599 | object *self; |
| 600 | object *args; |
| 601 | { |
| 602 | if (!getnoarg(args)) |
| 603 | return NULL; |
| 604 | return newintobject((long)getegid()); |
| 605 | } |
| 606 | |
| 607 | static object * |
| 608 | posix_geteuid(self, args) |
| 609 | object *self; |
| 610 | object *args; |
| 611 | { |
| 612 | if (!getnoarg(args)) |
| 613 | return NULL; |
| 614 | return newintobject((long)geteuid()); |
| 615 | } |
| 616 | |
| 617 | static object * |
| 618 | posix_getgid(self, args) |
| 619 | object *self; |
| 620 | object *args; |
| 621 | { |
| 622 | if (!getnoarg(args)) |
| 623 | return NULL; |
| 624 | return newintobject((long)getgid()); |
| 625 | } |
| 626 | |
| 627 | static object * |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 628 | posix_getpid(self, args) |
| 629 | object *self; |
| 630 | object *args; |
| 631 | { |
Guido van Rossum | 0481447 | 1991-06-04 20:23:49 +0000 | [diff] [blame] | 632 | if (!getnoarg(args)) |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 633 | return NULL; |
| 634 | return newintobject((long)getpid()); |
| 635 | } |
| 636 | |
| 637 | static object * |
Guido van Rossum | 0481447 | 1991-06-04 20:23:49 +0000 | [diff] [blame] | 638 | posix_getpgrp(self, args) |
| 639 | object *self; |
| 640 | object *args; |
| 641 | { |
| 642 | if (!getnoarg(args)) |
| 643 | return NULL; |
Guido van Rossum | 50e61dc | 1992-03-27 17:22:31 +0000 | [diff] [blame] | 644 | #ifdef SYSV |
| 645 | return newintobject((long)getpgrp()); |
| 646 | #else |
Guido van Rossum | 971443b | 1991-06-07 13:59:29 +0000 | [diff] [blame] | 647 | return newintobject((long)getpgrp(0)); |
Guido van Rossum | 50e61dc | 1992-03-27 17:22:31 +0000 | [diff] [blame] | 648 | #endif |
Guido van Rossum | 0481447 | 1991-06-04 20:23:49 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | static object * |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 652 | posix_setpgrp(self, args) |
| 653 | object *self; |
| 654 | object *args; |
| 655 | { |
| 656 | if (!getnoarg(args)) |
| 657 | return NULL; |
| 658 | #ifdef SYSV |
| 659 | if (setpgrp() < 0) |
| 660 | #else |
| 661 | if (setpgrp(0, 0) < 0) |
| 662 | #endif |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 663 | return posix_error(); |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 664 | INCREF(None); |
| 665 | return None; |
| 666 | } |
| 667 | |
| 668 | static object * |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 669 | posix_getppid(self, args) |
| 670 | object *self; |
| 671 | object *args; |
| 672 | { |
Guido van Rossum | 0481447 | 1991-06-04 20:23:49 +0000 | [diff] [blame] | 673 | if (!getnoarg(args)) |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 674 | return NULL; |
| 675 | return newintobject((long)getppid()); |
| 676 | } |
| 677 | |
| 678 | static object * |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 679 | posix_getuid(self, args) |
| 680 | object *self; |
| 681 | object *args; |
| 682 | { |
| 683 | if (!getnoarg(args)) |
| 684 | return NULL; |
| 685 | return newintobject((long)getuid()); |
| 686 | } |
| 687 | |
| 688 | static object * |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 689 | posix_kill(self, args) |
| 690 | object *self; |
| 691 | object *args; |
| 692 | { |
| 693 | int pid, sig; |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame^] | 694 | if (!getargs(args, "(ii)", &pid, &sig)) |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 695 | return NULL; |
| 696 | if (kill(pid, sig) == -1) |
| 697 | return posix_error(); |
| 698 | INCREF(None); |
| 699 | return None; |
| 700 | } |
| 701 | |
| 702 | static object * |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 703 | posix_popen(self, args) |
| 704 | object *self; |
| 705 | object *args; |
| 706 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 707 | char *name, *mode; |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 708 | FILE *fp; |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 709 | if (!getargs(args, "(ss)", &name, &mode)) |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 710 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 711 | BGN_SAVE |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 712 | fp = popen(name, mode); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 713 | END_SAVE |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 714 | if (fp == NULL) |
| 715 | return posix_error(); |
Guido van Rossum | e0d452d | 1991-07-27 21:41:01 +0000 | [diff] [blame] | 716 | /* From now on, ignore SIGPIPE and let the error checking |
| 717 | do the work. */ |
| 718 | (void) signal(SIGPIPE, SIG_IGN); |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 719 | return newopenfileobject(fp, name, mode, pclose); |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | static object * |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 723 | posix_waitpid(self, args) |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 724 | object *self; |
| 725 | object *args; |
| 726 | { |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 727 | #ifdef NO_WAITPID |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 728 | err_setstr(PosixError, |
| 729 | "posix.waitpid() not supported on this system"); |
| 730 | return NULL; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 731 | #else |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 732 | int pid, options, sts; |
| 733 | if (!getargs(args, "(ii)", &pid, &options)) |
| 734 | return NULL; |
| 735 | BGN_SAVE |
| 736 | pid = waitpid(pid, &sts, options); |
| 737 | END_SAVE |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 738 | if (pid == -1) |
| 739 | return posix_error(); |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 740 | else |
| 741 | return mkvalue("ii", pid, sts); |
| 742 | #endif |
| 743 | } |
| 744 | |
| 745 | static object * |
| 746 | posix_wait(self, args) |
| 747 | object *self; |
| 748 | object *args; |
| 749 | { |
| 750 | int pid, sts; |
| 751 | if (args != NULL) |
| 752 | return posix_waitpid(self, args); /* BW compat */ |
| 753 | BGN_SAVE |
| 754 | pid = wait(&sts); |
| 755 | END_SAVE |
| 756 | if (pid == -1) |
| 757 | return posix_error(); |
| 758 | else |
| 759 | return mkvalue("ii", pid, sts); |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | #endif /* MSDOS */ |
| 763 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 764 | static object * |
| 765 | posix_lstat(self, args) |
| 766 | object *self; |
| 767 | object *args; |
| 768 | { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 769 | return posix_do_stat(self, args, lstat); |
| 770 | } |
| 771 | |
| 772 | static object * |
| 773 | posix_readlink(self, args) |
| 774 | object *self; |
| 775 | object *args; |
| 776 | { |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 777 | #ifdef NO_LSTAT |
| 778 | err_setstr(PosixError, "readlink not implemented on this system"); |
| 779 | return NULL; |
| 780 | #else |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 781 | char buf[1024]; /* XXX Should use MAXPATHLEN */ |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 782 | char *path; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 783 | int n; |
| 784 | if (!getstrarg(args, &path)) |
| 785 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 786 | BGN_SAVE |
Guido van Rossum | 50e61dc | 1992-03-27 17:22:31 +0000 | [diff] [blame] | 787 | n = readlink(path, buf, (int) sizeof buf); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 788 | END_SAVE |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 789 | if (n < 0) |
| 790 | return posix_error(); |
| 791 | return newsizedstringobject(buf, n); |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 792 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | static object * |
| 796 | posix_symlink(self, args) |
| 797 | object *self; |
| 798 | object *args; |
| 799 | { |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 800 | #ifdef NO_LSTAT |
| 801 | err_setstr(PosixError, "symlink not implemented on this system"); |
| 802 | return NULL; |
| 803 | #else |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 804 | return posix_2str(args, symlink); |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 805 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 806 | } |
| 807 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 808 | |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 809 | #ifdef DO_TIMES |
| 810 | |
| 811 | static object * |
| 812 | posix_times(self, args) |
| 813 | object *self; |
| 814 | object *args; |
| 815 | { |
| 816 | struct tms t; |
| 817 | clock_t c; |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 818 | if (!getnoarg(args)) |
| 819 | return NULL; |
| 820 | errno = 0; |
| 821 | c = times(&t); |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 822 | if (c == (clock_t) -1) |
| 823 | return posix_error(); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 824 | return mkvalue("dddd", |
| 825 | (double)t.tms_utime / HZ, |
| 826 | (double)t.tms_stime / HZ, |
| 827 | (double)t.tms_cutime / HZ, |
| 828 | (double)t.tms_cstime / HZ); |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 831 | #endif /* DO_TIMES */ |
| 832 | |
| 833 | #ifdef DO_PG |
| 834 | |
| 835 | static object * |
| 836 | posix_setsid(self, args) |
| 837 | object *self; |
| 838 | object *args; |
| 839 | { |
| 840 | if (!getnoarg(args)) |
| 841 | return NULL; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 842 | if (setsid() < 0) |
| 843 | return posix_error(); |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 844 | INCREF(None); |
| 845 | return None; |
| 846 | } |
| 847 | |
| 848 | static object * |
| 849 | posix_setpgid(self, args) |
| 850 | object *self; |
| 851 | object *args; |
| 852 | { |
| 853 | int pid, pgrp; |
| 854 | if (!getargs(args, "(ii)", &pid, &pgrp)) |
| 855 | return NULL; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 856 | if (setpgid(pid, pgrp) < 0) |
| 857 | return posix_error(); |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 858 | INCREF(None); |
| 859 | return None; |
| 860 | } |
| 861 | |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 862 | static object * |
| 863 | posix_tcgetpgrp(self, args) |
| 864 | object *self; |
| 865 | object *args; |
| 866 | { |
| 867 | int fd, pgid; |
| 868 | if (!getargs(args, "i", &fd)) |
| 869 | return NULL; |
| 870 | pgid = tcgetpgrp(fd); |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 871 | if (pgid < 0) |
| 872 | return posix_error(); |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 873 | return newintobject((long)pgid); |
| 874 | } |
| 875 | |
| 876 | static object * |
| 877 | posix_tcsetpgrp(self, args) |
| 878 | object *self; |
| 879 | object *args; |
| 880 | { |
| 881 | int fd, pgid; |
| 882 | if (!getargs(args, "(ii)", &fd, &pgid)) |
| 883 | return NULL; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 884 | if (tcsetpgrp(fd, pgid) < 0) |
| 885 | return posix_error(); |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 886 | INCREF(None); |
| 887 | return None; |
| 888 | } |
| 889 | |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 890 | #endif /* DO_PG */ |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 891 | |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 892 | /* Functions acting on file descriptors */ |
| 893 | |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame^] | 894 | static object * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 895 | posix_open(self, args) |
| 896 | object *self; |
| 897 | object *args; |
| 898 | { |
| 899 | char *file; |
| 900 | int flag; |
| 901 | int mode = 0777; |
| 902 | int fd; |
| 903 | if (!getargs(args, "(si)", &file, &flag)) { |
| 904 | err_clear(); |
| 905 | if (!getargs(args, "(sii)", &file, &flag, &mode)) |
| 906 | return NULL; |
| 907 | } |
| 908 | BGN_SAVE |
| 909 | fd = open(file, flag, mode); |
| 910 | END_SAVE |
| 911 | if (fd < 0) |
| 912 | return posix_error(); |
| 913 | return newintobject((long)fd); |
| 914 | } |
| 915 | |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame^] | 916 | static object * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 917 | posix_close(self, args) |
| 918 | object *self; |
| 919 | object *args; |
| 920 | { |
| 921 | int fd, res; |
| 922 | if (!getargs(args, "i", &fd)) |
| 923 | return NULL; |
| 924 | BGN_SAVE |
| 925 | res = close(fd); |
| 926 | END_SAVE |
| 927 | if (res < 0) |
| 928 | return posix_error(); |
| 929 | INCREF(None); |
| 930 | return None; |
| 931 | } |
| 932 | |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame^] | 933 | static object * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 934 | posix_dup(self, args) |
| 935 | object *self; |
| 936 | object *args; |
| 937 | { |
| 938 | int fd; |
| 939 | if (!getargs(args, "i", &fd)) |
| 940 | return NULL; |
| 941 | BGN_SAVE |
| 942 | fd = dup(fd); |
| 943 | END_SAVE |
| 944 | if (fd < 0) |
| 945 | return posix_error(); |
| 946 | return newintobject((long)fd); |
| 947 | } |
| 948 | |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame^] | 949 | static object * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 950 | posix_dup2(self, args) |
| 951 | object *self; |
| 952 | object *args; |
| 953 | { |
| 954 | int fd, fd2, res; |
| 955 | if (!getargs(args, "(ii)", &fd, &fd2)) |
| 956 | return NULL; |
| 957 | BGN_SAVE |
| 958 | res = dup2(fd, fd2); |
| 959 | END_SAVE |
| 960 | if (res < 0) |
| 961 | return posix_error(); |
| 962 | INCREF(None); |
| 963 | return None; |
| 964 | } |
| 965 | |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame^] | 966 | static object * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 967 | posix_lseek(self, args) |
| 968 | object *self; |
| 969 | object *args; |
| 970 | { |
| 971 | int fd, how; |
| 972 | long pos, res; |
| 973 | if (!getargs(args, "(ili)", &fd, &pos, &how)) |
| 974 | return NULL; |
| 975 | #ifdef SEEK_SET |
| 976 | /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */ |
| 977 | switch (how) { |
| 978 | case 0: how = SEEK_SET; break; |
| 979 | case 1: how = SEEK_CUR; break; |
| 980 | case 2: how = SEEK_END; break; |
| 981 | } |
| 982 | #endif |
| 983 | BGN_SAVE |
| 984 | res = lseek(fd, pos, how); |
| 985 | END_SAVE |
| 986 | if (res < 0) |
| 987 | return posix_error(); |
| 988 | return newintobject(res); |
| 989 | } |
| 990 | |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame^] | 991 | static object * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 992 | posix_read(self, args) |
| 993 | object *self; |
| 994 | object *args; |
| 995 | { |
| 996 | int fd, size; |
| 997 | object *buffer; |
| 998 | if (!getargs(args, "(ii)", &fd, &size)) |
| 999 | return NULL; |
| 1000 | buffer = newsizedstringobject((char *)NULL, size); |
| 1001 | if (buffer == NULL) |
| 1002 | return NULL; |
| 1003 | BGN_SAVE |
| 1004 | size = read(fd, getstringvalue(buffer), size); |
| 1005 | END_SAVE |
| 1006 | if (size < 0) { |
| 1007 | DECREF(buffer); |
| 1008 | return posix_error(); |
| 1009 | } |
| 1010 | resizestring(&buffer, size); |
| 1011 | return buffer; |
| 1012 | } |
| 1013 | |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame^] | 1014 | static object * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 1015 | posix_write(self, args) |
| 1016 | object *self; |
| 1017 | object *args; |
| 1018 | { |
| 1019 | int fd, size; |
| 1020 | char *buffer; |
| 1021 | if (!getargs(args, "(is#)", &fd, &buffer, &size)) |
| 1022 | return NULL; |
| 1023 | BGN_SAVE |
| 1024 | size = write(fd, buffer, size); |
| 1025 | END_SAVE |
| 1026 | if (size < 0) |
| 1027 | return posix_error(); |
| 1028 | return newintobject((long)size); |
| 1029 | } |
| 1030 | |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame^] | 1031 | static object * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 1032 | posix_fstat(self, args) |
| 1033 | object *self; |
| 1034 | object *args; |
| 1035 | { |
| 1036 | int fd; |
| 1037 | struct stat st; |
| 1038 | int res; |
| 1039 | if (!getargs(args, "i", &fd)) |
| 1040 | return NULL; |
| 1041 | BGN_SAVE |
| 1042 | res = fstat(fd, &st); |
| 1043 | END_SAVE |
| 1044 | if (res != 0) |
| 1045 | return posix_error(); |
| 1046 | return mkvalue("(llllllllll)", |
| 1047 | (long)st.st_mode, |
| 1048 | (long)st.st_ino, |
| 1049 | (long)st.st_dev, |
| 1050 | (long)st.st_nlink, |
| 1051 | (long)st.st_uid, |
| 1052 | (long)st.st_gid, |
| 1053 | (long)st.st_size, |
| 1054 | (long)st.st_atime, |
| 1055 | (long)st.st_mtime, |
| 1056 | (long)st.st_ctime); |
| 1057 | } |
| 1058 | |
| 1059 | static object * |
| 1060 | posix_fdopen(self, args) |
| 1061 | object *self; |
| 1062 | object *args; |
| 1063 | { |
| 1064 | extern int fclose PROTO((FILE *)); |
| 1065 | int fd; |
| 1066 | char *mode; |
| 1067 | FILE *fp; |
| 1068 | if (!getargs(args, "(is)", &fd, &mode)) |
| 1069 | return NULL; |
| 1070 | BGN_SAVE |
| 1071 | fp = fdopen(fd, mode); |
| 1072 | END_SAVE |
| 1073 | if (fp == NULL) |
| 1074 | return posix_error(); |
| 1075 | /* From now on, ignore SIGPIPE and let the error checking |
| 1076 | do the work. */ |
| 1077 | (void) signal(SIGPIPE, SIG_IGN); |
| 1078 | return newopenfileobject(fp, "(fdopen)", mode, fclose); |
| 1079 | } |
| 1080 | |
| 1081 | #ifndef MSDOS |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame^] | 1082 | static object * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 1083 | posix_pipe(self, args) |
| 1084 | object *self; |
| 1085 | object *args; |
| 1086 | { |
| 1087 | int fds[2]; |
| 1088 | int res; |
| 1089 | if (!getargs(args, "")) |
| 1090 | return NULL; |
| 1091 | BGN_SAVE |
| 1092 | res = pipe(fds); |
| 1093 | END_SAVE |
| 1094 | if (res != 0) |
| 1095 | return posix_error(); |
| 1096 | return mkvalue("(ii)", fds[0], fds[1]); |
| 1097 | } |
| 1098 | #endif /* MSDOS */ |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 1099 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1100 | static struct methodlist posix_methods[] = { |
| 1101 | {"chdir", posix_chdir}, |
| 1102 | {"chmod", posix_chmod}, |
| 1103 | {"getcwd", posix_getcwd}, |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 1104 | #ifndef MSDOS |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1105 | {"link", posix_link}, |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 1106 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1107 | {"listdir", posix_listdir}, |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 1108 | {"lstat", posix_lstat}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1109 | {"mkdir", posix_mkdir}, |
Guido van Rossum | 775f4da | 1993-01-09 17:18:52 +0000 | [diff] [blame] | 1110 | #ifndef MSDOS |
| 1111 | {"nice", posix_nice}, |
| 1112 | #endif |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 1113 | {"readlink", posix_readlink}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1114 | {"rename", posix_rename}, |
| 1115 | {"rmdir", posix_rmdir}, |
| 1116 | {"stat", posix_stat}, |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 1117 | {"symlink", posix_symlink}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1118 | {"system", posix_system}, |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 1119 | #ifndef MSDOS |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1120 | {"umask", posix_umask}, |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 1121 | #endif |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 1122 | #ifndef NO_UNAME |
| 1123 | {"uname", posix_uname}, |
| 1124 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1125 | {"unlink", posix_unlink}, |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 1126 | {"utime", posix_utime}, |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 1127 | #ifdef DO_TIMES |
| 1128 | {"times", posix_times}, |
| 1129 | #endif |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 1130 | |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1131 | #ifndef MSDOS |
| 1132 | {"_exit", posix__exit}, |
| 1133 | {"exec", posix_exec}, |
| 1134 | {"fork", posix_fork}, |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1135 | {"getegid", posix_getegid}, |
| 1136 | {"geteuid", posix_geteuid}, |
| 1137 | {"getgid", posix_getgid}, |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1138 | {"getpid", posix_getpid}, |
Guido van Rossum | 0481447 | 1991-06-04 20:23:49 +0000 | [diff] [blame] | 1139 | {"getpgrp", posix_getpgrp}, |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1140 | {"getppid", posix_getppid}, |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1141 | {"getuid", posix_getuid}, |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1142 | {"kill", posix_kill}, |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 1143 | {"popen", posix_popen}, |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 1144 | {"setpgrp", posix_setpgrp}, |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1145 | {"wait", posix_wait}, |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 1146 | {"waitpid", posix_waitpid}, |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1147 | #endif |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 1148 | |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 1149 | #ifdef DO_PG |
| 1150 | {"setsid", posix_setsid}, |
| 1151 | {"setpgid", posix_setpgid}, |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 1152 | {"tcgetpgrp", posix_tcgetpgrp}, |
| 1153 | {"tcsetpgrp", posix_tcsetpgrp}, |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 1154 | #endif |
| 1155 | |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 1156 | {"open", posix_open}, |
| 1157 | {"close", posix_close}, |
| 1158 | {"dup", posix_dup}, |
| 1159 | {"dup2", posix_dup2}, |
| 1160 | {"lseek", posix_lseek}, |
| 1161 | {"read", posix_read}, |
| 1162 | {"write", posix_write}, |
| 1163 | {"fstat", posix_fstat}, |
| 1164 | {"fdopen", posix_fdopen}, |
| 1165 | #ifndef MSDOS |
| 1166 | {"pipe", posix_pipe}, |
| 1167 | #endif |
| 1168 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1169 | {NULL, NULL} /* Sentinel */ |
| 1170 | }; |
| 1171 | |
| 1172 | |
| 1173 | void |
| 1174 | initposix() |
| 1175 | { |
| 1176 | object *m, *d, *v; |
| 1177 | |
| 1178 | m = initmodule("posix", posix_methods); |
| 1179 | d = getmoduledict(m); |
| 1180 | |
| 1181 | /* Initialize posix.environ dictionary */ |
| 1182 | v = convertenviron(); |
| 1183 | if (v == NULL || dictinsert(d, "environ", v) != 0) |
| 1184 | fatal("can't define posix.environ"); |
| 1185 | DECREF(v); |
| 1186 | |
| 1187 | /* Initialize posix.error exception */ |
| 1188 | PosixError = newstringobject("posix.error"); |
| 1189 | if (PosixError == NULL || dictinsert(d, "error", PosixError) != 0) |
| 1190 | fatal("can't define posix.error"); |
| 1191 | } |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 1192 | |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 1193 | |
| 1194 | /* Function used elsewhere to get a file's modification time */ |
| 1195 | |
| 1196 | long |
| 1197 | getmtime(path) |
| 1198 | char *path; |
| 1199 | { |
| 1200 | struct stat st; |
| 1201 | if (stat(path, &st) != 0) |
| 1202 | return -1; |
| 1203 | else |
| 1204 | return st.st_mtime; |
| 1205 | } |
| 1206 | |
| 1207 | |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 1208 | #ifdef MSDOS |
| 1209 | |
| 1210 | /* A small "compatibility library" for TurboC under MS-DOS */ |
| 1211 | |
| 1212 | #include <sir.h> |
| 1213 | #include <io.h> |
| 1214 | #include <dos.h> |
| 1215 | #include <fcntl.h> |
| 1216 | |
| 1217 | int |
| 1218 | chmod(path, mode) |
| 1219 | char *path; |
| 1220 | int mode; |
| 1221 | { |
| 1222 | return _chmod(path, 1, mode); |
| 1223 | } |
| 1224 | |
| 1225 | int |
| 1226 | utime(path, times) |
| 1227 | char *path; |
| 1228 | time_t times[2]; |
| 1229 | { |
| 1230 | struct date dt; |
| 1231 | struct time tm; |
| 1232 | struct ftime dft; |
| 1233 | int fh; |
| 1234 | unixtodos(tv[0].tv_sec,&dt,&tm); |
| 1235 | dft.ft_tsec = tm.ti_sec; dft.ft_min = tm.ti_min; |
| 1236 | dft.ft_hour = tm.ti_hour; dft.ft_day = dt.da_day; |
| 1237 | dft.ft_month = dt.da_mon; |
| 1238 | dft.ft_year = (dt.da_year - 1980); /* this is for TC library */ |
| 1239 | |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 1240 | if ((fh = open(path,O_RDWR)) < 0) |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 1241 | return posix_error(); /* can't open file to set time */ |
| 1242 | if (setftime(fh,&dft) < 0) |
| 1243 | { |
| 1244 | close(fh); |
| 1245 | return posix_error(); |
| 1246 | } |
| 1247 | close(fh); /* close the temp handle */ |
| 1248 | } |
| 1249 | |
| 1250 | #endif /* MSDOS */ |