From: Gurusamy Sarathy Date: Wed, 24 Mar 1999 01:08:33 +0000 (+0000) Subject: support POSIX::uname() via win32_uname() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b2af26b13be5ac143d7c7e58ef2458b8b3103485;p=p5sagit%2Fp5-mst-13.2.git support POSIX::uname() via win32_uname() p4raw-id: //depot/perl@3134 --- diff --git a/XSUB.h b/XSUB.h index ad465a0..f847886 100644 --- a/XSUB.h +++ b/XSUB.h @@ -203,6 +203,7 @@ # 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() diff --git a/iperlsys.h b/iperlsys.h index 67ef90a..03e3c08 100644 --- a/iperlsys.h +++ b/iperlsys.h @@ -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 */ diff --git a/win32/GenCAPI.pl b/win32/GenCAPI.pl index af71291..77e7aad 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 fa1daf9..691dfbb 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 e270d49..39b7701 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 082b4c1..cf4799b 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 7437cf6..9a87054 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 ddb8524..271a6f5 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 4a8a097..aab6935 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 ce1009b..0a753fb 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 e514bf1..cc5b5e5 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 4d7721e..a43d108 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 0b8b710..a072b87 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 c7a7444..a0649b1 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