diff options
author | Dmitry Stogov <dmitry@php.net> | 2006-11-10 09:56:16 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2006-11-10 09:56:16 +0000 |
commit | 9fd2b6deb43c276e8c5421c04a6be5eb85390ace (patch) | |
tree | 3624c51221582bee178812416c19047e97e23e21 /main/safe_mode.c | |
parent | 126be8ec7c13258a3361d2ebc2f3e609831213d2 (diff) | |
download | php-git-9fd2b6deb43c276e8c5421c04a6be5eb85390ace.tar.gz |
Simplify the code base as this getpwd() was used only once
Diffstat (limited to 'main/safe_mode.c')
-rw-r--r-- | main/safe_mode.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/main/safe_mode.c b/main/safe_mode.c index 3753e90ffb..e66b43f12d 100644 --- a/main/safe_mode.c +++ b/main/safe_mode.c @@ -197,7 +197,6 @@ PHPAPI int php_checkuid(const char *filename, const char *fopen_mode, int mode) PHPAPI char *php_get_current_user() { - struct passwd *pwd; struct stat *pstat; TSRMLS_FETCH(); @@ -213,15 +212,29 @@ PHPAPI char *php_get_current_user() if (!pstat) { return ""; - } + } else { +#ifdef PHP_WIN32 + char name[256]; + DWORD len = sizeof(name)-1; - if ((pwd=getpwuid(pstat->st_uid))==NULL) { - return ""; - } - SG(request_info).current_user_length = strlen(pwd->pw_name); - SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length); - - return SG(request_info).current_user; + if (!GetUserName(name, &len)) { + return ""; + } + name[len] = '\0'; + SG(request_info).current_user_length = len; + SG(request_info).current_user = estrndup(name, len); + return SG(request_info).current_user; +#else + struct passwd *pwd; + + if ((pwd=getpwuid(pstat->st_uid))==NULL) { + return ""; + } + SG(request_info).current_user_length = strlen(pwd->pw_name); + SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length); + return SG(request_info).current_user; +#endif + } } /* |