41#ifndef PHP_WIN32_IOUTIL_H
42#define PHP_WIN32_IOUTIL_H
59# define PW32IO __declspec(dllexport)
61# define PW32IO __declspec(dllimport)
64#define PHP_WIN32_IOUTIL_MAXPATHLEN 2048
66#if !defined(MAXPATHLEN) || MAXPATHLEN < PHP_WIN32_IOUTIL_MAXPATHLEN
68# define MAXPATHLEN PHP_WIN32_IOUTIL_MAXPATHLEN
90#ifndef SYMLINK_FLAG_RELATIVE
91#define SYMLINK_FLAG_RELATIVE 0x01
113#define PHP_WIN32_IOUTIL_FW_SLASHW L'/'
114#define PHP_WIN32_IOUTIL_FW_SLASH '/'
115#define PHP_WIN32_IOUTIL_BW_SLASHW L'\\'
116#define PHP_WIN32_IOUTIL_BW_SLASH '\\'
117#define PHP_WIN32_IOUTIL_DEFAULT_SLASHW PHP_WIN32_IOUTIL_BW_SLASHW
118#define PHP_WIN32_IOUTIL_DEFAULT_SLASH PHP_WIN32_IOUTIL_BW_SLASH
120#define PHP_WIN32_IOUTIL_DEFAULT_DIR_SEPARATORW L';'
121#define PHP_WIN32_IOUTIL_IS_SLASHW(c) ((c) == PHP_WIN32_IOUTIL_BW_SLASHW || (c) == PHP_WIN32_IOUTIL_FW_SLASHW)
122#define PHP_WIN32_IOUTIL_IS_LETTERW(c) (((c) >= L'a' && (c) <= L'z') || ((c) >= L'A' && (c) <= L'Z'))
123#define PHP_WIN32_IOUTIL_JUNCTION_PREFIXW L"\\??\\"
124#define PHP_WIN32_IOUTIL_JUNCTION_PREFIX_LENW 4
125#define PHP_WIN32_IOUTIL_LONG_PATH_PREFIXW L"\\\\?\\"
126#define PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW 4
127#define PHP_WIN32_IOUTIL_UNC_PATH_PREFIXW L"\\\\?\\UNC\\"
128#define PHP_WIN32_IOUTIL_UNC_PATH_PREFIX_LENW 8
130#define PHP_WIN32_IOUTIL_IS_LONG_PATHW(pathw, path_lenw) (path_lenw >= PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW \
131 && 0 == wcsncmp((pathw), PHP_WIN32_IOUTIL_LONG_PATH_PREFIXW, PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW))
132#define PHP_WIN32_IOUTIL_IS_UNC_PATHW(pathw, path_lenw) (path_lenw >= PHP_WIN32_IOUTIL_UNC_PATH_PREFIX_LENW \
133 && 0 == wcsncmp((pathw), PHP_WIN32_IOUTIL_UNC_PATH_PREFIXW, PHP_WIN32_IOUTIL_UNC_PATH_PREFIX_LENW))
134#define PHP_WIN32_IOUTIL_IS_JUNCTION_PATHW(pathw, path_lenw) (path_lenw >= PHP_WIN32_IOUTIL_JUNCTION_PREFIX_LENW \
135 && 0 == wcsncmp((pathw), PHP_WIN32_IOUTIL_JUNCTION_PREFIXW, PHP_WIN32_IOUTIL_JUNCTION_PREFIX_LENW))
136#define PHP_WIN32_IOUTIL_IS_ABSOLUTEW(pathw, path_lenw) (PHP_WIN32_IOUTIL_IS_LONG_PATHW(pathw, path_lenw) \
137 || path_lenw >= 3 && PHP_WIN32_IOUTIL_IS_LETTERW(pathw[0]) && L':' == pathw[1] && PHP_WIN32_IOUTIL_IS_SLASHW(pathw[2]))
138#define PHP_WIN32_IOUTIL_IS_UNC(pathw, path_lenw) (path_lenw >= 2 && PHP_WIN32_IOUTIL_IS_SLASHW(pathw[0]) && PHP_WIN32_IOUTIL_IS_SLASHW(pathw[1]) \
139 || path_lenw >= PHP_WIN32_IOUTIL_UNC_PATH_PREFIX_LENW && 0 == wcsncmp((pathw), PHP_WIN32_IOUTIL_UNC_PATH_PREFIXW, PHP_WIN32_IOUTIL_UNC_PATH_PREFIX_LENW))
141#define PHP_WIN32_IOUTIL_DEFAULT_SHARE_MODE (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE)
143#define PHP_WIN32_IOUTIL_INIT_W(path) \
144 wchar_t *pathw = php_win32_ioutil_any_to_w(path); \
146#define PHP_WIN32_IOUTIL_CLEANUP_W() do { \
151#define PHP_WIN32_IOUTIL_REINIT_W(path) do { \
152 PHP_WIN32_IOUTIL_CLEANUP_W() \
153 pathw = php_win32_ioutil_any_to_w(path); \
156#define PHP_WIN32_IOUTIL_PATH_IS_OK_W(pathw, len) \
157 (!((len) >= 1 && L' ' == pathw[(len)-1] || \
158 (len) > 1 && !PHP_WIN32_IOUTIL_IS_SLASHW(pathw[(len)-2]) && L'.' != pathw[(len)-2] && L'.' == pathw[(len)-1]))
160#define PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, ret, dealloc) do { \
161 size_t _len = wcslen(pathw); \
162 if (!PHP_WIN32_IOUTIL_PATH_IS_OK_W(pathw, _len)) { \
164 free((void *)pathw); \
166 SET_ERRNO_FROM_WIN32_CODE(ERROR_ACCESS_DENIED); \
180__forceinline
static wchar_t *php_win32_ioutil_conv_any_to_w(
const char* in,
size_t in_len,
size_t *out_len)
185 mb = php_win32_cp_conv_any_to_w(in, in_len, &mb_len);
191 if (mb_len >= _MAX_PATH) {
206 if (new_mb_len > mb_len) {
207 wchar_t *tmp = (
wchar_t *) realloc(
ret, (new_mb_len + 1) *
sizeof(
wchar_t));
223 while (src < mb + mb_len) {
247#define php_win32_ioutil_any_to_w(in) php_win32_ioutil_conv_any_to_w(in, PHP_WIN32_CP_IGNORE_LEN, PHP_WIN32_CP_IGNORE_LEN_P)
249#define php_win32_ioutil_ascii_to_w php_win32_cp_ascii_to_w
250#define php_win32_ioutil_utf8_to_w php_win32_cp_utf8_to_w
251#define php_win32_ioutil_cur_to_w php_win32_cp_cur_to_w
252#define php_win32_ioutil_w_to_any php_win32_cp_w_to_any
253#define php_win32_ioutil_conv_w_to_any php_win32_cp_conv_w_to_any
258#define php_win32_ioutil_w_to_utf8 php_win32_cp_w_to_utf8
259#define php_win32_ioutil_w_to_thread php_win32_cp_w_to_thread
278__forceinline
static int php_win32_ioutil_access(
const char *path,
mode_t mode)
292 err = GetLastError();
303__forceinline
static int php_win32_ioutil_open(
const char *path,
int flags, ...)
327 err = GetLastError();
338__forceinline
static int php_win32_ioutil_unlink(
const char *path)
351 err = GetLastError();
362__forceinline
static int php_win32_ioutil_rmdir(
const char *path)
375 if (!RemoveDirectoryW(pathw)) {
376 err = GetLastError();
389__forceinline
static FILE *php_win32_ioutil_fopen(
const char *patha,
const char *modea)
392 wchar_t modew[16] = {0};
404 modew[i] = (wchar_t)modea[i];
410 int err = GetLastError();
421__forceinline static
int php_win32_ioutil_rename(const
char *oldnamea, const
char *newnamea)
441 size_t newnamew_len = wcslen(newnamew);
452 err = GetLastError();
465__forceinline
static int php_win32_ioutil_chdir(
const char *patha)
478 err = GetLastError();
490__forceinline
static char *php_win32_ioutil_getcwd(
char *
buf,
size_t len)
493 char *tmp_bufa =
NULL;
498 err = GetLastError();
503 tmp_bufa = php_win32_cp_conv_w_to_any(tmp_bufw, wcslen(tmp_bufw), &tmp_bufa_len);
505 err = GetLastError();
512 }
else if (tmp_bufa_len + 1 >
len) {
530__forceinline
static int php_win32_ioutil_chmod(
const char *patha,
int mode)
557__forceinline
static int php_win32_ioutil_mkdir(
const char *path,
mode_t mode)
570 err = GetLastError();
582__forceinline
static int php_win32_ioutil_symlink(
const char *target,
const char *
link)
584 wchar_t *targetw, *linkw;
608__forceinline
static int php_win32_ioutil_link(
const char *target,
const char *
link)
610 wchar_t *targetw, *linkw;
635__forceinline
static char *php_win32_ioutil_realpath_ex0(
const char *path,
char *resolved, PBY_HANDLE_FILE_INFORMATION info)
664 resolved = (
char *) malloc(reta_len + 1);
672 memmove(resolved, reta, reta_len+1);
680__forceinline static
char *php_win32_ioutil_realpath(const
char *path,
char *resolved)
682 return php_win32_ioutil_realpath_ex0(path, resolved,
NULL);
727 } SymbolicLinkReparseBuffer;
729 unsigned short SubstituteNameOffset;
730 unsigned short SubstituteNameLength;
731 unsigned short PrintNameOffset;
732 unsigned short PrintNameLength;
733 wchar_t ReparseTarget[1];
734 } MountPointReparseBuffer;
737 } GenericReparseBuffer;
761#define php_win32_ioutil_stat(path, buf) php_win32_ioutil_stat_ex(path, buf, 0)
762#define php_win32_ioutil_lstat(path, buf) php_win32_ioutil_stat_ex(path, buf, 1)
766__forceinline
static ssize_t php_win32_ioutil_readlink(
const char *path,
char *
buf,
size_t buf_len)
768 size_t pathw_len, ret_buf_len;
781 DWORD _err = GetLastError();
788 if (!ret_buf || ret_buf_len >= buf_len || ret_buf_len >=
MAXPATHLEN) {
sizeof(Countable|array $value, int $mode=COUNT_NORMAL)
link(string $target, string $link)
#define PHP_WIN32_CP_IGNORE_LEN_P
#define PHP_WIN32_CP_IGNORE_LEN
zend_ffi_ctype_name_buf buf
foreach($dp as $el) foreach( $dp as $el) if( $pass2< 2) echo ""
BOOL php_win32_ioutil_init(void)
PW32IO int php_win32_ioutil_access_w(const wchar_t *path, mode_t mode)
#define PHP_WIN32_IOUTIL_FW_SLASHW
PW32IO int php_win32_ioutil_link_w(const wchar_t *target, const wchar_t *link)
__time32_t php_win32_ioutil_time_t
#define PHP_WIN32_IOUTIL_IS_JUNCTION_PATHW(pathw, path_lenw)
PW32IO ssize_t php_win32_ioutil_readlink_w(const wchar_t *path, wchar_t *buf, size_t buf_len)
PW32IO int php_win32_ioutil_symlink_w(const wchar_t *target, const wchar_t *link)
PW32IO int php_win32_ioutil_open_w(const wchar_t *path, int flags,...)
PW32IO php_win32_ioutil_normalization_result php_win32_ioutil_normalize_path_w(wchar_t **buf, size_t len, size_t *new_len)
__int32 php_win32_ioutil_size_t
#define PHP_WIN32_IOUTIL_PATH_IS_OK_W(pathw, len)
PW32IO int php_win32_ioutil_access_w(const wchar_t *path, mode_t mode)
#define PHP_WIN32_IOUTIL_IS_UNC_PATHW(pathw, path_lenw)
PW32IO size_t php_win32_ioutil_dirname(char *buf, size_t len)
PW32IO int php_win32_ioutil_mkdir_w(const wchar_t *path, mode_t mode)
PW32IO int php_win32_ioutil_close(int fd)
PW32IO char * realpath(const char *path, char *resolved)
php_win32_ioutil_encoding
@ PHP_WIN32_IOUTIL_IS_UTF8
@ PHP_WIN32_IOUTIL_IS_ANSI
@ PHP_WIN32_IOUTIL_IS_ASCII
#define PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, ret, dealloc)
PW32IO wchar_t * php_win32_ioutil_realpath_w_ex0(const wchar_t *path, wchar_t *resolved, PBY_HANDLE_FILE_INFORMATION info)
PW32IO int php_win32_ioutil_rename_w(const wchar_t *oldname, const wchar_t *newname)
PW32IO int php_win32_ioutil_stat_ex_w(const wchar_t *path, size_t path_len, php_win32_ioutil_stat_t *buf, int lstat)
#define PHP_WIN32_IOUTIL_INIT_W(path)
#define PHP_WIN32_IOUTIL_IS_LONG_PATHW(pathw, path_lenw)
PW32IO wchar_t * php_win32_ioutil_getcwd_w(wchar_t *buf, size_t len)
PW32IO int php_win32_ioutil_fstat(int fd, php_win32_ioutil_stat_t *buf)
PW32IO wchar_t * php_win32_ioutil_realpath_w(const wchar_t *path, wchar_t *resolved)
#define PHP_WIN32_IOUTIL_DEFAULT_SLASHW
unsigned __int32 php_win32_ioutil_ino_t
php_win32_ioutil_normalization_result
@ PHP_WIN32_IOUTIL_NORM_PARTIAL
@ PHP_WIN32_IOUTIL_NORM_OK
@ PHP_WIN32_IOUTIL_NORM_FAIL
#define PHP_WIN32_IOUTIL_CLEANUP_W()
PW32IO int php_win32_ioutil_unlink_w(const wchar_t *path)
PW32IO int php_win32_ioutil_chdir_w(const wchar_t *path)
#define php_win32_ioutil_any_to_w(in)
unsigned __int32 php_win32_ioutil_dev_t
#define PHP_WIN32_IOUTIL_LONG_PATH_PREFIXW
#define PHP_WIN32_IOUTIL_MAXPATHLEN
struct PHP_WIN32_IOUTIL_REPARSE_DATA_BUFFER * PHP_WIN32_IOUTIL_PREPARSE_DATA_BUFFER
#define PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW
PW32IO BOOL php_win32_ioutil_posix_to_open_opts(int flags, mode_t mode, php_ioutil_open_opts *opts)
#define php_win32_ioutil_conv_w_to_any
PW32IO FILE * php_win32_ioutil_fopen_w(const wchar_t *path, const wchar_t *mode)
unsigned short SubstituteNameOffset
unsigned short SubstituteNameLength
unsigned short PrintNameLength
unsigned short PrintNameOffset
unsigned short ReparseDataLength
php_win32_ioutil_dev_t st_rdev
php_win32_ioutil_time_t st_atime
php_win32_ioutil_dev_t st_dev
unsigned __int32 st_nlink
php_win32_ioutil_time_t st_ctime
php_win32_ioutil_size_t st_size
php_win32_ioutil_ino_t st_ino
php_win32_ioutil_time_t st_mtime
#define SET_ERRNO_FROM_WIN32_CODE(err)