support POSIX::uname() via win32_uname()
Gurusamy Sarathy [Wed, 24 Mar 1999 01:08:33 +0000 (01:08 +0000)]
p4raw-id: //depot/perl@3134

14 files changed:
XSUB.h
iperlsys.h
win32/GenCAPI.pl
win32/config.bc
win32/config.gc
win32/config.vc
win32/config_H.bc
win32/config_H.gc
win32/config_H.vc
win32/makedef.pl
win32/perlhost.h
win32/win32.c
win32/win32.h
win32/win32iop.h

diff --git a/XSUB.h b/XSUB.h
index ad465a0..f847886 100644 (file)
--- a/XSUB.h
+++ b/XSUB.h
 #    define telldir            PerlDir_tell
 #    define putenv             PerlEnv_putenv
 #    define getenv             PerlEnv_getenv
+#    define uname              PerlEnv_uname
 #    define stdin              PerlIO_stdin()
 #    define stdout             PerlIO_stdout()
 #    define stderr             PerlIO_stderr()
index 67ef90a..03e3c08 100644 (file)
@@ -450,10 +450,12 @@ public:
     virtual int                Putenv(const char *envstring, int &err) = 0;
     virtual char *     LibPath(char *patchlevel) =0;
     virtual char *     SiteLibPath(char *patchlevel) =0;
+    virtual int                Uname(struct utsname *name, int &err) =0;
 };
 
 #define PerlEnv_putenv(str)            PL_piENV->Putenv((str), ErrorNo())
 #define PerlEnv_getenv(str)            PL_piENV->Getenv((str), ErrorNo())
+#define PerlEnv_uname(name)            PL_piENV->Uname((name), ErrorNo())
 #ifdef WIN32
 #define PerlEnv_lib_path(str)          PL_piENV->LibPath((str))
 #define PerlEnv_sitelib_path(str)      PL_piENV->SiteLibPath((str))
@@ -463,6 +465,7 @@ public:
 
 #define PerlEnv_putenv(str)            putenv((str))
 #define PerlEnv_getenv(str)            getenv((str))
+#define PerlEnv_uname(name)            uname((name))
 
 #endif /* PERL_OBJECT */
 
index af71291..77e7aad 100644 (file)
@@ -990,6 +990,11 @@ int          _win32_utime(const char *f, struct utimbuf *t)
     return pPerl->PL_piLIO->Utime((char*)f, t, ErrorNo());
 }
 
+int          _win32_uname(struct utsname *name)
+{
+    return pPerl->PL_piENV->Uname(name, ErrorNo());
+}
+
 char*   _win32_getenv(const char *name)
 {
     return pPerl->PL_piENV->Getenv(name, ErrorNo());
index fa1daf9..691dfbb 100644 (file)
@@ -339,7 +339,7 @@ d_truncate='undef'
 d_truncate64='undef'
 d_tzname='define'
 d_umask='define'
-d_uname='undef'
+d_uname='define'
 d_union_semun='define'
 d_vfork='undef'
 d_void_closedir='undef'
index e270d49..39b7701 100644 (file)
@@ -339,7 +339,7 @@ d_truncate='undef'
 d_truncate64='undef'
 d_tzname='undef'
 d_umask='define'
-d_uname='undef'
+d_uname='define'
 d_union_semun='define'
 d_vfork='undef'
 d_void_closedir='undef'
index 082b4c1..cf4799b 100644 (file)
@@ -339,7 +339,7 @@ d_truncate='undef'
 d_truncate64='undef'
 d_tzname='define'
 d_umask='define'
-d_uname='undef'
+d_uname='define'
 d_union_semun='define'
 d_vfork='undef'
 d_void_closedir='undef'
index 7437cf6..9a87054 100644 (file)
  *     even if used by a process with super-user privileges.
  */
 #define HAS_GETHOSTNAME        /**/
-/*#define HAS_UNAME            /**/
+#define HAS_UNAME              /**/
 /*#define PHOSTNAME "" / * How to get the host name */
 
 /* HAS_GETLOGIN:
index ddb8524..271a6f5 100644 (file)
  *     even if used by a process with super-user privileges.
  */
 #define HAS_GETHOSTNAME        /**/
-/*#define HAS_UNAME            /**/
+#define HAS_UNAME              /**/
 /*#define PHOSTNAME "" / * How to get the host name */
 
 /* HAS_GETLOGIN:
index 4a8a097..aab6935 100644 (file)
  *     even if used by a process with super-user privileges.
  */
 #define HAS_GETHOSTNAME        /**/
-/*#define HAS_UNAME            /**/
+#define HAS_UNAME              /**/
 /*#define PHOSTNAME "" / * How to get the host name */
 
 /* HAS_GETLOGIN:
index ce1009b..0a753fb 100644 (file)
@@ -451,6 +451,7 @@ win32_open_osfhandle
 win32_get_osfhandle
 win32_ioctl
 win32_utime
+win32_uname
 win32_wait
 win32_waitpid
 win32_kill
index e514bf1..cc5b5e5 100644 (file)
@@ -98,6 +98,10 @@ public:
     {
        return g_win32_get_sitelib(pl);
     };
+    virtual int Uname(struct utsname *name, int &err)
+    {
+       return win32_uname(name);
+    };
 };
 
 class CPerlSock : public IPerlSock
index 4d7721e..a43d108 100644 (file)
@@ -1133,6 +1133,91 @@ win32_utime(const char *filename, struct utimbuf *times)
 }
 
 DllExport int
+win32_uname(struct utsname *name)
+{
+    struct hostent *hep;
+    STRLEN nodemax = sizeof(name->nodename)-1;
+    OSVERSIONINFO osver;
+
+    memset(&osver, 0, sizeof(OSVERSIONINFO));
+    osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+    if (GetVersionEx(&osver)) {
+       /* sysname */
+       switch (osver.dwPlatformId) {
+       case VER_PLATFORM_WIN32_WINDOWS:
+           strcpy(name->sysname, "Windows");
+           break;
+       case VER_PLATFORM_WIN32_NT:
+           strcpy(name->sysname, "Windows NT");
+           break;
+       case VER_PLATFORM_WIN32s:
+           strcpy(name->sysname, "Win32s");
+           break;
+       default:
+           strcpy(name->sysname, "Win32 Unknown");
+           break;
+       }
+
+       /* version */
+       sprintf(name->version, "%d.%d",
+               osver.dwMajorVersion, osver.dwMinorVersion);
+
+       /* release */
+       sprintf(name->release, "Build %d",
+               osver.dwPlatformId == VER_PLATFORM_WIN32_NT
+               ? osver.dwBuildNumber : (osver.dwBuildNumber & 0xffff));
+       if (osver.szCSDVersion[0]) {
+           char *buf = name->release + strlen(name->release);
+           sprintf(buf, " (%s)", osver.szCSDVersion);
+       }
+    }
+    else {
+       *name->sysname = '\0';
+       *name->version = '\0';
+       *name->release = '\0';
+    }
+
+    /* nodename */
+    hep = win32_gethostbyname("localhost");
+    if (hep) {
+       STRLEN len = strlen(hep->h_name);
+       if (len <= nodemax) {
+           strcpy(name->nodename, hep->h_name);
+       }
+       else {
+           strncpy(name->nodename, hep->h_name, nodemax);
+           name->nodename[nodemax] = '\0';
+       }
+    }
+    else {
+       DWORD sz = nodemax;
+       if (!GetComputerName(name->nodename, &sz))
+           *name->nodename = '\0';
+    }
+
+    /* machine (architecture) */
+    {
+       SYSTEM_INFO info;
+       char *arch;
+       GetSystemInfo(&info);
+       switch (info.wProcessorArchitecture) {
+       case PROCESSOR_ARCHITECTURE_INTEL:
+           arch = "x86"; break;
+       case PROCESSOR_ARCHITECTURE_MIPS:
+           arch = "mips"; break;
+       case PROCESSOR_ARCHITECTURE_ALPHA:
+           arch = "alpha"; break;
+       case PROCESSOR_ARCHITECTURE_PPC:
+           arch = "ppc"; break;
+       default:
+           arch = "unknown"; break;
+       }
+       strcpy(name->machine, arch);
+    }
+    return 0;
+}
+
+DllExport int
 win32_waitpid(int pid, int *status, int flags)
 {
     int retval = -1;
index 0b8b710..a072b87 100644 (file)
@@ -83,6 +83,18 @@ struct tms {
        long    tms_cstime;
 };
 
+#ifndef SYS_NMLN
+#define SYS_NMLN       257
+#endif
+
+struct utsname {
+    char sysname[SYS_NMLN];
+    char nodename[SYS_NMLN];
+    char release[SYS_NMLN];
+    char version[SYS_NMLN];
+    char machine[SYS_NMLN];
+};
+
 #ifndef START_EXTERN_C
 #undef EXTERN_C
 #ifdef __cplusplus
index c7a7444..a0649b1 100644 (file)
@@ -124,6 +124,7 @@ DllExport  unsigned         win32_alarm(unsigned int sec);
 DllExport  int         win32_stat(const char *path, struct stat *buf);
 DllExport  int         win32_ioctl(int i, unsigned int u, char *data);
 DllExport  int         win32_utime(const char *f, struct utimbuf *t);
+DllExport  int         win32_uname(struct utsname *n);
 DllExport  int         win32_wait(int *status);
 DllExport  int         win32_waitpid(int pid, int *status, int flags);
 DllExport  int         win32_kill(int pid, int sig);
@@ -153,6 +154,7 @@ END_EXTERN_C
 #undef alarm
 #undef ioctl
 #undef utime
+#undef uname
 #undef wait
 
 #ifdef __BORLANDC__
@@ -261,6 +263,7 @@ END_EXTERN_C
 #define alarm                  win32_alarm
 #define ioctl                  win32_ioctl
 #define utime                  win32_utime
+#define uname                  win32_uname
 #define wait                   win32_wait
 #define waitpid                        win32_waitpid
 #define kill                   win32_kill