~clint-fewbar/ubuntu/precise/php5/php5-5.4-merge

« back to all changes in this revision

Viewing changes to ext/standard/link_win32.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-02-22 09:46:37 UTC
  • mfrom: (1.1.20) (0.3.18 sid)
  • Revision ID: package-import@ubuntu.com-20110222094637-nlu2tvb7oqgaarl0
Tags: 5.3.5-1ubuntu1
* Merge from debian/unstable. Remaining changes:
 - debian/control:
    * Dropped firebird2.1-dev, libc-client-dev, libmcrypt-dev as it is in universe.
    * Dropped libmysqlclient15-dev, build against mysql 5.1.
    * Dropped libcurl-dev not in the archive.
    * Suggest php5-suhosin rather than recommends.
    * Dropped php5-imap, php5-interbase, php5-mcrypt since we have versions 
      already in universe.
    * Dropped libonig-dev and libqgdbm since its in universe. (will be re-added in lucid+1)
    * Dropped locales-all.
  - modulelist: Drop imap, interbase, sybase, and mcrypt.
  - debian/rules:
    * Dropped building of mcrypt, imap, and interbase.
    * Install apport hook for php5.
    * stop mysql instance on clean just in case we failed in tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
   +----------------------------------------------------------------------+
17
17
 */
18
18
 
19
 
/* $Id: link_win32.c 293036 2010-01-03 09:23:27Z sebastian $ */
 
19
/* $Id: link_win32.c 303500 2010-09-18 14:54:40Z pajoye $ */
20
20
#ifdef PHP_WIN32
21
21
 
22
22
#include "php.h"
45
45
 
46
46
/*
47
47
TODO:
48
 
- Create php_readlink, php_link and php_symlink in win32/link.c
 
48
- Create php_readlink (done), php_link and php_symlink in win32/link.c
49
49
- Expose them (PHPAPI) so extensions developers can use them
50
50
- define link/readlink/symlink to their php_ equivalent and use them in ext/standart/link.c
51
51
- this file is then useless and we have a portable link API
52
52
*/
53
53
 
54
 
#ifndef VOLUME_NAME_NT
55
 
#define VOLUME_NAME_NT 0x2
56
 
#endif
57
 
 
58
 
#ifndef VOLUME_NAME_DOS
59
 
#define VOLUME_NAME_DOS 0x0
60
 
#endif
61
 
 
62
54
/* {{{ proto string readlink(string filename)
63
55
   Return the target of a symbolic link */
64
56
PHP_FUNCTION(readlink)
65
57
{
66
 
        HINSTANCE kernel32;
67
58
        char *link;
68
59
        int link_len;
69
 
        TCHAR Path[MAXPATHLEN];
70
 
        char path_resolved[MAXPATHLEN];
71
 
        HANDLE hFile;
72
 
        DWORD dwRet;
73
 
 
74
 
        typedef BOOL (WINAPI *gfpnh_func)(HANDLE, LPTSTR, DWORD, DWORD);
75
 
        gfpnh_func pGetFinalPathNameByHandle;
76
 
 
77
 
        kernel32 = LoadLibrary("kernel32.dll");
78
 
 
79
 
        if (kernel32) {
80
 
                pGetFinalPathNameByHandle = (gfpnh_func)GetProcAddress(kernel32, "GetFinalPathNameByHandleA");
81
 
                if (pGetFinalPathNameByHandle == NULL) {
82
 
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't call GetFinalPathNameByHandleA");
83
 
                        RETURN_FALSE;
84
 
                }
85
 
        } else {
86
 
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't call get a handle on kernel32.dll");
87
 
                RETURN_FALSE;
88
 
        }
 
60
        char target[MAXPATHLEN];
89
61
 
90
62
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &link, &link_len) == FAILURE) {
91
63
                return;
94
66
        if (OPENBASEDIR_CHECKPATH(link)) {
95
67
                RETURN_FALSE;
96
68
        }
97
 
        if (!expand_filepath(link, path_resolved TSRMLS_CC)) {
98
 
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory");
99
 
                RETURN_FALSE;
100
 
        }
101
 
        hFile = CreateFile(path_resolved,                  // file to open
102
 
                                 GENERIC_READ,          // open for reading
103
 
                                 FILE_SHARE_READ,       // share for reading
104
 
                                 NULL,                  // default security
105
 
                                 OPEN_EXISTING,         // existing file only
106
 
                                 FILE_FLAG_BACKUP_SEMANTICS, // normal file
107
 
                                 NULL);                 // no attr. template
108
 
 
109
 
        if( hFile == INVALID_HANDLE_VALUE) {
110
 
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not open file (error %d)", GetLastError());
111
 
                        RETURN_FALSE;
112
 
        }
113
 
 
114
 
        dwRet = pGetFinalPathNameByHandle(hFile, Path, MAXPATHLEN, VOLUME_NAME_DOS);
115
 
        if(dwRet >= MAXPATHLEN) {
116
 
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't resolve the full path, the path exceeds the MAX_PATH_LEN (%d) limit", MAXPATHLEN);
117
 
                RETURN_FALSE;
118
 
        }
119
 
 
120
 
        CloseHandle(hFile);
121
 
 
122
 
        /* Append NULL to the end of the string */
123
 
        Path[dwRet] = '\0';
124
 
 
125
 
        if(dwRet > 4) {
126
 
                /* Skip first 4 characters if they are "\??\" */
127
 
                if(Path[0] == '\\' && Path[1] == '\\' && Path[2] == '?' && Path[3] ==  '\\') {
128
 
                        RETURN_STRING(Path + 4, 1);
129
 
                }
130
 
        } else {
131
 
                RETURN_STRING(Path, 1);
132
 
        }
 
69
 
 
70
        if (php_sys_readlink(link, target, MAXPATHLEN) == -1) {
 
71
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "readlink failed to read the symbolic link (%s), error %d)", link, GetLastError());
 
72
        }
 
73
        RETURN_STRING(target, 1);
133
74
}
134
75
/* }}} */
135
76