summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1999-03-24 01:08:33 +0000
committerGurusamy Sarathy <gsar@cpan.org>1999-03-24 01:08:33 +0000
commitb2af26b13be5ac143d7c7e58ef2458b8b3103485 (patch)
tree708be0a38074ec2b410629956a8f04ed5b58c2a9 /win32
parent8fe0a5c4e04be608dcf92965347231ca4e6d5db7 (diff)
downloadperl-b2af26b13be5ac143d7c7e58ef2458b8b3103485.tar.gz
support POSIX::uname() via win32_uname()
p4raw-id: //depot/perl@3134
Diffstat (limited to 'win32')
-rw-r--r--win32/GenCAPI.pl5
-rw-r--r--win32/config.bc2
-rw-r--r--win32/config.gc2
-rw-r--r--win32/config.vc2
-rw-r--r--win32/config_H.bc2
-rw-r--r--win32/config_H.gc2
-rw-r--r--win32/config_H.vc2
-rw-r--r--win32/makedef.pl1
-rw-r--r--win32/perlhost.h4
-rw-r--r--win32/win32.c85
-rw-r--r--win32/win32.h12
-rw-r--r--win32/win32iop.h3
12 files changed, 116 insertions, 6 deletions
diff --git a/win32/GenCAPI.pl b/win32/GenCAPI.pl
index af71291830..77e7aad8b8 100644
--- a/win32/GenCAPI.pl
+++ b/win32/GenCAPI.pl
@@ -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());
diff --git a/win32/config.bc b/win32/config.bc
index fa1daf9e8b..691dfbbcd4 100644
--- a/win32/config.bc
+++ b/win32/config.bc
@@ -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'
diff --git a/win32/config.gc b/win32/config.gc
index e270d49820..39b77015ae 100644
--- a/win32/config.gc
+++ b/win32/config.gc
@@ -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'
diff --git a/win32/config.vc b/win32/config.vc
index 082b4c1db4..cf4799baa4 100644
--- a/win32/config.vc
+++ b/win32/config.vc
@@ -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'
diff --git a/win32/config_H.bc b/win32/config_H.bc
index 7437cf6b92..9a87054207 100644
--- a/win32/config_H.bc
+++ b/win32/config_H.bc
@@ -242,7 +242,7 @@
* 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:
diff --git a/win32/config_H.gc b/win32/config_H.gc
index ddb8524fad..271a6f51ff 100644
--- a/win32/config_H.gc
+++ b/win32/config_H.gc
@@ -242,7 +242,7 @@
* 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:
diff --git a/win32/config_H.vc b/win32/config_H.vc
index 4a8a097512..aab6935aca 100644
--- a/win32/config_H.vc
+++ b/win32/config_H.vc
@@ -242,7 +242,7 @@
* 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:
diff --git a/win32/makedef.pl b/win32/makedef.pl
index ce1009ba78..0a753fbfe1 100644
--- a/win32/makedef.pl
+++ b/win32/makedef.pl
@@ -451,6 +451,7 @@ win32_open_osfhandle
win32_get_osfhandle
win32_ioctl
win32_utime
+win32_uname
win32_wait
win32_waitpid
win32_kill
diff --git a/win32/perlhost.h b/win32/perlhost.h
index e514bf1342..cc5b5e5cd4 100644
--- a/win32/perlhost.h
+++ b/win32/perlhost.h
@@ -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
diff --git a/win32/win32.c b/win32/win32.c
index 4d7721edc6..a43d10882c 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -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;
diff --git a/win32/win32.h b/win32/win32.h
index 0b8b710616..a072b875c9 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -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
diff --git a/win32/win32iop.h b/win32/win32iop.h
index c7a74444e0..a0649b1623 100644
--- a/win32/win32iop.h
+++ b/win32/win32iop.h
@@ -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