From: Gurusamy Sarathy Date: Wed, 24 Dec 1997 03:10:55 +0000 (+0000) Subject: [win32] support getlogin() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e34ffe5a86599b66240875a414d90fdf19ed7649;p=p5sagit%2Fp5-mst-13.2.git [win32] support getlogin() p4raw-id: //depot/win32/perl@386 --- diff --git a/README.win32 b/README.win32 index 3fac64b..940c498 100644 --- a/README.win32 +++ b/README.win32 @@ -503,9 +503,9 @@ The following functions are currently unavailable: C, C, C, C, C, C, C and related security functions, C, C, C, C, C, -C, C, C, C, C, -C, C, C, C<*netent()>, C<*protoent()>, -C<*servent()>, C<*hostent()>, C. +C, C, C, C, C, C, +C, C<*netent()>, C<*protoent()>, C<*servent()>, +C<*hostent()>, C. This list is possibly incomplete. =item * diff --git a/win32/config.bc b/win32/config.bc index c534021..97cee6a 100644 --- a/win32/config.bc +++ b/win32/config.bc @@ -131,7 +131,7 @@ d_getgrps='undef' d_setgrps='undef' d_gethent='undef' d_gethname='undef' -d_getlogin='undef' +d_getlogin='define' d_getpgrp2='undef' d_getpgrp='undef' d_getpgid='undef' diff --git a/win32/config.gc b/win32/config.gc index c9b0b2a..3c9acbe 100644 --- a/win32/config.gc +++ b/win32/config.gc @@ -131,7 +131,7 @@ d_getgrps='undef' d_setgrps='undef' d_gethent='undef' d_gethname='undef' -d_getlogin='undef' +d_getlogin='define' d_getpgrp2='undef' d_getpgrp='undef' d_getpgid='undef' diff --git a/win32/config.vc b/win32/config.vc index 3e7f9aa..0957322 100644 --- a/win32/config.vc +++ b/win32/config.vc @@ -131,7 +131,7 @@ d_getgrps='undef' d_setgrps='undef' d_gethent='undef' d_gethname='undef' -d_getlogin='undef' +d_getlogin='define' d_getpgrp2='undef' d_getpgrp='undef' d_getpgid='undef' diff --git a/win32/config_H.bc b/win32/config_H.bc index cea8b4e..846d81d 100644 --- a/win32/config_H.bc +++ b/win32/config_H.bc @@ -352,7 +352,7 @@ * This symbol, if defined, indicates that the getlogin routine is * available to get the login name. */ -/*#define HAS_GETLOGIN /**/ +#define HAS_GETLOGIN /**/ /* HAS_GETPGRP2: * This symbol, if defined, indicates that the getpgrp2() (as in DG/UX) diff --git a/win32/config_H.gc b/win32/config_H.gc index 012d2e0..35737e7 100644 --- a/win32/config_H.gc +++ b/win32/config_H.gc @@ -352,7 +352,7 @@ * This symbol, if defined, indicates that the getlogin routine is * available to get the login name. */ -/*#define HAS_GETLOGIN /**/ +#define HAS_GETLOGIN /**/ /* HAS_GETPGRP2: * This symbol, if defined, indicates that the getpgrp2() (as in DG/UX) diff --git a/win32/config_H.vc b/win32/config_H.vc index 87ecab8..72caabb 100644 --- a/win32/config_H.vc +++ b/win32/config_H.vc @@ -352,7 +352,7 @@ * This symbol, if defined, indicates that the getlogin routine is * available to get the login name. */ -/*#define HAS_GETLOGIN /**/ +#define HAS_GETLOGIN /**/ /* HAS_GETPGRP2: * This symbol, if defined, indicates that the getpgrp2() (as in DG/UX) diff --git a/win32/win32.c b/win32/win32.c index 1de1bb8..bdfb3e2 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -58,15 +58,18 @@ HANDLE PerlDllHandle = INVALID_HANDLE_VALUE; #ifdef USE_THREADS # ifdef USE_DECLSPEC_THREAD __declspec(thread) char strerror_buffer[512]; +__declspec(thread) char getlogin_buffer[128]; # ifdef HAVE_DES_FCRYPT __declspec(thread) char crypt_buffer[30]; # endif # else # define strerror_buffer (thr->i.Wstrerror_buffer) +# define getlogin_buffer (thr->i.Wgetlogin_buffer) # define crypt_buffer (thr->i.Wcrypt_buffer) # endif #else char strerror_buffer[512]; +char getlogin_buffer[128]; # ifdef HAVE_DES_FCRYPT char crypt_buffer[30]; # endif @@ -573,6 +576,17 @@ setgid(gid_t agid) return (agid == ROOT_GID ? 0 : -1); } +char * +getlogin(void) +{ + dTHR; + char *buf = getlogin_buffer; + DWORD size = sizeof(getlogin_buffer); + if (GetUserName(buf,&size)) + return buf; + return (char*)NULL; +} + /* * pretended kill */ @@ -1524,8 +1538,8 @@ static XS(w32_LoginName) { dXSARGS; - char name[256]; - DWORD size = sizeof(name); + char *name = getlogin_buffer; + DWORD size = sizeof(getlogin_buffer); if (GetUserName(name,&size)) { /* size includes NULL */ ST(0) = sv_2mortal(newSVpv(name,size-1)); diff --git a/win32/win32.h b/win32/win32.h index 7534ec5..1b1f64a 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -149,6 +149,7 @@ extern int setuid(uid_t uid); extern int setgid(gid_t gid); extern int kill(int pid, int sig); extern void *sbrk(int need); +extern char * getlogin(void); #undef Stat #define Stat win32_stat @@ -205,18 +206,19 @@ EXT void win32_strip_return(struct sv *sv); */ #ifdef USE_THREADS -#ifndef USE_DECLSPEC_THREAD -#define HAVE_THREAD_INTERN - -struct thread_intern -{ - char Wstrerror_buffer[512]; - struct servent Wservent; -#ifdef HAVE_DES_FCRYPT - char Wcrypt_buffer[30]; -#endif +# ifndef USE_DECLSPEC_THREAD +# define HAVE_THREAD_INTERN + +struct thread_intern { + /* XXX can probably use one buffer instead of several */ + char Wstrerror_buffer[512]; + struct servent Wservent; + char Wgetlogin_buffer[128]; +# ifdef HAVE_DES_FCRYPT + char Wcrypt_buffer[30]; +# endif }; -#endif -#endif +# endif /* !USE_DECLSPEC_THREAD */ +#endif /* USE_THREADS */ #endif /* _INC_WIN32_PERL5 */