Skip to content

Commit c39de5f

Browse files
committed
Added uname. Made lstat/readlink/symlink unconditional (the latter
two raise posix.error if symlinks aren't supported).
1 parent 3c8ba7a commit c39de5f

1 file changed

Lines changed: 54 additions & 10 deletions

File tree

Modules/posixmodule.c

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3131

3232
#ifdef MSDOS
3333
#define NO_LSTAT
34+
#define NO_UNAME
3435
#endif
3536

3637
#include <signal.h>
@@ -385,6 +386,37 @@ posix_unlink(self, args)
385386
return posix_1str(args, unlink);
386387
}
387388

389+
#ifndef NO_UNAME
390+
#include <sys/utsname.h>
391+
392+
static object *
393+
posix_uname(self, args)
394+
object *self;
395+
object *args;
396+
{
397+
extern int uname PROTO((struct utsname *));
398+
struct utsname u;
399+
object *v;
400+
if (uname(&u) < 0)
401+
return posix_error();
402+
v = newtupleobject(5);
403+
if (v == NULL)
404+
return NULL;
405+
#define SET(i, member) settupleitem(v, i, newstringobject(u.member))
406+
SET(0, sysname);
407+
SET(1, nodename);
408+
SET(2, release);
409+
SET(3, version);
410+
SET(4, machine);
411+
#undef SET
412+
if (err_occurred()) {
413+
DECREF(v);
414+
return NULL;
415+
}
416+
return v;
417+
}
418+
#endif /* NO_UNAME */
419+
388420
#ifdef UTIME_STRUCT
389421
#include <utime.h>
390422
#endif
@@ -574,7 +606,7 @@ posix_wait(self, args) /* Also waitpid() */
574606
pid = wait(&sts);
575607
else {
576608
#ifdef NO_WAITPID
577-
err_setstr(RuntimeError,
609+
err_setstr(PosixError,
578610
"posix.wait(pid, options) not supported on this system");
579611
#else
580612
int options;
@@ -599,13 +631,14 @@ posix_wait(self, args) /* Also waitpid() */
599631

600632
#endif /* MSDOS */
601633

602-
#ifndef NO_LSTAT
603-
604634
static object *
605635
posix_lstat(self, args)
606636
object *self;
607637
object *args;
608638
{
639+
#ifdef NO_LSTAT
640+
#define lstat stat
641+
#endif
609642
extern int lstat PROTO((const char *, struct stat *));
610643
return posix_do_stat(self, args, lstat);
611644
}
@@ -615,6 +648,10 @@ posix_readlink(self, args)
615648
object *self;
616649
object *args;
617650
{
651+
#ifdef NO_LSTAT
652+
err_setstr(PosixError, "readlink not implemented on this system");
653+
return NULL;
654+
#else
618655
char buf[1024]; /* XXX Should use MAXPATHLEN */
619656
char *path;
620657
int n;
@@ -624,19 +661,23 @@ posix_readlink(self, args)
624661
if (n < 0)
625662
return posix_error();
626663
return newsizedstringobject(buf, n);
664+
#endif
627665
}
628666

629667
static object *
630668
posix_symlink(self, args)
631669
object *self;
632670
object *args;
633671
{
672+
#ifdef NO_LSTAT
673+
err_setstr(PosixError, "symlink not implemented on this system");
674+
return NULL;
675+
#else
634676
extern int symlink PROTO((const char *, const char *));
635677
return posix_2str(args, symlink);
678+
#endif
636679
}
637680

638-
#endif /* NO_LSTAT */
639-
640681

641682
static struct methodlist posix_methods[] = {
642683
{"chdir", posix_chdir},
@@ -646,16 +687,23 @@ static struct methodlist posix_methods[] = {
646687
{"link", posix_link},
647688
#endif
648689
{"listdir", posix_listdir},
690+
{"lstat", posix_lstat},
649691
{"mkdir", posix_mkdir},
692+
{"readlink", posix_readlink},
650693
{"rename", posix_rename},
651694
{"rmdir", posix_rmdir},
652695
{"stat", posix_stat},
696+
{"symlink", posix_symlink},
653697
{"system", posix_system},
654698
#ifndef MSDOS
655699
{"umask", posix_umask},
700+
#endif
701+
#ifndef NO_UNAME
702+
{"uname", posix_uname},
656703
#endif
657704
{"unlink", posix_unlink},
658705
{"utime", posix_utime},
706+
659707
#ifndef MSDOS
660708
{"_exit", posix__exit},
661709
{"exec", posix_exec},
@@ -667,11 +715,7 @@ static struct methodlist posix_methods[] = {
667715
{"popen", posix_popen},
668716
{"wait", posix_wait},
669717
#endif
670-
#ifndef NO_LSTAT
671-
{"lstat", posix_lstat},
672-
{"readlink", posix_readlink},
673-
{"symlink", posix_symlink},
674-
#endif
718+
675719
{NULL, NULL} /* Sentinel */
676720
};
677721

0 commit comments

Comments
 (0)