xref: /PHP-7.4/win32/ioutil.c (revision 58b17906)
13d3f11edSAnatol Belski /*
23d3f11edSAnatol Belski    +----------------------------------------------------------------------+
33d3f11edSAnatol Belski    | PHP Version 7                                                        |
43d3f11edSAnatol Belski    +----------------------------------------------------------------------+
50cf7de1cSZeev Suraski    | Copyright (c) The PHP Group                                          |
63d3f11edSAnatol Belski    +----------------------------------------------------------------------+
73d3f11edSAnatol Belski    | This source file is subject to version 3.01 of the PHP license,      |
83d3f11edSAnatol Belski    | that is bundled with this package in the file LICENSE, and is        |
93d3f11edSAnatol Belski    | available through the world-wide-web at the following url:           |
103d3f11edSAnatol Belski    | http://www.php.net/license/3_01.txt                                  |
113d3f11edSAnatol Belski    | If you did not receive a copy of the PHP license and are unable to   |
123d3f11edSAnatol Belski    | obtain it through the world-wide-web, please send a note to          |
133d3f11edSAnatol Belski    | license@php.net so we can mail you a copy immediately.               |
143d3f11edSAnatol Belski    +----------------------------------------------------------------------+
153d3f11edSAnatol Belski    | Author: Anatol Belski <ab@php.net>                                   |
163d3f11edSAnatol Belski    +----------------------------------------------------------------------+
173d3f11edSAnatol Belski */
183d3f11edSAnatol Belski 
193d3f11edSAnatol Belski /* This file integrates several modified parts from the libuv project, which
203d3f11edSAnatol Belski  * is copyrighted to
213d3f11edSAnatol Belski  *
223d3f11edSAnatol Belski  * Copyright Joyent, Inc. and other Node contributors. All rights reserved.
233d3f11edSAnatol Belski  *
243d3f11edSAnatol Belski  * Permission is hereby granted, free of charge, to any person obtaining a copy
253d3f11edSAnatol Belski  * of this software and associated documentation files (the "Software"), to
263d3f11edSAnatol Belski  * deal in the Software without restriction, including without limitation the
273d3f11edSAnatol Belski  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
283d3f11edSAnatol Belski  * sell copies of the Software, and to permit persons to whom the Software is
293d3f11edSAnatol Belski  * furnished to do so, subject to the following conditions:
303d3f11edSAnatol Belski  *
313d3f11edSAnatol Belski  * The above copyright notice and this permission notice shall be included in
323d3f11edSAnatol Belski  * all copies or substantial portions of the Software.
333d3f11edSAnatol Belski  *
343d3f11edSAnatol Belski  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
353d3f11edSAnatol Belski  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
363d3f11edSAnatol Belski  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
373d3f11edSAnatol Belski  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
383d3f11edSAnatol Belski  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
393d3f11edSAnatol Belski  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
403d3f11edSAnatol Belski  * IN THE SOFTWARE.
4164002648SGabriel Caruso  */
423d3f11edSAnatol Belski 
433d3f11edSAnatol Belski #include <assert.h>
443d3f11edSAnatol Belski #include <stdlib.h>
453d3f11edSAnatol Belski #include <direct.h>
463d3f11edSAnatol Belski #include <errno.h>
473d3f11edSAnatol Belski #include <fcntl.h>
483d3f11edSAnatol Belski #include <io.h>
493d3f11edSAnatol Belski #include <limits.h>
503d3f11edSAnatol Belski #include <sys/stat.h>
513d3f11edSAnatol Belski #include <sys/utime.h>
523d3f11edSAnatol Belski #include <stdio.h>
533d3f11edSAnatol Belski 
543d3f11edSAnatol Belski #include "php.h"
553d3f11edSAnatol Belski #include "SAPI.h"
563d3f11edSAnatol Belski #include "win32/winutil.h"
573d3f11edSAnatol Belski #include "win32/time.h"
583d3f11edSAnatol Belski #include "win32/ioutil.h"
593d3f11edSAnatol Belski #include "win32/codepage.h"
60f3fd860eSAnatol Belski #include "main/streams/php_stream_plain_wrapper.h"
613d3f11edSAnatol Belski 
620f16c562SAnatol Belski #include <pathcch.h>
63e42e8b10SAnatol Belski #include <winioctl.h>
64e42e8b10SAnatol Belski #include <winnt.h>
650f16c562SAnatol Belski 
663d3f11edSAnatol Belski /*
673d3f11edSAnatol Belski #undef NONLS
683d3f11edSAnatol Belski #undef _WINNLS_
693d3f11edSAnatol Belski #include <winnls.h>
703d3f11edSAnatol Belski */
713d3f11edSAnatol Belski 
724acde210SAnatol Belski typedef HRESULT (__stdcall *MyPathCchCanonicalizeEx)(wchar_t *pszPathOut, size_t cchPathOut, const wchar_t *pszPathIn, unsigned long dwFlags);
730f16c562SAnatol Belski 
740f16c562SAnatol Belski static MyPathCchCanonicalizeEx canonicalize_path_w = NULL;
750f16c562SAnatol Belski 
php_win32_ioutil_posix_to_open_opts(int flags,mode_t mode,php_ioutil_open_opts * opts)763d3f11edSAnatol Belski PW32IO BOOL php_win32_ioutil_posix_to_open_opts(int flags, mode_t mode, php_ioutil_open_opts *opts)
773d3f11edSAnatol Belski {/*{{{*/
783d3f11edSAnatol Belski 	int current_umask;
793d3f11edSAnatol Belski 
803d3f11edSAnatol Belski 	opts->attributes = 0;
813d3f11edSAnatol Belski 
823d3f11edSAnatol Belski 	/* Obtain the active umask. umask() never fails and returns the previous */
833d3f11edSAnatol Belski 	/* umask. */
843d3f11edSAnatol Belski 	current_umask = umask(0);
853d3f11edSAnatol Belski 	umask(current_umask);
86