Skip to content

Commit dc34d34

Browse files
committed
Simplify the code base as this getpwd() was used only once
1 parent 0daf128 commit dc34d34

File tree

13 files changed

+30
-148
lines changed

13 files changed

+30
-148
lines changed

ext/standard/basic_functions.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4957,7 +4957,6 @@ PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers T
49574957

49584958
PHPAPI char *php_get_current_user()
49594959
{
4960-
struct passwd *pwd;
49614960
struct stat *pstat;
49624961
TSRMLS_FETCH();
49634962

@@ -4973,15 +4972,29 @@ PHPAPI char *php_get_current_user()
49734972

49744973
if (!pstat) {
49754974
return "";
4976-
}
4975+
} else {
4976+
#ifdef PHP_WIN32
4977+
char name[256];
4978+
DWORD len = sizeof(name)-1;
49774979

4978-
if ((pwd=getpwuid(pstat->st_uid))==NULL) {
4979-
return "";
4980+
if (!GetUserName(name, &len)) {
4981+
return "";
4982+
}
4983+
name[len] = '\0';
4984+
SG(request_info).current_user_length = len;
4985+
SG(request_info).current_user = estrndup(name, len);
4986+
return SG(request_info).current_user;
4987+
#else
4988+
struct passwd *pwd;
4989+
4990+
if ((pwd=getpwuid(pstat->st_uid))==NULL) {
4991+
return "";
4992+
}
4993+
SG(request_info).current_user_length = strlen(pwd->pw_name);
4994+
SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
4995+
return SG(request_info).current_user;
4996+
#endif
49804997
}
4981-
SG(request_info).current_user_length = strlen(pwd->pw_name);
4982-
SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
4983-
4984-
return SG(request_info).current_user;
49854998
}
49864999

49875000
/* {{{ proto array error_get_last() U

main/config.w32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
#define HAVE_ASSERT_H 1
157157
#define HAVE_FCNTL_H 1
158158
#define HAVE_GRP_H 0
159-
#define HAVE_PWD_H 1
159+
#undef HAVE_PWD_H
160160
#define HAVE_STRING_H 1
161161
#undef HAVE_SYS_FILE_H
162162
#undef HAVE_SYS_SOCKET_H

main/fopen_wrappers.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,8 @@
4545
#include "php_network.h"
4646

4747
#if HAVE_PWD_H
48-
#ifdef PHP_WIN32
49-
#include "win32/pwd.h"
50-
#else
5148
#include <pwd.h>
5249
#endif
53-
#endif
5450

5551
#include <sys/types.h>
5652
#if HAVE_SYS_SOCKET_H

main/php.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ char *strerror(int);
199199

200200
#if HAVE_PWD_H
201201
# ifdef PHP_WIN32
202-
#include "win32/pwd.h"
203202
#include "win32/param.h"
204203
# else
205204
#include <pwd.h>

win32/build/config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ ADD_SOURCES("main", "main.c snprintf.c spprintf.c fopen_wrappers.c \
281281
ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c plain_wrapper.c \
282282
userspace.c transports.c xp_socket.c mmap.c unicode_filter.c");
283283

284-
ADD_SOURCES("win32", "crypt_win32.c flock.c glob.c md5crypt.c pwd.c readdir.c \
284+
ADD_SOURCES("win32", "crypt_win32.c flock.c glob.c md5crypt.c readdir.c \
285285
registry.c select.c sendmail.c time.c wfile.c winutil.c wsyslog.c globals.c");
286286

287287
ADD_SOURCES("regex", "regcomp.c regerror.c regexec.c regfree.c");

win32/build/config.w32.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
#define HAVE_ASSERT_H 1
100100
#define HAVE_FCNTL_H 1
101101
#define HAVE_GRP_H 0
102-
#define HAVE_PWD_H 1
102+
#undef HAVE_PWD_H
103103
#define HAVE_STRING_H 1
104104
#undef HAVE_SYS_FILE_H
105105
#undef HAVE_SYS_SOCKET_H

win32/glob.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@
8181
#include <dirent.h>
8282
#include <pwd.h>
8383
#include <unistd.h>
84-
#else
85-
#include "win32/pwd.h"
8684
#endif
8785
#include <errno.h>
8886
#include "glob.h"
@@ -359,7 +357,9 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
359357
size_t patbuf_len;
360358
glob_t *pglob;
361359
{
360+
#ifndef PHP_WIN32
362361
struct passwd *pwd;
362+
#endif
363363
char *h;
364364
const Char *p;
365365
Char *b, *eb;
@@ -399,10 +399,14 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
399399
/*
400400
* Expand a ~user
401401
*/
402+
#ifndef PHP_WIN32
402403
if ((pwd = getpwnam((char*) patbuf)) == NULL)
403404
return pattern;
404405
else
405406
h = pwd->pw_dir;
407+
#else
408+
return pattern;
409+
#endif
406410
}
407411

408412
/* Copy the home directory */

win32/globals.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ PHP_RSHUTDOWN_FUNCTION(win32_core_globals)
4343
#endif
4444
;
4545

46-
STR_FREE(wg->login_name);
47-
4846
memset(wg, 0, sizeof(*wg));
4947
return SUCCESS;
5048
}

win32/php5dll.dsp

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

win32/php5dllts.dsp

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

win32/php_win32_globals.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
/* misc globals for thread-safety under win32 */
2525

26-
#include "pwd.h"
27-
2826
typedef struct _php_win32_core_globals php_win32_core_globals;
2927

3028
#ifdef ZTS
@@ -40,12 +38,6 @@ struct _php_win32_core_globals {
4038
char *log_header;
4139
HANDLE log_source;
4240

43-
/* getpwuid */
44-
struct passwd pwd;
45-
46-
/* getlogin */
47-
char *login_name;
48-
4941
/* time */
5042
struct timeval starttime;
5143
__int64 lasttime, freq;

win32/pwd.c

Lines changed: 0 additions & 66 deletions
This file was deleted.

win32/pwd.h

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)