Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion stl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ set(HEADERS
${CMAKE_CURRENT_LIST_DIR}/inc/execution
${CMAKE_CURRENT_LIST_DIR}/inc/expected
${CMAKE_CURRENT_LIST_DIR}/inc/experimental/coroutine
${CMAKE_CURRENT_LIST_DIR}/inc/experimental/filesystem
${CMAKE_CURRENT_LIST_DIR}/inc/experimental/generator
${CMAKE_CURRENT_LIST_DIR}/inc/experimental/resumable
${CMAKE_CURRENT_LIST_DIR}/inc/filesystem
Expand Down
4 changes: 0 additions & 4 deletions stl/inc/__msvc_all_public_headers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#endif // !defined(_SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING)

#define _SILENCE_CXX20_CISO646_REMOVED_WARNING
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS

// Core STL Headers
Expand Down Expand Up @@ -158,9 +157,6 @@
#include <cstdbool>
#include <ctgmath>

// Non-Core Experimental Headers
#include <experimental/filesystem>

#endif // !defined(_CORE_HEADERS_ONLY)

#ifndef _MSVC_TESTING_NVCC
Expand Down
41 changes: 1 addition & 40 deletions stl/inc/__msvc_filebuf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

// TRANSITION, ABI: The _Path_ish functions accepting filesystem::path or experimental::filesystem::path are templates
// TRANSITION, ABI: The _Path_ish functions accepting filesystem::path are templates
// which always use the same types as a workaround for user code deriving from iostreams types and
// __declspec(dllexport)ing the derived types. Adding member functions to iostreams broke the ABI of such DLLs.
// Deriving and __declspec(dllexport)ing standard library types is not supported, but in this particular case
Expand All @@ -31,36 +31,6 @@ namespace filesystem {
}
#endif // _HAS_CXX17

#ifndef _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
#ifdef _M_CEE
#define _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM 0
#else // ^^^ defined(_M_CEE) / !defined(_M_CEE) vvv
#define _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM 1
#endif // ^^^ !defined(_M_CEE) ^^^
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM

#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
namespace experimental {
namespace filesystem {
inline namespace v1 {
class path;
}
} // namespace filesystem
} // namespace experimental
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM

template <class _Ty>
constexpr bool _Is_any_path = _Is_any_of_v<_Ty
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
,
experimental::filesystem::path
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
#if _HAS_CXX17
,
filesystem::path
#endif // _HAS_CXX17
>;

extern "C++" _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const char*, ios_base::openmode, int);
extern "C++" _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const wchar_t*, ios_base::openmode, int);

Expand Down Expand Up @@ -325,15 +295,6 @@ class basic_filebuf : public basic_streambuf<_Elem, _Traits> { // stream buffer
return open(_Str.c_str(), _Mode, _Prot);
}

#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
template <class _Path_ish = experimental::filesystem::path>
basic_filebuf* open(
const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode, int _Prot = ios_base::_Default_open_prot) {
// _Prot is an extension
return open(_Path.c_str(), _Mode, _Prot);
}
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM

#if _HAS_CXX17
template <int = 0, class _Path_ish = filesystem::path>
basic_filebuf* open(
Expand Down
41 changes: 9 additions & 32 deletions stl/inc/fstream
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ public:
const wstring& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot)
: basic_ifstream(_Str.c_str(), _Mode, _Prot) {} // extension

template <class _Ty, enable_if_t<_Is_any_path<_Ty>, int> = 0>
#if _HAS_CXX17
template <class _Ty, enable_if_t<is_same_v<_Ty, filesystem::path>, int> = 0>
explicit basic_ifstream(
const _Ty& _Path, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot)
: basic_ifstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension
#endif // _HAS_CXX17

explicit basic_ifstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension

Expand Down Expand Up @@ -102,15 +104,6 @@ public:
open(_Str.c_str(), _Mode, _Prot);
}

#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
template <class _Path_ish = experimental::filesystem::path>
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in,
int _Prot = ios_base::_Default_open_prot) {
// _Prot is an extension
open(_Path.c_str(), _Mode, _Prot);
}
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM

#if _HAS_CXX17
template <int = 0, class _Path_ish = filesystem::path>
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in,
Expand Down Expand Up @@ -207,10 +200,12 @@ public:
const wstring& _Str, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot)
: basic_ofstream(_Str.c_str(), _Mode, _Prot) {} // extension

template <class _Ty, enable_if_t<_Is_any_path<_Ty>, int> = 0>
#if _HAS_CXX17
template <class _Ty, enable_if_t<is_same_v<_Ty, filesystem::path>, int> = 0>
explicit basic_ofstream(
const _Ty& _Path, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot)
: basic_ofstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension
#endif // _HAS_CXX17

explicit basic_ofstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension

Expand Down Expand Up @@ -255,15 +250,6 @@ public:
open(_Str.c_str(), _Mode, _Prot);
}

#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
template <class _Path_ish = experimental::filesystem::path>
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::out,
int _Prot = ios_base::_Default_open_prot) {
// _Prot is an extension
open(_Path.c_str(), _Mode, _Prot);
}
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM

#if _HAS_CXX17
template <int = 0, class _Path_ish = filesystem::path>
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::out,
Expand Down Expand Up @@ -365,10 +351,12 @@ public:
int _Prot = ios_base::_Default_open_prot)
: basic_fstream(_Str.c_str(), _Mode, _Prot) {} // extension

template <class _Ty, enable_if_t<_Is_any_path<_Ty>, int> = 0>
#if _HAS_CXX17
template <class _Ty, enable_if_t<is_same_v<_Ty, filesystem::path>, int> = 0>
explicit basic_fstream(const _Ty& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot)
: basic_fstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension
#endif // _HAS_CXX17

explicit basic_fstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension

Expand Down Expand Up @@ -414,15 +402,6 @@ public:
open(_Str.c_str(), _Mode, _Prot);
}

#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
template <class _Path_ish = experimental::filesystem::path>
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot) {
// extension
open(_Path.c_str(), _Mode, _Prot);
}
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM

#if _HAS_CXX17
template <int = 0, class _Path_ish = filesystem::path>
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
Expand Down Expand Up @@ -487,8 +466,6 @@ void swap(basic_fstream<_Elem, _Traits>& _Left, basic_fstream<_Elem, _Traits>& _
}
_STD_END

#undef _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM

#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
#pragma warning(pop)
Expand Down
2 changes: 0 additions & 2 deletions stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1937,8 +1937,6 @@ _EMIT_STL_ERROR(STL1004, "C++98 unexpected() is incompatible with C++23 unexpect
#define __cpp_lib_variant 202102L // P2162R2 Inheriting From variant
#endif

#define __cpp_lib_experimental_filesystem 201406L

#ifdef _RTC_CONVERSION_CHECKS_ENABLED
#ifndef _ALLOW_RTCc_IN_STL
#error /RTCc rejects conformant code, so it is not supported by the C++ Standard Library. Either remove this \
Expand Down
66 changes: 64 additions & 2 deletions stl/src/filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@
// filesys.cpp -- <experimental/filesystem> implementation
// (see filesystem.cpp for C++17 <filesystem> implementation)

#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
// TRANSITION, ABI: Everything in this file is preserved for binary compatibility.

#include <yvals.h>

#include <cstdint>
#include <cstring>
#include <direct.h>
#include <experimental/filesystem>
#include <io.h>
#include <string>

#include <Windows.h>

#define _MAX_FILESYS_NAME 260 // longest Windows or Posix filename + 1

#define _FS_BEGIN \
_STD_BEGIN \
namespace experimental { \
namespace filesystem { \
inline namespace v1 {

#define _FS_END \
} \
} \
} \
_STD_END

#ifdef _M_CEE_PURE
#define __crtGetTempPath2W(BufferLength, Buffer) GetTempPathW(BufferLength, Buffer)
#else // vvv !defined(_M_CEE_PURE) vvv
Expand All @@ -23,6 +38,53 @@ extern "C" _Success_(return > 0 && return < BufferLength) DWORD __stdcall __crtG
#endif // ^^^ !defined(_M_CEE_PURE) ^^^

_FS_BEGIN

enum class file_type { // names for file types
not_found = -1,
none,
regular,
directory,
symlink,
block,
character,
fifo,
socket,
unknown
};

enum class perms { // names for permissions
none = 0,
owner_read = 0400, // S_IRUSR
owner_write = 0200, // S_IWUSR
owner_exec = 0100, // S_IXUSR
owner_all = 0700, // S_IRWXU
group_read = 040, // S_IRGRP
group_write = 020, // S_IWGRP
group_exec = 010, // S_IXGRP
group_all = 070, // S_IRWXG
others_read = 04, // S_IROTH
others_write = 02, // S_IWOTH
others_exec = 01, // S_IXOTH
others_all = 07, // S_IRWXO
all = 0777,
set_uid = 04000, // S_ISUID
set_gid = 02000, // S_ISGID
sticky_bit = 01000, // S_ISVTX
mask = 07777,
unknown = 0xFFFF,
add_perms = 0x10000,
remove_perms = 0x20000,
resolve_symlinks = 0x40000
};

_BITMASK_OPS(_EMPTY_ARGUMENT, perms)

struct space_info { // space information for a file
uintmax_t capacity;
uintmax_t free;
uintmax_t available;
};

static file_type _Map_mode(int _Mode) { // map Windows file attributes to file_status
constexpr int _File_attribute_regular =
FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_COMPRESSED | FILE_ATTRIBUTE_ENCRYPTED | FILE_ATTRIBUTE_HIDDEN
Expand Down
1 change: 0 additions & 1 deletion stl/src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

// filesystem.cpp -- C++17 <filesystem> implementation
// (see filesys.cpp for <experimental/filesystem> implementation)

#include <clocale>
#include <corecrt_terminate.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

// ********************************************************************************************************************
// * This was previously shipped in product code as <experimental/filesystem>. *
// * It's now preserved in cryostasis for test code to exercise functions that are retained for binary compatibility. *
// * This file should generally not be changed, except to fix compiler warnings/errors and to update clang-format. *
// ********************************************************************************************************************

#ifndef _EXPERIMENTAL_FILESYSTEM_
#define _EXPERIMENTAL_FILESYSTEM_
#include <yvals_core.h>
Expand Down
33 changes: 19 additions & 14 deletions tests/std/tests/Dev09_172666_tr1_tuple_odr/test.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING

#include <__msvc_all_public_headers.hpp>
#include <cassert>

namespace fs = std::experimental::filesystem;
#include "experimental_filesystem.hpp"

int meow();

inline bool test_wchar_t_minus() {
// Test for DevDiv-1004799: <filesystem>: /Zc:wchar_t- fails. Calling file_size
// should cause the failure to occur if we are wchar_t incorrect. Test is disabled
// (i.e. always passes) if compiled with /clr:pure and /Zc:wchar_t-, as it triggers
// LNK2031: calling convention missing in metadata errors, which are irrelevant here.
#if defined(_M_CEE_PURE) && !defined(_NATIVE_WCHAR_T_DEFINED)
return true;
#else // ^^^ /clr:pure /Zc:wchar_t- / Other vvv
return fs::file_size(fs::current_path() / "Dev09_172666_tr1_tuple_odr.exe") != 0u;
#endif // defined(_M_CEE_PURE) && !defined(_NATIVE_WCHAR_T_DEFINED)
}

int main() {
assert(meow() == 1729);
assert(test_wchar_t_minus());

// Test for DevDiv-1004799: <filesystem>: /Zc:wchar_t- fails.
// Calling file_size should cause the failure to occur if we are wchar_t incorrect.
#if defined(_M_CEE_PURE) && !defined(_NATIVE_WCHAR_T_DEFINED)
// Test is disabled if compiled with /clr:pure and /Zc:wchar_t-, as it triggers
// LNK2031: calling convention missing in metadata errors, which are irrelevant here.
#else // ^^^ workaround / no workaround vvv
{
namespace fs = std::experimental::filesystem;
assert(fs::file_size(fs::current_path() / "Dev09_172666_tr1_tuple_odr.exe") != 0u);
}

#if _HAS_CXX17
assert(std::filesystem::file_size(std::filesystem::current_path() / "Dev09_172666_tr1_tuple_odr.exe") != 0u);
#endif // _HAS_CXX17
#endif // ^^^ no workaround ^^^
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <cassert>
#include <cstring>
#include <deque>
#include <experimental/filesystem>
#include <forward_list>
#include <iterator>
#include <list>
Expand All @@ -31,6 +30,8 @@
#include <span>
#endif // _HAS_CXX20

#include "experimental_filesystem.hpp"

using namespace std;

// N3797 24.2.5 [forward.iterators]/2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <experimental/filesystem>
#include <fstream>
#include <string>
#include <system_error>
Expand All @@ -16,6 +15,7 @@
#include <filesystem>
#endif // _HAS_CXX17

#include "experimental_filesystem.hpp"
#include <test_filesystem_support.hpp>

using namespace std;
Expand Down
Loading