For Programmers: Free Programming Magazines  


Home > Archive > PHP Zend Engine > November 2006 > cvs: TSRM(PHP_5_2) / tsrm_virtual_cwd.c tsrm_virtual_cwd.h php-src NEWS









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cvs: TSRM(PHP_5_2) / tsrm_virtual_cwd.c tsrm_virtual_cwd.h php-src NEWS
Dmitry Stogov

2006-11-10, 6:55 pm

dmitry Fri Nov 10 15:04:07 2006 UTC

Modified files: (Branch: PHP_5_2)
/php-src NEWS
/TSRM tsrm_virtual_cwd.c tsrm_virtual_cwd.h
Log:
stat() is reimplemented using using GetFileAttributesEx().
The new implementation is faster then implementation in MS VC CRT, but it doesn't support Windows 95.


http://cvs.php.net/viewvc.cgi/php-s...4&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.353 php-src/NEWS:1.2027.2.547.2.354
--- php-src/NEWS:1.2027.2.547.2.353 Fri Nov 10 13:18:35 2006
+++ php-src/NEWS Fri Nov 10 15:04:07 2006
@@ -9,6 +9,9 @@
In case of modification of corresponding registry-tree PHP will reload
it automatic
. start timiout thread only if necessary
+ . stat() is reimplemented using using GetFileAttributesEx().
+ The new implementation is faster then implementation in MS VC CRT, but
+ it doesn't support Windows 95.
- Streams optimization (Dmitry)
. removed unnecessary ftell() calls (one call for each included PHP file)
. disabled calls to read() after EOF
http://cvs.php.net/viewvc.cgi/TSRM/...1&diff_format=u
Index: TSRM/tsrm_virtual_cwd.c
diff -u TSRM/tsrm_virtual_cwd.c:1.74.2.9.2.10 TSRM/tsrm_virtual_cwd.c:1.74.2.9.2.11
--- TSRM/tsrm_virtual_cwd.c:1.74.2.9.2.10 Fri Nov 10 12:59:27 2006
+++ TSRM/tsrm_virtual_cwd.c Fri Nov 10 15:04:07 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/

-/* $Id: tsrm_virtual_cwd.c,v 1.74.2.9.2.10 2006/11/10 12:59:27 dmitry Exp $ */
+/* $Id: tsrm_virtual_cwd.c,v 1.74.2.9.2.11 2006/11/10 15:04:07 dmitry Exp $ */

#include <sys/types.h>
#include <sys/stat.h>
@@ -140,11 +140,93 @@
#define CWD_STATE_FREE(s) \
free((s)->cwd);

+#ifdef TSRM_WIN32
+CWD_API int php_sys_stat(const char *path, struct stat *buf)
+{
+ WIN32_FILE_ATTRIBUTE_DATA data;
+ __int64 t;
+
+ if (!GetFileAttributesEx(path, GetFileExInfoStandard, &data)) {
+ return stat(path, buf);
+ }
+
+ if (path[1] == ':') {
+ if (path[0] >= 'A' && path[0] <= 'Z') {
+ buf->st_dev = buf->st_rdev = path[0] - 'A';
+ } else {
+ buf->st_dev = buf->st_rdev = path[0] - 'a';
+ }
+ } else {
+ char cur_path[MAXPATHLEN+1];
+ DWORD len = sizeof(cur_path);
+ char *tmp = cur_path;
+
+ while(1) {
+ DWORD r = GetCurrentDirectory(len, tmp);
+ if (r < len) {
+ if (tmp[1] == ':') {
+ if (path[0] >= 'A' && path[0] <= 'Z') {
+ buf->st_dev = buf->st_rdev = path[0] - 'A';
+ } else {
+ buf->st_dev = buf->st_rdev = path[0] - 'a';
+ }
+ } else {
+ buf->st_dev = buf->st_rdev = -1;
+ }
+ break;
+ } else if (!r) {
+ buf->st_dev = buf->st_rdev = -1;
+ break;
+ } else {
+ len = r+1;
+ tmp = (char*)malloc(len);
+ }
+ }
+ if (tmp != cur_path) {
+ free(tmp);
+ }
+ }
+ buf->st_uid = buf->st_gid = buf->st_ino = 0;
+ buf->st_mode = (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? (S_IFDIR|S_IEXEC|(S_IEXEC>>3)|(S_IEXEC>>6)) : S_IFREG;
+ buf->st_mode |= (data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)) : (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)|S_IWRITE|(S_IWRITE>>3)|(S_IWRITE>>6));
+ if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
+ int len = strlen(path);
+
+ if (path[len-4] == '.') {
+ if (_memicmp(path+len-3, "exe", 3) == 0 ||
+ _memicmp(path+len-3, "com", 3) == 0 ||
+ _memicmp(path+len-3, "bat", 3) == 0 ||
+ _memicmp(path+len-3, "cmd", 3) == 0) {
+ buf->st_mode |= (S_IEXEC|(S_IEXEC>>3)|(S_IEXEC>>6));
+ }
+ }
+ }
+ buf->st_nlink = 1;
+ t = data.nFileSizeHigh;
+ t = t << 32;
+ t |= data.nFileSizeLow;
+ buf->st_size = t;
+ t = data.ftLastAccessTime.dwHighDateTime;
+ t = t << 32;
+ t |= data.ftLastAccessTime.dwLowDateTime;
+ buf->st_atime = (unsigned long)((t / 10000000) - 11644473600);
+ t = data.ftCreationTime.dwHighDateTime;
+ t = t << 32;
+ t |= data.ftCreationTime.dwLowDateTime;
+ buf->st_ctime = (unsigned long)((t / 10000000) - 11644473600);
+ t = data.ftLastWriteTime.dwHighDateTime;
+ t = t << 32;
+ t |= data.ftLastWriteTime.dwLowDateTime;
+ buf->st_mtime = (unsigned long)((t / 10000000) - 11644473600);
+ return 0;
+}
+#endif
+
static int php_is_dir_ok(const cwd_state *state)
{
struct stat buf;

- if (stat(state->cwd, &buf) == 0 && S_ISDIR(buf.st_mode))
+ if (php_sys_stat(state->cwd, &buf) == 0 && S_ISDIR(buf.st_mode))
return (0);

return (1);
@@ -154,7 +236,7 @@
{
struct stat buf;

- if (stat(state->cwd, &buf) == 0 && S_ISREG(buf.st_mode))
+ if (php_sys_stat(state->cwd, &buf) == 0 && S_ISREG(buf.st_mode))
return (0);

return (1);
@@ -838,7 +920,7 @@
return -1;
}

- retval = stat(new_state.cwd, buf);
+ retval = php_sys_stat(new_state.cwd, buf);

CWD_STATE_FREE(&new_state);
return retval;
http://cvs.php.net/viewvc.cgi/TSRM/...4&diff_format=u
Index: TSRM/tsrm_virtual_cwd.h
diff -u TSRM/tsrm_virtual_cwd.h:1.48.2.5.2.3 TSRM/tsrm_virtual_cwd.h:1.48.2.5.2.4
--- TSRM/tsrm_virtual_cwd.h:1.48.2.5.2.3 Fri Nov 10 12:59:27 2006
+++ TSRM/tsrm_virtual_cwd.h Fri Nov 10 15:04:07 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/

-/* $Id: tsrm_virtual_cwd.h,v 1.48.2.5.2.3 2006/11/10 12:59:27 dmitry Exp $ */
+/* $Id: tsrm_virtual_cwd.h,v 1.48.2.5.2.4 2006/11/10 15:04:07 dmitry Exp $ */

#ifndef VIRTUAL_CWD_H
#define VIRTUAL_CWD_H
@@ -126,6 +126,12 @@
#define CWD_API
#endif

+#ifdef TSRM_WIN32
+CWD_API int php_sys_stat(const char *path, struct stat *buf);
+#else
+# define php_sys_stat stat
+#endif
+
typedef struct _cwd_state {
char *cwd;
int cwd_length;
@@ -263,7 +269,7 @@
#define VCWD_CHDIR(path) chdir(path)
#define VCWD_CHDIR_FILE(path) virtual_chdir_file(path, chdir)
#define VCWD_GETWD(buf) getwd(buf)
-#define VCWD_STAT(path, buff) stat(path, buff)
+#define VCWD_STAT(path, buff) php_sys_stat(path, buff)
#define VCWD_LSTAT(path, buff) lstat(path, buff)
#define VCWD_UNLINK(path) unlink(path)
#define VCWD_MKDIR(pathname, mode) mkdir(pathname, mode)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com