#include <tchar.h>
#define tsrm_strtok_r(a,b,c) _tcstok((a),(b))
#define TOKENIZER_STRING "/\\"
-
-static int php_check_dots(const char *element, int n)
+
+static int php_check_dots(const char *element, int n)
{
while (n-- > 0) if (element[n] != '.') break;
return (n != -1);
}
-
+
#define IS_DIRECTORY_UP(element, len) \
(len >= 2 && !php_check_dots(element, len))
/* define this to check semantics */
#define IS_DIR_OK(s) (1)
-
+
#ifndef IS_DIR_OK
#define IS_DIR_OK(state) (php_is_dir_ok(state) == 0)
#endif
#define CWD_STATE_FREE(s) \
free((s)->cwd);
-
+
#ifdef TSRM_WIN32
#ifdef CTL_CODE
}
}
#else
- result = getcwd(cwd, sizeof(cwd));
+ result = getcwd(cwd, sizeof(cwd));
#endif
if (!result) {
cwd[0] = '\0';
*length = 1;
retval = (char *) malloc(2);
retval[0] = DEFAULT_SLASH;
- retval[1] = '\0';
+ retval[1] = '\0';
return retval;
}
{
long size = sizeof(realpath_cache_bucket) + path_len + 1;
int same = 1;
-
+
if (realpath_len != path_len ||
memcmp(path, realpath, path_len) != 0) {
size += realpath_len + 1;
}
/* }}} */
-CWD_API int realpath_cache_size(TSRMLS_D)
+CWD_API int realpath_cache_size(TSRMLS_D)
{
return CWDG(realpath_cache_size);
}
-CWD_API int realpath_cache_max_buckets(TSRMLS_D)
+CWD_API int realpath_cache_max_buckets(TSRMLS_D)
{
return (sizeof(CWDG(realpath_cache)) / sizeof(CWDG(realpath_cache)[0]));
}
-CWD_API realpath_cache_bucket** realpath_cache_get_buckets(TSRMLS_D)
+CWD_API realpath_cache_bucket** realpath_cache_get_buckets(TSRMLS_D)
{
return CWDG(realpath_cache);
}
path[4] = '.';
path[5] = DEFAULT_SLASH;
j = 5;
- } else if (j > 0 &&
+ } else if (j > 0 &&
path[j+1] == '.' && path[j+2] == '.' &&
IS_SLASH(path[j+3])) {
j += 4;
}
return j;
}
-
+
path[len] = 0;
save = (use_realpath != CWD_EXPAND);
/* continue resolution anyway but don't save result in the cache */
save = 0;
}
-
+
if (save) {
FindClose(hFind);
}
reparsetarget = pbuffer->SymbolicLinkReparseBuffer.ReparseTarget;
printname_len = pbuffer->MountPointReparseBuffer.PrintNameLength / sizeof(WCHAR);
isabsolute = (pbuffer->SymbolicLinkReparseBuffer.Flags == 0) ? 1 : 0;
- if (!WideCharToMultiByte(CP_THREAD_ACP, 0,
+ if (!WideCharToMultiByte(CP_THREAD_ACP, 0,
reparsetarget + pbuffer->MountPointReparseBuffer.PrintNameOffset / sizeof(WCHAR),
printname_len + 1,
printname, MAX_PATH, NULL, NULL
printname[printname_len] = 0;
substitutename_len = pbuffer->MountPointReparseBuffer.SubstituteNameLength / sizeof(WCHAR);
- if (!WideCharToMultiByte(CP_THREAD_ACP, 0,
+ if (!WideCharToMultiByte(CP_THREAD_ACP, 0,
reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR),
substitutename_len + 1,
substitutename, MAX_PATH, NULL, NULL
isabsolute = 1;
reparsetarget = pbuffer->MountPointReparseBuffer.ReparseTarget;
printname_len = pbuffer->MountPointReparseBuffer.PrintNameLength / sizeof(WCHAR);
- if (!WideCharToMultiByte(CP_THREAD_ACP, 0,
+ if (!WideCharToMultiByte(CP_THREAD_ACP, 0,
reparsetarget + pbuffer->MountPointReparseBuffer.PrintNameOffset / sizeof(WCHAR),
printname_len + 1,
printname, MAX_PATH, NULL, NULL
printname[pbuffer->MountPointReparseBuffer.PrintNameLength / sizeof(WCHAR)] = 0;
substitutename_len = pbuffer->MountPointReparseBuffer.SubstituteNameLength / sizeof(WCHAR);
- if (!WideCharToMultiByte(CP_THREAD_ACP, 0,
+ if (!WideCharToMultiByte(CP_THREAD_ACP, 0,
reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR),
substitutename_len + 1,
substitutename, MAX_PATH, NULL, NULL
}
if(isabsolute && substitutename_len > 4) {
- /* Do not resolve volumes (for now). A mounted point can
+ /* Do not resolve volumes (for now). A mounted point can
target a volume without a drive, it is not certain that
- all IO functions we use in php and its deps support
+ all IO functions we use in php and its deps support
path with volume GUID instead of the DOS way, like:
d:\test\mnt\foo
\\?\Volume{62d1c3f8-83b9-11de-b108-806e6f6e6963}\foo
*/
- if (strncmp(substitutename, "\\??\\Volume{",11) == 0
+ if (strncmp(substitutename, "\\??\\Volume{",11) == 0
|| strncmp(substitutename, "\\\\?\\Volume{",11) == 0
|| strncmp(substitutename, "\\??\\UNC\\", 8) == 0
) {
substitutename_off = 0;
} else
/* do not use the \??\ and \\?\ prefix*/
- if (strncmp(substitutename, "\\??\\", 4) == 0
+ if (strncmp(substitutename, "\\??\\", 4) == 0
|| strncmp(substitutename, "\\\\?\\", 4) == 0) {
substitutename_off = 4;
}
memcpy(tmp, path, len+1);
if (save && S_ISLNK(st.st_mode)) {
- if (++(*ll) > LINK_MAX || (j = readlink(tmp, path, MAXPATHLEN)) < 0) {
+ if (++(*ll) > LINK_MAX || (j = php_sys_readlink(tmp, path, MAXPATHLEN)) < 0) {
/* too many links or broken symlinks */
tsrm_free_alloca(tmp, use_heap);
return -1;
state_cwd_length = 2;
while (IS_SLASH(state->cwd[state_cwd_length])) {
state_cwd_length++;
- }
+ }
while (state->cwd[state_cwd_length] &&
!IS_SLASH(state->cwd[state_cwd_length])) {
state_cwd_length++;
- }
+ }
while (IS_SLASH(state->cwd[state_cwd_length])) {
state_cwd_length++;
- }
+ }
while (state->cwd[state_cwd_length] &&
!IS_SLASH(state->cwd[state_cwd_length])) {
state_cwd_length++;
- }
+ }
}
}
#endif
memcpy(resolved_path + state_cwd_length + 1, path, path_length + 1);
path_length += state_cwd_length + 1;
}
- } else {
+ } else {
#ifdef TSRM_WIN32
if (path_length > 2 && path[1] == ':' && !IS_SLASH(path[2])) {
resolved_path[0] = path[0];
} else
#endif
memcpy(resolved_path, path, path_length + 1);
- }
+ }
#ifdef TSRM_WIN32
if (memchr(resolved_path, '*', path_length) ||
add_slash = (use_realpath != CWD_REALPATH) && path_length > 0 && IS_SLASH(resolved_path[path_length-1]);
t = CWDG(realpath_cache_ttl) ? 0 : -1;
path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL TSRMLS_CC);
-
+
if (path_length < 0) {
errno = ENOENT;
return 1;
}
-
+
if (!start && !path_length) {
resolved_path[path_length++] = '.';
}
memcpy(state->cwd, resolved_path, state->cwd_length+1);
ret = 0;
}
-
+
#if VIRTUAL_CWD_DEBUG
fprintf (stderr, "virtual_file_ex() = %s\n",state->cwd);
#endif
if (!*path) {
new_state.cwd = (char*)malloc(1);
new_state.cwd[0] = '\0';
- new_state.cwd_length = 0;
+ new_state.cwd_length = 0;
if (VCWD_GETCWD(cwd, MAXPATHLEN)) {
path = cwd;
}
} else {
new_state.cwd = (char*)malloc(1);
new_state.cwd[0] = '\0';
- new_state.cwd_length = 0;
+ new_state.cwd_length = 0;
}
if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)==0) {
{
cwd_state new_state;
int ret;
-
+
CWD_STATE_COPY(&new_state, &CWDG(cwd));
if (virtual_file_ex(&new_state, pathname, NULL, CWD_REALPATH)) {
CWD_STATE_FREE(&new_state);
#else
ret = access(new_state.cwd, mode);
#endif
-
+
CWD_STATE_FREE(&new_state);
-
+
return ret;
}
/* }}} */
TSRM_API int win32_utime(const char *filename, struct utimbuf *buf) /* {{{ */
{
FILETIME mtime, atime;
- HANDLE hFile;
+ HANDLE hFile;
hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL,
OPEN_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL);
- /* OPEN_ALWAYS mode sets the last error to ERROR_ALREADY_EXISTS but
+ /* OPEN_ALWAYS mode sets the last error to ERROR_ALREADY_EXISTS but
the CreateFile operation succeeds */
if (GetLastError() == ERROR_ALREADY_EXISTS) {
SetLastError(0);
f = open(new_state.cwd, flags, mode);
} else {
f = open(new_state.cwd, flags);
- }
+ }
CWD_STATE_FREE(&new_state);
return f;
}
}
*ptr++ = '\'';
}
-
+
*ptr++ = ' ';
*ptr++ = ';';
*ptr++ = ' ';
if (!*path) {
new_state.cwd = (char*)malloc(1);
new_state.cwd[0] = '\0';
- new_state.cwd_length = 0;
+ new_state.cwd_length = 0;
if (VCWD_GETCWD(cwd, MAXPATHLEN)) {
path = cwd;
}
} else {
new_state.cwd = (char*)malloc(1);
new_state.cwd[0] = '\0';
- new_state.cwd_length = 0;
+ new_state.cwd_length = 0;
}
if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)) {