php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
ioutil.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Anatol Belski <ab@php.net> |
14 +----------------------------------------------------------------------+
15*/
16
17/* This file integrates several modified parts from the libuv project, which
18 * is copyrighted to
19 *
20 * Copyright Joyent, Inc. and other Node contributors. All rights reserved.
21 *
22 * Permission is hereby granted, free of charge, to any person obtaining a copy
23 * of this software and associated documentation files (the "Software"), to
24 * deal in the Software without restriction, including without limitation the
25 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
26 * sell copies of the Software, and to permit persons to whom the Software is
27 * furnished to do so, subject to the following conditions:
28 *
29 * The above copyright notice and this permission notice shall be included in
30 * all copies or substantial portions of the Software.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
37 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
38 * IN THE SOFTWARE.
39 */
40
41#ifndef PHP_WIN32_IOUTIL_H
42#define PHP_WIN32_IOUTIL_H
43
44#include <fcntl.h>
45#include <sys/types.h>
46#include <sys/stat.h>
47#include <io.h>
48#include <stdio.h>
49#include <stdlib.h>
50
51#include "win32/winutil.h"
52#include "win32/codepage.h"
53
54#ifdef __cplusplus
55extern "C" {
56#endif
57
58#ifdef PHP_EXPORTS
59# define PW32IO __declspec(dllexport)
60#else
61# define PW32IO __declspec(dllimport)
62#endif
63
64#define PHP_WIN32_IOUTIL_MAXPATHLEN 2048
65
66#if !defined(MAXPATHLEN) || MAXPATHLEN < PHP_WIN32_IOUTIL_MAXPATHLEN
67# undef MAXPATHLEN
68# define MAXPATHLEN PHP_WIN32_IOUTIL_MAXPATHLEN
69#endif
70
71#ifndef mode_t
72typedef unsigned short mode_t;
73#endif
74
75/* these are not defined in win32 headers */
76#ifndef W_OK
77#define W_OK 0x02
78#endif
79#ifndef R_OK
80#define R_OK 0x04
81#endif
82#ifndef X_OK
83#define X_OK 0x01
84#endif
85#ifndef F_OK
86#define F_OK 0x00
87#endif
88
89/* from ntifs.h */
90#ifndef SYMLINK_FLAG_RELATIVE
91#define SYMLINK_FLAG_RELATIVE 0x01
92#endif
93
100
106
112
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
119
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
129
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))
140
141#define PHP_WIN32_IOUTIL_DEFAULT_SHARE_MODE (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE)
142
143#define PHP_WIN32_IOUTIL_INIT_W(path) \
144 wchar_t *pathw = php_win32_ioutil_any_to_w(path); \
145
146#define PHP_WIN32_IOUTIL_CLEANUP_W() do { \
147 free(pathw); \
148 pathw = NULL; \
149} while (0);
150
151#define PHP_WIN32_IOUTIL_REINIT_W(path) do { \
152 PHP_WIN32_IOUTIL_CLEANUP_W() \
153 pathw = php_win32_ioutil_any_to_w(path); \
154} while (0);
155
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]))
159
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)) { \
163 if (dealloc) { \
164 free((void *)pathw); \
165 } \
166 SET_ERRNO_FROM_WIN32_CODE(ERROR_ACCESS_DENIED); \
167 return ret; \
168 } \
169} while (0);
170
172#ifdef PHP_EXPORTS
173/* This symbols are needed only for the DllMain, but should not be exported
174 or be available when used with PHP binaries. */
176#endif
177
178/* Keep these functions aliased for case some additional handling
179 is needed later. */
180__forceinline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in, size_t in_len, size_t *out_len)
181{/*{{{*/
182 wchar_t *mb, *ret;
183 size_t mb_len;
184
185 mb = php_win32_cp_conv_any_to_w(in, in_len, &mb_len);
186 if (!mb) {
187 return NULL;
188 }
189
190 /* Only prefix with long if it's needed. */
191 if (mb_len >= _MAX_PATH) {
192 size_t new_mb_len;
193
194 ret = (wchar_t *) malloc((mb_len + PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW + 1) * sizeof(wchar_t));
195 if (!ret) {
196 free(mb);
197 return NULL;
198 }
199
200 if (PHP_WIN32_IOUTIL_NORM_FAIL == php_win32_ioutil_normalize_path_w(&mb, mb_len, &new_mb_len)) {
201 free(ret);
202 free(mb);
203 return NULL;
204 }
205
206 if (new_mb_len > mb_len) {
207 wchar_t *tmp = (wchar_t *) realloc(ret, (new_mb_len + 1) * sizeof(wchar_t));
208 if (!tmp) {
209 free(ret);
210 free(mb);
211 return NULL;
212 }
213 ret = tmp;
214 mb_len = new_mb_len;
215 }
216
218 memmove(ret, mb, mb_len * sizeof(wchar_t));
219 ret[mb_len] = L'\0';
220 } else {
221 wchar_t *src = mb, *dst = ret + PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW;
223 while (src < mb + mb_len) {
224 if (*src == PHP_WIN32_IOUTIL_FW_SLASHW) {
226 src++;
227 } else {
228 *dst++ = *src++;
229 }
230 }
232
234 }
235
236 free(mb);
237 } else {
238 ret = mb;
239 }
240
241 if (PHP_WIN32_CP_IGNORE_LEN_P != out_len) {
242 *out_len = mb_len;
243 }
244
245 return ret;
246}/*}}}*/
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)
248
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
254/*__forceinline static char *php_win32_ioutil_w_to_any(wchar_t* w_source_ptr)
255{
256 return php_win32_cp_w_to_any(w_source_ptr);
257}*/
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
260
263PW32IO size_t php_win32_ioutil_dirname(char *buf, size_t len);
264
265PW32IO int php_win32_ioutil_open_w(const wchar_t *path, int flags, ...);
266PW32IO int php_win32_ioutil_chdir_w(const wchar_t *path);
267PW32IO int php_win32_ioutil_rename_w(const wchar_t *oldname, const wchar_t *newname);
268PW32IO wchar_t *php_win32_ioutil_getcwd_w(wchar_t *buf, size_t len);
269PW32IO int php_win32_ioutil_unlink_w(const wchar_t *path);
270PW32IO int php_win32_ioutil_access_w(const wchar_t *path, mode_t mode);
271PW32IO int php_win32_ioutil_mkdir_w(const wchar_t *path, mode_t mode);
272PW32IO FILE *php_win32_ioutil_fopen_w(const wchar_t *path, const wchar_t *mode);
273PW32IO wchar_t *php_win32_ioutil_realpath_w(const wchar_t *path, wchar_t *resolved);
274PW32IO wchar_t *php_win32_ioutil_realpath_w_ex0(const wchar_t *path, wchar_t *resolved, PBY_HANDLE_FILE_INFORMATION info);
275PW32IO int php_win32_ioutil_symlink_w(const wchar_t *target, const wchar_t *link);
276PW32IO int php_win32_ioutil_link_w(const wchar_t *target, const wchar_t *link);
277
278__forceinline static int php_win32_ioutil_access(const char *path, mode_t mode)
279{/*{{{*/
281 int ret, err;
282
283 if (!pathw) {
284 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
285 return -1;
286 }
287
289
291 if (0 > ret) {
292 err = GetLastError();
293 }
295
296 if (0 > ret) {
298 }
299
300 return ret;
301}/*}}}*/
302
303__forceinline static int php_win32_ioutil_open(const char *path, int flags, ...)
304{/*{{{*/
305 mode_t mode = 0;
307 int ret = -1;
308 DWORD err;
309
310 if (!pathw) {
311 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
312 return -1;
313 }
314
316
317 if (flags & O_CREAT) {
318 va_list arg;
319
320 va_start(arg, flags);
321 mode = (mode_t) va_arg(arg, int);
322 va_end(arg);
323 }
324
326 if (0 > ret) {
327 err = GetLastError();
328 }
330
331 if (0 > ret) {
333 }
334
335 return ret;
336}/*}}}*/
337
338__forceinline static int php_win32_ioutil_unlink(const char *path)
339{/*{{{*/
341 int ret = -1;
342 DWORD err;
343
344 if (!pathw) {
345 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
346 return -1;
347 }
348
350 if (0 > ret) {
351 err = GetLastError();
352 }
354
355 if (0 > ret) {
357 }
358
359 return ret;
360}/*}}}*/
361
362__forceinline static int php_win32_ioutil_rmdir(const char *path)
363{/*{{{*/
365 int ret = 0;
366 DWORD err = 0;
367
368 if (!pathw) {
369 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
370 return -1;
371 }
372
374
375 if (!RemoveDirectoryW(pathw)) {
376 err = GetLastError();
377 ret = -1;
378 }
379
381
382 if (0 > ret) {
384 }
385
386 return ret;
387}/*}}}*/
388
389__forceinline static FILE *php_win32_ioutil_fopen(const char *patha, const char *modea)
390{/*{{{*/
391 FILE *ret;
392 wchar_t modew[16] = {0};
393 int i = 0;
394
396 if (!pathw) {
397 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
398 return NULL;
399 }
400
402
403 while (i < (sizeof(modew)-1)/sizeof(wchar_t) && modea[i]) {
404 modew[i] = (wchar_t)modea[i];
405 i++;
406 }
407
408 ret = php_win32_ioutil_fopen_w(pathw, modew);
409 if (!ret) {
410 int err = GetLastError();
413 return NULL;
414 }
415
417
418 return ret;
419}/*}}}*/
420
421__forceinline static int php_win32_ioutil_rename(const char *oldnamea, const char *newnamea)
422{/*{{{*/
423 wchar_t *oldnamew;
424 wchar_t *newnamew;
425 int ret;
426 DWORD err = 0;
427
428 oldnamew = php_win32_ioutil_any_to_w(oldnamea);
429 if (!oldnamew) {
430 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
431 return -1;
432 }
433 PHP_WIN32_IOUTIL_CHECK_PATH_W(oldnamew, -1, 1)
434
435 newnamew = php_win32_ioutil_any_to_w(newnamea);
436 if (!newnamew) {
437 free(oldnamew);
438 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
439 return -1;
440 } else {
441 size_t newnamew_len = wcslen(newnamew);
442 if (!PHP_WIN32_IOUTIL_PATH_IS_OK_W(newnamew, newnamew_len)) {
443 free(oldnamew);
444 free(newnamew);
445 SET_ERRNO_FROM_WIN32_CODE(ERROR_ACCESS_DENIED);
446 return -1;
447 }
448 }
449
450 ret = php_win32_ioutil_rename_w(oldnamew, newnamew);
451 if (0 > ret) {
452 err = GetLastError();
453 }
454
455 free(oldnamew);
456 free(newnamew);
457
458 if (0 > ret) {
460 }
461
462 return ret;
463}/*}}}*/
464
465__forceinline static int php_win32_ioutil_chdir(const char *patha)
466{/*{{{*/
467 int ret;
468 wchar_t *pathw = php_win32_ioutil_any_to_w(patha);
469 DWORD err = 0;
470
471 if (!pathw) {
472 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
473 return -1;
474 }
475
477 if (0 > ret) {
478 err = GetLastError();
479 }
480
481 free(pathw);
482
483 if (0 > ret) {
485 }
486
487 return ret;
488}/*}}}*/
489
490__forceinline static char *php_win32_ioutil_getcwd(char *buf, size_t len)
491{/*{{{*/
492 wchar_t tmp_bufw[PHP_WIN32_IOUTIL_MAXPATHLEN];
493 char *tmp_bufa = NULL;
494 size_t tmp_bufa_len;
495 DWORD err = 0;
496
498 err = GetLastError();
500 return NULL;
501 }
502
503 tmp_bufa = php_win32_cp_conv_w_to_any(tmp_bufw, wcslen(tmp_bufw), &tmp_bufa_len);
504 if (!tmp_bufa) {
505 err = GetLastError();
507 return NULL;
508 } else if (tmp_bufa_len + 1 > PHP_WIN32_IOUTIL_MAXPATHLEN) {
509 free(tmp_bufa);
510 SET_ERRNO_FROM_WIN32_CODE(ERROR_BAD_LENGTH);
511 return NULL;
512 } else if (tmp_bufa_len + 1 > len) {
513 free(tmp_bufa);
514 SET_ERRNO_FROM_WIN32_CODE(ERROR_INSUFFICIENT_BUFFER);
515 return NULL;
516 }
517
518 if (!buf && !len) {
519 /* If buf was NULL, the result has to be freed outside here. */
520 buf = tmp_bufa;
521 } else {
522 memmove(buf, tmp_bufa, tmp_bufa_len + 1);
523 free(tmp_bufa);
524 }
525
526 return buf;
527}/*}}}*/
528
529/* TODO improve with usage of native APIs, split for _a and _w. */
530__forceinline static int php_win32_ioutil_chmod(const char *patha, int mode)
531{/*{{{*/
532 wchar_t *pathw = php_win32_ioutil_any_to_w(patha);
533 int err = 0;
534 int ret;
535
536 if (!pathw) {
537 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
538 return -1;
539 }
540
542
543 ret = _wchmod(pathw, mode);
544 if (0 > ret) {
545 _get_errno(&err);
546 }
547
548 free(pathw);
549
550 if (0 > ret) {
551 _set_errno(err);
552 }
553
554 return ret;
555}/*}}}*/
556
557__forceinline static int php_win32_ioutil_mkdir(const char *path, mode_t mode)
558{/*{{{*/
559 int ret;
560 DWORD err = 0;
561
563 if (!pathw) {
564 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
565 return -1;
566 }
567
569 if (0 > ret) {
570 err = GetLastError();
571 }
572
574
575 if (0 > ret) {
577 }
578
579 return ret;
580}/*}}}*/
581
582__forceinline static int php_win32_ioutil_symlink(const char *target, const char *link)
583{/*{{{*/
584 wchar_t *targetw, *linkw;
585 int ret;
586
587 targetw = php_win32_ioutil_any_to_w(target);
588 if (!targetw) {
589 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
590 return -1;
591 }
592
594 if (!linkw) {
595 free(targetw);
596 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
597 return -1;
598 }
599
600 ret = php_win32_ioutil_symlink_w(targetw, linkw);
601
602 free(targetw);
603 free(linkw);
604
605 return ret;
606}/*}}}*/
607
608__forceinline static int php_win32_ioutil_link(const char *target, const char *link)
609{/*{{{*/
610 wchar_t *targetw, *linkw;
611 int ret;
612
613 targetw = php_win32_ioutil_any_to_w(target);
614 if (!targetw) {
615 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
616 return -1;
617 }
619 if (!linkw) {
620 free(targetw);
621 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
622 return -1;
623 }
624
625 ret = php_win32_ioutil_link_w(targetw, linkw);
626
627 free(targetw);
628 free(linkw);
629
630 return ret;
631}/*}}}*/
632
633PW32IO char *realpath(const char *path, char *resolved);
634
635__forceinline static char *php_win32_ioutil_realpath_ex0(const char *path, char *resolved, PBY_HANDLE_FILE_INFORMATION info)
636{/*{{{*/
637 wchar_t retw[PHP_WIN32_IOUTIL_MAXPATHLEN];
638 char *reta;
639 size_t reta_len;
640
642 if (!pathw) {
643 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
644 return NULL;
645 }
646
647 if (NULL == php_win32_ioutil_realpath_w_ex0(pathw, retw, info)) {
648 DWORD err = GetLastError();
651 return NULL;
652 }
653
654 reta = php_win32_cp_conv_w_to_any(retw, PHP_WIN32_CP_IGNORE_LEN, &reta_len);
655 if (!reta || reta_len > PHP_WIN32_IOUTIL_MAXPATHLEN) {
656 DWORD err = GetLastError();
659 return NULL;
660 }
661
662 if (NULL == resolved) {
663 /* ret is expected to be either NULL or a buffer of capable size. */
664 resolved = (char *) malloc(reta_len + 1);
665 if (!resolved) {
666 free(reta);
668 SET_ERRNO_FROM_WIN32_CODE(ERROR_NOT_ENOUGH_MEMORY);
669 return NULL;
670 }
671 }
672 memmove(resolved, reta, reta_len+1);
673
675 free(reta);
676
677 return resolved;
678}/*}}}*/
679
680__forceinline static char *php_win32_ioutil_realpath(const char *path, char *resolved)
681{/*{{{*/
682 return php_win32_ioutil_realpath_ex0(path, resolved, NULL);
683}/*}}}*/
684
685#include <sys/stat.h>
686#ifdef _WIN64
687typedef unsigned __int64 php_win32_ioutil_dev_t;
688typedef unsigned __int64 php_win32_ioutil_ino_t;
689typedef __time64_t php_win32_ioutil_time_t;
690typedef __int64 php_win32_ioutil_size_t;
691#else
692typedef unsigned __int32 php_win32_ioutil_dev_t;
693typedef unsigned __int32 php_win32_ioutil_ino_t;
694typedef __time32_t php_win32_ioutil_time_t;
696#endif
714
715typedef struct {
716 unsigned long ReparseTag;
717 unsigned short ReparseDataLength;
718 unsigned short Reserved;
719 union {
720 struct {
721 unsigned short SubstituteNameOffset;
722 unsigned short SubstituteNameLength;
723 unsigned short PrintNameOffset;
724 unsigned short PrintNameLength;
725 unsigned long Flags;
726 wchar_t ReparseTarget[1];
727 } SymbolicLinkReparseBuffer;
728 struct {
729 unsigned short SubstituteNameOffset;
730 unsigned short SubstituteNameLength;
731 unsigned short PrintNameOffset;
732 unsigned short PrintNameLength;
733 wchar_t ReparseTarget[1];
734 } MountPointReparseBuffer;
735 struct {
736 unsigned char ReparseTarget[1];
737 } GenericReparseBuffer;
738 };
740
741PW32IO int php_win32_ioutil_stat_ex_w(const wchar_t *path, size_t path_len, php_win32_ioutil_stat_t *buf, int lstat);
743
744__forceinline static int php_win32_ioutil_stat_ex(const char *path, php_win32_ioutil_stat_t *buf, int lstat)
745{/*{{{*/
746 size_t pathw_len;
747 wchar_t *pathw = php_win32_ioutil_conv_any_to_w(path, PHP_WIN32_CP_IGNORE_LEN, &pathw_len);
748 int ret;
749
750 if (!pathw) {
751 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
752 return -1;
753 }
754
755 ret = php_win32_ioutil_stat_ex_w(pathw, pathw_len, buf, lstat);
756
757 free(pathw);
758
759 return ret;
760}/*}}}*/
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)
763
764PW32IO ssize_t php_win32_ioutil_readlink_w(const wchar_t *path, wchar_t *buf, size_t buf_len);
765
766__forceinline static ssize_t php_win32_ioutil_readlink(const char *path, char *buf, size_t buf_len)
767{/*{{{*/
768 size_t pathw_len, ret_buf_len;
769 wchar_t *pathw = php_win32_ioutil_conv_any_to_w(path, PHP_WIN32_CP_IGNORE_LEN, &pathw_len);
770 wchar_t retw[PHP_WIN32_IOUTIL_MAXPATHLEN];
771 char *ret_buf;
772 ssize_t ret;
773
774 if (!pathw) {
775 SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
776 return -1;
777 }
778
779 ret = php_win32_ioutil_readlink_w(pathw, retw, sizeof(retw)-1);
780 if (ret < 0) {
781 DWORD _err = GetLastError();
782 free(pathw);
784 return ret;
785 }
786
787 ret_buf = php_win32_ioutil_conv_w_to_any(retw, ret, &ret_buf_len);
788 if (!ret_buf || ret_buf_len >= buf_len || ret_buf_len >= MAXPATHLEN) {
789 free(ret_buf);
790 free(pathw);
791 SET_ERRNO_FROM_WIN32_CODE(ERROR_BAD_PATHNAME);
792 return -1;
793 }
794 memcpy(buf, ret_buf, ret_buf_len + 1);
795
796 free(ret_buf);
797 free(pathw);
798
799 return ret_buf_len;
800}/*}}}*/
801
802#ifdef __cplusplus
803}
804#endif
805
806#endif /* PHP_WIN32_IOUTIL_H */
size_t len
Definition apprentice.c:174
sizeof(Countable|array $value, int $mode=COUNT_NORMAL)
link(string $target, string $link)
lstat(string $filename)
#define PHP_WIN32_CP_IGNORE_LEN_P
Definition codepage.h:31
#define PHP_WIN32_CP_IGNORE_LEN
Definition codepage.h:30
#define DWORD
Definition exif.c:1762
memcpy(ptr1, ptr2, size)
char * err
Definition ffi.c:3029
zval * arg
Definition ffi.c:3975
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
char * mode
#define NULL
Definition gdcache.h:45
foreach($dp as $el) foreach( $dp as $el) if( $pass2< 2) echo ""
BOOL php_win32_ioutil_init(void)
Definition ioutil.c:651
PW32IO int php_win32_ioutil_access_w(const wchar_t *path, mode_t mode)
Definition ioutil.c:667
#define PHP_WIN32_IOUTIL_FW_SLASHW
Definition ioutil.h:113
PW32IO int php_win32_ioutil_link_w(const wchar_t *target, const wchar_t *link)
Definition ioutil.c:839
__time32_t php_win32_ioutil_time_t
Definition ioutil.h:694
#define PHP_WIN32_IOUTIL_IS_JUNCTION_PATHW(pathw, path_lenw)
Definition ioutil.h:134
PW32IO ssize_t php_win32_ioutil_readlink_w(const wchar_t *path, wchar_t *buf, size_t buf_len)
Definition ioutil.c:1142
PW32IO int php_win32_ioutil_symlink_w(const wchar_t *target, const wchar_t *link)
Definition ioutil.c:820
PW32IO int php_win32_ioutil_open_w(const wchar_t *path, int flags,...)
Definition ioutil.c:187
PW32IO php_win32_ioutil_normalization_result php_win32_ioutil_normalize_path_w(wchar_t **buf, size_t len, size_t *new_len)
Definition ioutil.c:601
unsigned short mode_t
Definition ioutil.h:72
__int32 php_win32_ioutil_size_t
Definition ioutil.h:695
#define PHP_WIN32_IOUTIL_PATH_IS_OK_W(pathw, len)
Definition ioutil.h:156
PW32IO int php_win32_ioutil_access_w(const wchar_t *path, mode_t mode)
Definition ioutil.c:667
#define PHP_WIN32_IOUTIL_IS_UNC_PATHW(pathw, path_lenw)
Definition ioutil.h:132
PW32IO size_t php_win32_ioutil_dirname(char *buf, size_t len)
Definition ioutil.c:521
PW32IO int php_win32_ioutil_mkdir_w(const wchar_t *path, mode_t mode)
Definition ioutil.c:286
#define PW32IO
Definition ioutil.h:61
PW32IO int php_win32_ioutil_close(int fd)
Definition ioutil.c:261
PW32IO char * realpath(const char *path, char *resolved)
Definition ioutil.c:815
php_win32_ioutil_encoding
Definition ioutil.h:101
@ PHP_WIN32_IOUTIL_IS_UTF8
Definition ioutil.h:104
@ PHP_WIN32_IOUTIL_IS_ANSI
Definition ioutil.h:103
@ PHP_WIN32_IOUTIL_IS_ASCII
Definition ioutil.h:102
#define PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, ret, dealloc)
Definition ioutil.h:160
PW32IO wchar_t * php_win32_ioutil_realpath_w_ex0(const wchar_t *path, wchar_t *resolved, PBY_HANDLE_FILE_INFORMATION info)
Definition ioutil.c:775
PW32IO int php_win32_ioutil_rename_w(const wchar_t *oldname, const wchar_t *newname)
Definition ioutil.c:467
PW32IO int php_win32_ioutil_stat_ex_w(const wchar_t *path, size_t path_len, php_win32_ioutil_stat_t *buf, int lstat)
Definition ioutil.c:972
#define PHP_WIN32_IOUTIL_INIT_W(path)
Definition ioutil.h:143
#define PHP_WIN32_IOUTIL_IS_LONG_PATHW(pathw, path_lenw)
Definition ioutil.h:130
PW32IO wchar_t * php_win32_ioutil_getcwd_w(wchar_t *buf, size_t len)
Definition ioutil.c:484
PW32IO int php_win32_ioutil_fstat(int fd, php_win32_ioutil_stat_t *buf)
Definition ioutil.c:1022
PW32IO wchar_t * php_win32_ioutil_realpath_w(const wchar_t *path, wchar_t *resolved)
Definition ioutil.c:770
#define PHP_WIN32_IOUTIL_DEFAULT_SLASHW
Definition ioutil.h:117
unsigned __int32 php_win32_ioutil_ino_t
Definition ioutil.h:693
php_win32_ioutil_normalization_result
Definition ioutil.h:107
@ PHP_WIN32_IOUTIL_NORM_PARTIAL
Definition ioutil.h:109
@ PHP_WIN32_IOUTIL_NORM_OK
Definition ioutil.h:108
@ PHP_WIN32_IOUTIL_NORM_FAIL
Definition ioutil.h:110
#define PHP_WIN32_IOUTIL_CLEANUP_W()
Definition ioutil.h:146
PW32IO int php_win32_ioutil_unlink_w(const wchar_t *path)
Definition ioutil.c:368
PW32IO int php_win32_ioutil_chdir_w(const wchar_t *path)
Definition ioutil.c:454
#define php_win32_ioutil_any_to_w(in)
Definition ioutil.h:247
unsigned __int32 php_win32_ioutil_dev_t
Definition ioutil.h:692
#define PHP_WIN32_IOUTIL_LONG_PATH_PREFIXW
Definition ioutil.h:125
#define PHP_WIN32_IOUTIL_MAXPATHLEN
Definition ioutil.h:64
struct PHP_WIN32_IOUTIL_REPARSE_DATA_BUFFER * PHP_WIN32_IOUTIL_PREPARSE_DATA_BUFFER
#define PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW
Definition ioutil.h:126
PW32IO BOOL php_win32_ioutil_posix_to_open_opts(int flags, mode_t mode, php_ioutil_open_opts *opts)
Definition ioutil.c:74
#define php_win32_ioutil_conv_w_to_any
Definition ioutil.h:253
PW32IO FILE * php_win32_ioutil_fopen_w(const wchar_t *path, const wchar_t *mode)
Definition ioutil.c:695
int BOOL
#define memmove(a, b, c)
int fd
Definition phpdbg.h:282
php_win32_ioutil_dev_t st_rdev
Definition ioutil.h:704
php_win32_ioutil_time_t st_atime
Definition ioutil.h:710
unsigned __int32 st_mode
Definition ioutil.h:700
php_win32_ioutil_dev_t st_dev
Definition ioutil.h:698
unsigned short st_gid
Definition ioutil.h:703
unsigned short st_uid
Definition ioutil.h:702
unsigned __int32 st_nlink
Definition ioutil.h:701
php_win32_ioutil_time_t st_ctime
Definition ioutil.h:712
php_win32_ioutil_size_t st_size
Definition ioutil.h:705
php_win32_ioutil_ino_t st_ino
Definition ioutil.h:699
php_win32_ioutil_time_t st_mtime
Definition ioutil.h:711
#define SET_ERRNO_FROM_WIN32_CODE(err)
Definition winutil.h:47
#define MAXPATHLEN
while(0)
zval * ret