Commit e17dd934 authored by Guido van Rossum's avatar Guido van Rossum

Added uname. Made lstat/readlink/symlink unconditional (the latter

two raise posix.error if symlinks aren't supported).
parent 4e67c0ce
...@@ -31,6 +31,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -31,6 +31,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifdef MSDOS #ifdef MSDOS
#define NO_LSTAT #define NO_LSTAT
#define NO_UNAME
#endif #endif
#include <signal.h> #include <signal.h>
...@@ -385,6 +386,37 @@ posix_unlink(self, args) ...@@ -385,6 +386,37 @@ posix_unlink(self, args)
return posix_1str(args, unlink); return posix_1str(args, unlink);
} }
#ifndef NO_UNAME
#include <sys/utsname.h>
static object *
posix_uname(self, args)
object *self;
object *args;
{
extern int uname PROTO((struct utsname *));
struct utsname u;
object *v;
if (uname(&u) < 0)
return posix_error();
v = newtupleobject(5);
if (v == NULL)
return NULL;
#define SET(i, member) settupleitem(v, i, newstringobject(u.member))
SET(0, sysname);
SET(1, nodename);
SET(2, release);
SET(3, version);
SET(4, machine);
#undef SET
if (err_occurred()) {
DECREF(v);
return NULL;
}
return v;
}
#endif /* NO_UNAME */
#ifdef UTIME_STRUCT #ifdef UTIME_STRUCT
#include <utime.h> #include <utime.h>
#endif #endif
...@@ -574,7 +606,7 @@ posix_wait(self, args) /* Also waitpid() */ ...@@ -574,7 +606,7 @@ posix_wait(self, args) /* Also waitpid() */
pid = wait(&sts); pid = wait(&sts);
else { else {
#ifdef NO_WAITPID #ifdef NO_WAITPID
err_setstr(RuntimeError, err_setstr(PosixError,
"posix.wait(pid, options) not supported on this system"); "posix.wait(pid, options) not supported on this system");
#else #else
int options; int options;
...@@ -599,13 +631,14 @@ posix_wait(self, args) /* Also waitpid() */ ...@@ -599,13 +631,14 @@ posix_wait(self, args) /* Also waitpid() */
#endif /* MSDOS */ #endif /* MSDOS */
#ifndef NO_LSTAT
static object * static object *
posix_lstat(self, args) posix_lstat(self, args)
object *self; object *self;
object *args; object *args;
{ {
#ifdef NO_LSTAT
#define lstat stat
#endif
extern int lstat PROTO((const char *, struct stat *)); extern int lstat PROTO((const char *, struct stat *));
return posix_do_stat(self, args, lstat); return posix_do_stat(self, args, lstat);
} }
...@@ -615,6 +648,10 @@ posix_readlink(self, args) ...@@ -615,6 +648,10 @@ posix_readlink(self, args)
object *self; object *self;
object *args; object *args;
{ {
#ifdef NO_LSTAT
err_setstr(PosixError, "readlink not implemented on this system");
return NULL;
#else
char buf[1024]; /* XXX Should use MAXPATHLEN */ char buf[1024]; /* XXX Should use MAXPATHLEN */
char *path; char *path;
int n; int n;
...@@ -624,6 +661,7 @@ posix_readlink(self, args) ...@@ -624,6 +661,7 @@ posix_readlink(self, args)
if (n < 0) if (n < 0)
return posix_error(); return posix_error();
return newsizedstringobject(buf, n); return newsizedstringobject(buf, n);
#endif
} }
static object * static object *
...@@ -631,12 +669,15 @@ posix_symlink(self, args) ...@@ -631,12 +669,15 @@ posix_symlink(self, args)
object *self; object *self;
object *args; object *args;
{ {
#ifdef NO_LSTAT
err_setstr(PosixError, "symlink not implemented on this system");
return NULL;
#else
extern int symlink PROTO((const char *, const char *)); extern int symlink PROTO((const char *, const char *));
return posix_2str(args, symlink); return posix_2str(args, symlink);
#endif
} }
#endif /* NO_LSTAT */
static struct methodlist posix_methods[] = { static struct methodlist posix_methods[] = {
{"chdir", posix_chdir}, {"chdir", posix_chdir},
...@@ -646,16 +687,23 @@ static struct methodlist posix_methods[] = { ...@@ -646,16 +687,23 @@ static struct methodlist posix_methods[] = {
{"link", posix_link}, {"link", posix_link},
#endif #endif
{"listdir", posix_listdir}, {"listdir", posix_listdir},
{"lstat", posix_lstat},
{"mkdir", posix_mkdir}, {"mkdir", posix_mkdir},
{"readlink", posix_readlink},
{"rename", posix_rename}, {"rename", posix_rename},
{"rmdir", posix_rmdir}, {"rmdir", posix_rmdir},
{"stat", posix_stat}, {"stat", posix_stat},
{"symlink", posix_symlink},
{"system", posix_system}, {"system", posix_system},
#ifndef MSDOS #ifndef MSDOS
{"umask", posix_umask}, {"umask", posix_umask},
#endif
#ifndef NO_UNAME
{"uname", posix_uname},
#endif #endif
{"unlink", posix_unlink}, {"unlink", posix_unlink},
{"utime", posix_utime}, {"utime", posix_utime},
#ifndef MSDOS #ifndef MSDOS
{"_exit", posix__exit}, {"_exit", posix__exit},
{"exec", posix_exec}, {"exec", posix_exec},
...@@ -667,11 +715,7 @@ static struct methodlist posix_methods[] = { ...@@ -667,11 +715,7 @@ static struct methodlist posix_methods[] = {
{"popen", posix_popen}, {"popen", posix_popen},
{"wait", posix_wait}, {"wait", posix_wait},
#endif #endif
#ifndef NO_LSTAT
{"lstat", posix_lstat},
{"readlink", posix_readlink},
{"symlink", posix_symlink},
#endif
{NULL, NULL} /* Sentinel */ {NULL, NULL} /* Sentinel */
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment