Skip to content

Commit

Permalink
Added uname. Made lstat/readlink/symlink unconditional (the latter
Browse files Browse the repository at this point in the history
two raise posix.error if symlinks aren't supported).
  • Loading branch information
gvanrossum committed Feb 5, 1992
1 parent 3c8ba7a commit c39de5f
Showing 1 changed file with 54 additions and 10 deletions.
64 changes: 54 additions & 10 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#ifdef MSDOS
#define NO_LSTAT
#define NO_UNAME
#endif

#include <signal.h>
Expand Down Expand Up @@ -385,6 +386,37 @@ posix_unlink(self, args)
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
#include <utime.h>
#endif
Expand Down Expand Up @@ -574,7 +606,7 @@ posix_wait(self, args) /* Also waitpid() */
pid = wait(&sts);
else {
#ifdef NO_WAITPID
err_setstr(RuntimeError,
err_setstr(PosixError,
"posix.wait(pid, options) not supported on this system");
#else
int options;
Expand All @@ -599,13 +631,14 @@ posix_wait(self, args) /* Also waitpid() */

#endif /* MSDOS */

#ifndef NO_LSTAT

static object *
posix_lstat(self, args)
object *self;
object *args;
{
#ifdef NO_LSTAT
#define lstat stat
#endif
extern int lstat PROTO((const char *, struct stat *));
return posix_do_stat(self, args, lstat);
}
Expand All @@ -615,6 +648,10 @@ posix_readlink(self, args)
object *self;
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 *path;
int n;
Expand All @@ -624,19 +661,23 @@ posix_readlink(self, args)
if (n < 0)
return posix_error();
return newsizedstringobject(buf, n);
#endif
}

static object *
posix_symlink(self, args)
object *self;
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 *));
return posix_2str(args, symlink);
#endif
}

#endif /* NO_LSTAT */


static struct methodlist posix_methods[] = {
{"chdir", posix_chdir},
Expand All @@ -646,16 +687,23 @@ static struct methodlist posix_methods[] = {
{"link", posix_link},
#endif
{"listdir", posix_listdir},
{"lstat", posix_lstat},
{"mkdir", posix_mkdir},
{"readlink", posix_readlink},
{"rename", posix_rename},
{"rmdir", posix_rmdir},
{"stat", posix_stat},
{"symlink", posix_symlink},
{"system", posix_system},
#ifndef MSDOS
{"umask", posix_umask},
#endif
#ifndef NO_UNAME
{"uname", posix_uname},
#endif
{"unlink", posix_unlink},
{"utime", posix_utime},

#ifndef MSDOS
{"_exit", posix__exit},
{"exec", posix_exec},
Expand All @@ -667,11 +715,7 @@ static struct methodlist posix_methods[] = {
{"popen", posix_popen},
{"wait", posix_wait},
#endif
#ifndef NO_LSTAT
{"lstat", posix_lstat},
{"readlink", posix_readlink},
{"symlink", posix_symlink},
#endif

{NULL, NULL} /* Sentinel */
};

Expand Down

0 comments on commit c39de5f

Please sign in to comment.