├── .gitattributes ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── CMakeLists.txt ├── README.md ├── appveyor.yml ├── bug ├── Jamfile.v2 ├── bug.cpp └── index.html ├── build.jam ├── build └── Jamfile.v2 ├── cmake └── BoostLibraryIncludes.cmake ├── config ├── Jamfile.v2 ├── has_attribute_init_priority.cpp ├── has_bcrypt.cpp ├── has_cxx20_atomic_ref.cpp ├── has_dirent_d_type.cpp ├── has_fallocate.cpp ├── has_fdopendir_nofollow.cpp ├── has_linkflag_no_undefined.cpp ├── has_posix_at_apis.cpp ├── has_stat_st_birthtim.cpp ├── has_stat_st_birthtimensec.cpp ├── has_stat_st_birthtimespec.cpp ├── has_stat_st_blksize.cpp ├── has_stat_st_mtim.cpp ├── has_stat_st_mtimensec.cpp ├── has_stat_st_mtimespec.cpp ├── has_statx.cpp ├── has_statx_syscall.cpp └── is_windows_ce.cpp ├── doc ├── Jamfile.v2 ├── POSIX_filename_encoding.txt ├── deprecated.html ├── design.htm ├── do_list.html ├── faq.htm ├── index.htm ├── issue_reporting.html ├── path_table.cpp ├── path_table.txt ├── portability_guide.htm ├── reference.html ├── relative_proposal.html ├── release_history.html ├── styles.css ├── tickets.html ├── tutorial.html ├── v3.html ├── v3_design.html └── v4.html ├── example ├── .gitignore ├── Jamfile.v2 ├── error_demo.cpp ├── file_size.cpp ├── file_status.cpp ├── mbcopy.cpp ├── mbpath.cpp ├── mbpath.hpp ├── path_info.cpp ├── simple_ls.cpp ├── stems.cpp ├── tchar.cpp ├── tut0.cpp ├── tut1.cpp ├── tut2.cpp ├── tut3.cpp ├── tut4.cpp ├── tut5.cpp ├── tut6a.cpp ├── tut6b.cpp └── tut6c.cpp ├── include └── boost │ ├── filesystem.hpp │ └── filesystem │ ├── config.hpp │ ├── cstdio.hpp │ ├── detail │ ├── footer.hpp │ ├── header.hpp │ ├── path_traits.hpp │ ├── type_traits │ │ ├── conjunction.hpp │ │ ├── disjunction.hpp │ │ └── negation.hpp │ └── utf8_codecvt_facet.hpp │ ├── directory.hpp │ ├── exception.hpp │ ├── file_status.hpp │ ├── fstream.hpp │ ├── operations.hpp │ └── path.hpp ├── index.html ├── meta └── libraries.json ├── src ├── atomic_ref.hpp ├── atomic_tools.hpp ├── codecvt_error_category.cpp ├── directory.cpp ├── error_handling.hpp ├── exception.cpp ├── operations.cpp ├── path.cpp ├── path_traits.cpp ├── platform_config.hpp ├── portability.cpp ├── posix_tools.hpp ├── private_config.hpp ├── unique_path.cpp ├── utf8_codecvt_facet.cpp ├── windows_file_codecvt.cpp ├── windows_file_codecvt.hpp └── windows_tools.hpp └── test ├── Jamfile.v2 ├── cf_path_nullptr_test.cpp ├── config_info.cpp ├── convenience_test.cpp ├── copy_test.cpp ├── cstdio_test.cpp ├── deprecated_test.cpp ├── design_use_cases.cpp ├── equivalent.cpp ├── foreach_test.cpp ├── fstream_test.cpp ├── issues ├── 3332 │ └── test.cpp ├── 10038.cpp ├── 10205.cpp ├── 10485.cpp ├── 10641.cpp ├── 11166-remove-race.cpp ├── 11228--filtered-recursive_directory_iterator-range.cpp ├── 4329.-basename.cpp ├── 5300-temp-dir-path-130.cpp ├── 6638-global-init-fails-3.cpp ├── 70-71-copy.cpp ├── 8930.cpp ├── 9054_static_const_codecvt_segfault_pre_main.cpp ├── 9219.cpp ├── 99_canonical_with_junction_point.cpp ├── Jamfile.v2 ├── boost-no-inspect ├── copy_file-compilation-error-2015-05-04.cpp ├── fchmodat_AT_SYMLINK_NOFOLLOW_6659.cpp ├── hello_filesystem.cpp ├── readme.txt ├── recurse_dir_iter_5403.cpp └── reparse_tag_file_placeholder.cpp ├── large_file_support_test.cpp ├── locale_info.cpp ├── long_path_test.cpp ├── macro_default_test.cpp ├── macro_value.hpp ├── odr1_test.cpp ├── odr2_test.cpp ├── operations_test.cpp ├── operations_unit_test.cpp ├── path_iter_ctor_overload_test.cpp ├── path_operator_ambiguity.cpp ├── path_test.cpp ├── path_times.cpp ├── path_unit_test.cpp ├── quick.cpp ├── relative_test.cpp ├── sample_test.cpp ├── test_cmake ├── CMakeLists.txt └── main.cpp ├── test_codecvt.hpp └── windows_attributes.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto !eol svneol=native#text/plain 2 | *.gitattributes text svneol=native#text/plain 3 | 4 | # Scriptish formats 5 | *.bat text svneol=native#text/plain 6 | *.bsh text svneol=native#text/x-beanshell 7 | *.cgi text svneol=native#text/plain 8 | *.cmd text svneol=native#text/plain 9 | *.js text svneol=native#text/javascript 10 | *.php text svneol=native#text/x-php 11 | *.pl text svneol=native#text/x-perl 12 | *.pm text svneol=native#text/x-perl 13 | *.py text svneol=native#text/x-python 14 | *.sh eol=lf svneol=LF#text/x-sh 15 | configure eol=lf svneol=LF#text/x-sh 16 | 17 | # Image formats 18 | *.bmp binary svneol=unset#image/bmp 19 | *.gif binary svneol=unset#image/gif 20 | *.ico binary svneol=unset#image/ico 21 | *.jpeg binary svneol=unset#image/jpeg 22 | *.jpg binary svneol=unset#image/jpeg 23 | *.png binary svneol=unset#image/png 24 | *.tif binary svneol=unset#image/tiff 25 | *.tiff binary svneol=unset#image/tiff 26 | *.svg text svneol=native#image/svg%2Bxml 27 | 28 | # Data formats 29 | *.pdf binary svneol=unset#application/pdf 30 | *.avi binary svneol=unset#video/avi 31 | *.doc binary svneol=unset#application/msword 32 | *.dsp text svneol=crlf#text/plain 33 | *.dsw text svneol=crlf#text/plain 34 | *.eps binary svneol=unset#application/postscript 35 | *.gz binary svneol=unset#application/gzip 36 | *.mov binary svneol=unset#video/quicktime 37 | *.mp3 binary svneol=unset#audio/mpeg 38 | *.ppt binary svneol=unset#application/vnd.ms-powerpoint 39 | *.ps binary svneol=unset#application/postscript 40 | *.psd binary svneol=unset#application/photoshop 41 | *.rdf binary svneol=unset#text/rdf 42 | *.rss text svneol=unset#text/xml 43 | *.rtf binary svneol=unset#text/rtf 44 | *.sln text svneol=native#text/plain 45 | *.swf binary svneol=unset#application/x-shockwave-flash 46 | *.tgz binary svneol=unset#application/gzip 47 | *.vcproj text svneol=native#text/xml 48 | *.vcxproj text svneol=native#text/xml 49 | *.vsprops text svneol=native#text/xml 50 | *.wav binary svneol=unset#audio/wav 51 | *.xls binary svneol=unset#application/vnd.ms-excel 52 | *.zip binary svneol=unset#application/zip 53 | 54 | # Text formats 55 | .htaccess text svneol=native#text/plain 56 | *.bbk text svneol=native#text/xml 57 | *.cmake text svneol=native#text/plain 58 | *.css text svneol=native#text/css 59 | *.dtd text svneol=native#text/xml 60 | *.htm text svneol=native#text/html 61 | *.html text svneol=native#text/html 62 | *.ini text svneol=native#text/plain 63 | *.log text svneol=native#text/plain 64 | *.mak text svneol=native#text/plain 65 | *.qbk text svneol=native#text/plain 66 | *.rst text svneol=native#text/plain 67 | *.sql text svneol=native#text/x-sql 68 | *.txt text svneol=native#text/plain 69 | *.xhtml text svneol=native#text/xhtml%2Bxml 70 | *.xml text svneol=native#text/xml 71 | *.xsd text svneol=native#text/xml 72 | *.xsl text svneol=native#text/xml 73 | *.xslt text svneol=native#text/xml 74 | *.xul text svneol=native#text/xul 75 | *.yml text svneol=native#text/plain 76 | boost-no-inspect text svneol=native#text/plain 77 | CHANGES text svneol=native#text/plain 78 | COPYING text svneol=native#text/plain 79 | INSTALL text svneol=native#text/plain 80 | Jamfile text svneol=native#text/plain 81 | Jamroot text svneol=native#text/plain 82 | Jamfile.v2 text svneol=native#text/plain 83 | Jamrules text svneol=native#text/plain 84 | Makefile* text svneol=native#text/plain 85 | README text svneol=native#text/plain 86 | TODO text svneol=native#text/plain 87 | 88 | # Code formats 89 | *.c text svneol=native#text/plain 90 | *.cpp text svneol=native#text/plain 91 | *.h text svneol=native#text/plain 92 | *.hpp text svneol=native#text/plain 93 | *.ipp text svneol=native#text/plain 94 | *.tpp text svneol=native#text/plain 95 | *.jam text svneol=native#text/plain 96 | *.java text svneol=native#text/plain 97 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.com 4 | *.class 5 | *.dll 6 | *.exe 7 | *.o 8 | *.so 9 | 10 | # Packages # 11 | ############ 12 | # it's better to unpack these files and commit the raw source 13 | # git has its own built in compression methods 14 | *.7z 15 | *.dmg 16 | *.gz 17 | *.iso 18 | *.jar 19 | *.rar 20 | *.tar 21 | *.zip 22 | 23 | # Logs and databases # 24 | ###################### 25 | *.log 26 | *.sql 27 | *.sqlite 28 | 29 | # OS generated files # 30 | ###################### 31 | .DS_Store 32 | .DS_Store? 33 | ._* 34 | .Spotlight-V100 35 | .Trashes 36 | ehthumbs.db 37 | Thumbs.db 38 | 39 | # IDE generated files # 40 | ####################### 41 | 42 | # Visual Studio 43 | Debug 44 | Release 45 | .sdf 46 | .suo 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Boost.Filesystem 2 | 3 | Boost.Filesystem, part of collection of the [Boost C++ Libraries](https://github.com/boostorg), provides facilities to manipulate files and directories, and the paths that identify them. 4 | 5 | ### Directories 6 | 7 | * **doc** - Documentation sources 8 | * **include** - Interface headers of Boost.Filesystem 9 | * **src** - Compilable source files of Boost.Filesystem 10 | * **test** - Boost.Filesystem unit tests 11 | * **example** - Boost.Filesystem usage examples 12 | 13 | ### More information 14 | 15 | * [Documentation](https://boost.org/libs/filesystem) 16 | * [Report bugs](https://github.com/boostorg/filesystem/issues/new). Be sure to mention Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well. 17 | * Submit your patches as [pull requests](https://github.com/boostorg/filesystem/compare) against **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt). 18 | 19 | ### Build status 20 | 21 | Branch | GitHub Actions | AppVeyor | Test Matrix | Dependencies | 22 | :-------------: | -------------- | -------- | ----------- | ------------ | 23 | [`master`](https://github.com/boostorg/filesystem/tree/master) | [![GitHub Actions](https://github.com/boostorg/filesystem/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/boostorg/filesystem/actions?query=branch%3Amaster) | [![AppVeyor](https://ci.appveyor.com/api/projects/status/nx3e7bcavvn3q953/branch/master?svg=true)](https://ci.appveyor.com/project/Lastique/filesystem/branch/master) | [![Tests](https://img.shields.io/badge/matrix-master-brightgreen.svg)](http://www.boost.org/development/tests/master/developer/filesystem.html) | [![Dependencies](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/filesystem.html) 24 | [`develop`](https://github.com/boostorg/filesystem/tree/develop) | [![GitHub Actions](https://github.com/boostorg/filesystem/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/boostorg/filesystem/actions?query=branch%3Adevelop) | [![AppVeyor](https://ci.appveyor.com/api/projects/status/nx3e7bcavvn3q953/branch/develop?svg=true)](https://ci.appveyor.com/project/Lastique/filesystem/branch/develop) | [![Tests](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](http://www.boost.org/development/tests/develop/developer/filesystem.html) | [![Dependencies](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/filesystem.html) 25 | 26 | ### License 27 | 28 | Distributed under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt). 29 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2016, 2017 Peter Dimov 2 | # Copyright 2019-2022 Andrey Semashev 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 5 | 6 | version: 1.0.{build}-{branch} 7 | 8 | shallow_clone: true 9 | 10 | branches: 11 | only: 12 | - master 13 | - develop 14 | - /feature\/.*/ 15 | 16 | environment: 17 | matrix: 18 | - TOOLSET: msvc-14.0 19 | ADDRMD: 32,64 20 | EXTRA_TESTS: 1 21 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 22 | - TOOLSET: msvc-14.1 23 | CXXSTD: 14,17,latest 24 | ADDRMD: 32,64 25 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 26 | - TOOLSET: msvc-14.2 27 | ADDRMD: 32,64 28 | CXXSTD: 14,17,20,latest 29 | THREADING: single,multi 30 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 31 | - TOOLSET: msvc-14.3 32 | ADDRMD: 32,64 33 | CXXSTD: 14,17,20,latest 34 | THREADING: single,multi 35 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 36 | - TOOLSET: clang-win 37 | ADDRMD: 32 38 | CXXSTD: 14,17,latest 39 | ENV_SCRIPT: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat 40 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 41 | - TOOLSET: clang-win 42 | ADDRMD: 64 43 | CXXSTD: 14,17,latest 44 | ENV_SCRIPT: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat 45 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 46 | - TOOLSET: gcc 47 | CXXSTD: 11,14,1z 48 | ADDPATH: C:\cygwin\bin; 49 | THREADING: single,multi 50 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 51 | - TOOLSET: gcc 52 | CXXSTD: 11,14,1z 53 | ADDPATH: C:\cygwin64\bin; 54 | EXTRA_TESTS: 1 55 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 56 | - TOOLSET: gcc 57 | CXXSTD: 11,14,1z 58 | ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin; 59 | EXTRA_TESTS: 1 60 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 61 | - TOOLSET: gcc 62 | CXXSTD: 11,14,17 63 | ADDPATH: C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin; 64 | THREADING: single,multi 65 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 66 | - TOOLSET: gcc 67 | CXXSTD: 11,14,17,2a 68 | ADDPATH: C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin; 69 | THREADING: single,multi 70 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 71 | - TEST_CMAKE: 1 72 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 73 | 74 | install: 75 | - set GIT_FETCH_JOBS=8 76 | - set BOOST_BRANCH=develop 77 | - if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master 78 | - cd .. 79 | - git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root 80 | - cd boost-root 81 | - git submodule init tools/build 82 | - git submodule init tools/boostdep 83 | - git submodule init tools/boost_install 84 | - git submodule init libs/headers 85 | - git submodule init libs/config 86 | - git submodule update --jobs %GIT_FETCH_JOBS% 87 | - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\filesystem 88 | - if not "%EXTRA_TESTS%" == "" set DEPINST_ARG_INCLUDE_EXAMPLES="--include=example" 89 | - python tools/boostdep/depinst/depinst.py %DEPINST_ARG_INCLUDE_EXAMPLES% --git_args "--jobs %GIT_FETCH_JOBS%" filesystem 90 | - cmd /c bootstrap 91 | - b2 -d0 headers 92 | 93 | build: off 94 | 95 | test_script: 96 | - PATH=%ADDPATH%%PATH% 97 | - if not "%ENV_SCRIPT%" == "" call "%ENV_SCRIPT%" 98 | - if not "%EXTRA_TESTS%" == "" set BOOST_FILESYSTEM_TEST_WITH_EXAMPLES=1 99 | - if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD% 100 | - if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD% 101 | - if not "%THREADING%" == "" set THREADING=threading=%THREADING% 102 | - b2 -j %NUMBER_OF_PROCESSORS% libs/filesystem/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% %THREADING% 103 | 104 | for: 105 | - matrix: 106 | only: [TEST_CMAKE: 1] 107 | test_script: 108 | - mkdir __build_static__ 109 | - cd __build_static__ 110 | - cmake ../libs/filesystem/test/test_cmake 111 | - cmake --build . --target boost_filesystem_cmake_self_test -j %NUMBER_OF_PROCESSORS% 112 | - cd .. 113 | - mkdir __build_shared__ 114 | - cd __build_shared__ 115 | - cmake -DBUILD_SHARED_LIBS=On ../libs/filesystem/test/test_cmake 116 | - cmake --build . --target boost_filesystem_cmake_self_test -j %NUMBER_OF_PROCESSORS% 117 | -------------------------------------------------------------------------------- /bug/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Boost Filesystem Library Bug report Jamfile 2 | 3 | # Copyright Beman Dawes 2014 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # See www.boost.org/LICENSE_1_0.txt 6 | 7 | # Library home page: http://www.boost.org/libs/filesystem 8 | 9 | project 10 | : requirements 11 | /boost/filesystem//boost_filesystem 12 | ; 13 | 14 | exe bug : bug.cpp : static ; 15 | 16 | # install in ./bin; invoke via "b2", not "b2 install" 17 | install bin : bug ; 18 | -------------------------------------------------------------------------------- /bug/bug.cpp: -------------------------------------------------------------------------------- 1 | // filesystem/bug/bug.cpp 2 | 3 | #include 4 | #include 5 | 6 | namespace fs = boost::filesystem; 7 | 8 | int test_main(int, char*[]) // note name 9 | { 10 | BOOST_TEST(2 + 2 == 5); // one convertible-to-bool argument 11 | BOOST_TEST_EQ(4 + 4, 9); // two EqualityComparible arguments 12 | BOOST_TEST(fs::exists(".")); // should pass, so nothing reported 13 | 14 | return ::boost::report_errors(); // required 15 | } 16 | 17 | // Copyright Beman Dawes 2014 18 | // Distributed under the Boost Software License, Version 1.0. 19 | // www.boost.org/LICENSE_1_0.txt 20 | -------------------------------------------------------------------------------- /bug/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Automatic redirection failed, please go to 7 | ../doc/issue_reporting.html. 8 |
9 |

© Copyright Beman Dawes, 2014

10 |

Distributed under the Boost Software License, Version 1.0. 11 | See http://www.boost.org/LICENSE_1_0.txt

12 | 13 | 14 | -------------------------------------------------------------------------------- /build.jam: -------------------------------------------------------------------------------- 1 | # Copyright René Ferdinand Rivera Morell 2023-2024 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | require-b2 5.2 ; 7 | 8 | constant boost_dependencies : 9 | /boost/assert//boost_assert 10 | /boost/config//boost_config 11 | /boost/container_hash//boost_container_hash 12 | /boost/detail//boost_detail 13 | /boost/io//boost_io 14 | /boost/iterator//boost_iterator 15 | /boost/smart_ptr//boost_smart_ptr 16 | /boost/system//boost_system 17 | /boost/type_traits//boost_type_traits ; 18 | 19 | project /boost/filesystem 20 | : common-requirements 21 | include 22 | ; 23 | 24 | explicit 25 | [ alias boost_filesystem : build//boost_filesystem ] 26 | [ alias all : boost_filesystem example test ] 27 | ; 28 | 29 | call-if : boost-library filesystem 30 | : install boost_filesystem 31 | ; 32 | 33 | -------------------------------------------------------------------------------- /cmake/BoostLibraryIncludes.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Andrey Semashev 2 | # 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 5 | # 6 | # After including this module, BOOST_LIBRARY_INCLUDES variable is set to the list of include 7 | # directories for all Boost libraries. If the monolithic include directory is found, it is 8 | # used instead. 9 | 10 | if (NOT CMAKE_VERSION VERSION_LESS 3.10) 11 | include_guard() 12 | endif() 13 | 14 | # Generates a list of include paths for all Boost libraries in \a result variable. Uses unified Boost include tree, if available. 15 | function(generate_boost_include_paths result) 16 | if (IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../../../boost" AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../../boost/version.hpp") 17 | get_filename_component(include_dir "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE) 18 | set(${result} "${include_dir}" PARENT_SCOPE) 19 | return() 20 | endif() 21 | file(GLOB path_list LIST_DIRECTORIES True "${CMAKE_CURRENT_LIST_DIR}/../../../libs/*") 22 | foreach(path IN LISTS path_list) 23 | if (IS_DIRECTORY "${path}/include") 24 | get_filename_component(include_dir "${path}/include" ABSOLUTE) 25 | list(APPEND include_list "${include_dir}") 26 | endif() 27 | endforeach() 28 | set(${result} ${include_list} PARENT_SCOPE) 29 | endfunction() 30 | 31 | if (NOT DEFINED BOOST_LIBRARY_INCLUDES) 32 | generate_boost_include_paths(__BOOST_LIBRARY_INCLUDES) 33 | # Save the paths in a global property to avoid scanning the filesystem if this module is used in multiple libraries 34 | set(BOOST_LIBRARY_INCLUDES ${__BOOST_LIBRARY_INCLUDES} CACHE INTERNAL "List of all Boost library include paths") 35 | unset(__BOOST_LIBRARY_INCLUDES) 36 | # message(STATUS "Boost library includes: ${BOOST_LIBRARY_INCLUDES}") 37 | endif() 38 | -------------------------------------------------------------------------------- /config/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright Andrey Semashev 2020 - 2021. 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # (See accompanying file LICENSE_1_0.txt or copy at 5 | # http://www.boost.org/LICENSE_1_0.txt) 6 | # 7 | 8 | obj has_attribute_init_priority : has_attribute_init_priority.cpp : ../src ; 9 | explicit has_attribute_init_priority ; 10 | obj has_cxx20_atomic_ref : has_cxx20_atomic_ref.cpp : ../src ; 11 | explicit has_cxx20_atomic_ref ; 12 | obj has_stat_st_blksize : has_stat_st_blksize.cpp : ../src ; 13 | explicit has_stat_st_blksize ; 14 | obj has_stat_st_mtim : has_stat_st_mtim.cpp : ../src ; 15 | explicit has_stat_st_mtim ; 16 | obj has_stat_st_mtimensec : has_stat_st_mtimensec.cpp : ../src ; 17 | explicit has_stat_st_mtimensec ; 18 | obj has_stat_st_mtimespec : has_stat_st_mtimespec.cpp : ../src ; 19 | explicit has_stat_st_mtimespec ; 20 | obj has_statx : has_statx.cpp : ../src ; 21 | explicit has_statx ; 22 | obj has_statx_syscall : has_statx_syscall.cpp : ../src ; 23 | explicit has_statx_syscall ; 24 | obj has_stat_st_birthtim : has_stat_st_birthtim.cpp : ../src ; 25 | explicit has_stat_st_birthtim ; 26 | obj has_stat_st_birthtimensec : has_stat_st_birthtimensec.cpp : ../src ; 27 | explicit has_stat_st_birthtimensec ; 28 | obj has_stat_st_birthtimespec : has_stat_st_birthtimespec.cpp : ../src ; 29 | explicit has_stat_st_birthtimespec ; 30 | obj has_fdopendir_nofollow : has_fdopendir_nofollow.cpp : ../src ; 31 | explicit has_fdopendir_nofollow ; 32 | obj has_dirent_d_type : has_dirent_d_type.cpp : ../src ; 33 | explicit has_dirent_d_type ; 34 | obj has_posix_at_apis : has_posix_at_apis.cpp : ../src ; 35 | explicit has_posix_at_apis ; 36 | obj has_fallocate : has_fallocate.cpp : ../src ; 37 | explicit has_fallocate ; 38 | 39 | searched-lib bcrypt ; 40 | explicit bcrypt ; 41 | 42 | exe has_bcrypt : has_bcrypt.cpp : ../src bcrypt ; 43 | explicit has_bcrypt ; 44 | obj is_windows_ce : is_windows_ce.cpp ; 45 | explicit is_windows_ce ; 46 | 47 | lib has_linkflag_no_undefined : has_linkflag_no_undefined.cpp : shared "-Wl,--no-undefined" ; 48 | explicit has_linkflag_no_undefined ; 49 | lib has_linkflag_undefined_error : has_linkflag_no_undefined.cpp : shared "-Wl,-undefined,error" ; 50 | explicit has_linkflag_undefined_error ; 51 | -------------------------------------------------------------------------------- /config/has_attribute_init_priority.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | struct global_class 9 | { 10 | global_class() {} 11 | ~global_class() {} 12 | }; 13 | 14 | __attribute__ ((init_priority(32767))) 15 | global_class g_object; 16 | 17 | int main() 18 | { 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /config/has_bcrypt.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | // Include platform_config.hpp first so that windows.h is guaranteed to be not included 9 | #include "platform_config.hpp" 10 | 11 | #include 12 | #include 13 | #if !BOOST_OS_WINDOWS && !BOOST_OS_CYGWIN 14 | #error "This config test is for Windows only" 15 | #endif 16 | 17 | #include 18 | #include 19 | #if !(BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 && BOOST_WINAPI_PARTITION_APP_SYSTEM) 20 | #error "No BCrypt API" 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | int main() 28 | { 29 | unsigned char buf[16] = {}; 30 | boost::winapi::BCRYPT_ALG_HANDLE_ handle; 31 | boost::winapi::NTSTATUS_ status = boost::winapi::BCryptOpenAlgorithmProvider(&handle, boost::winapi::BCRYPT_RNG_ALGORITHM_, NULL, 0); 32 | status = boost::winapi::BCryptGenRandom(handle, reinterpret_cast< boost::winapi::PUCHAR_ >(static_cast< unsigned char* >(buf)), static_cast< boost::winapi::ULONG_ >(sizeof(buf)), 0); 33 | boost::winapi::BCryptCloseAlgorithmProvider(handle, 0); 34 | } 35 | -------------------------------------------------------------------------------- /config/has_cxx20_atomic_ref.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include 9 | 10 | typedef void func_t(); 11 | 12 | int main() 13 | { 14 | func_t* func = 0; 15 | std::atomic_ref< func_t* > ref(func); 16 | ref.load(std::memory_order_relaxed); 17 | ref.store((func_t*)0, std::memory_order_relaxed); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /config/has_dirent_d_type.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | 13 | int main() 14 | { 15 | DIR* dir = opendir("."); 16 | dirent* ent = readdir(dir); 17 | switch (ent->d_type) 18 | { 19 | case DT_REG: 20 | break; 21 | case DT_DIR: 22 | break; 23 | case DT_LNK: 24 | break; 25 | case DT_SOCK: 26 | break; 27 | case DT_FIFO: 28 | break; 29 | case DT_BLK: 30 | break; 31 | case DT_CHR: 32 | break; 33 | case DT_UNKNOWN: 34 | break; 35 | default: 36 | break; 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /config/has_fallocate.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | int fd = open("file.txt", O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); 17 | int err = fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, 4096); 18 | return err != 0; 19 | } 20 | -------------------------------------------------------------------------------- /config/has_fdopendir_nofollow.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | int main() 16 | { 17 | int fd = open(".", O_DIRECTORY | O_RDONLY | O_NOFOLLOW); 18 | DIR* dir = fdopendir(fd); 19 | // Note: dirfd is a macro on FreeBSD 9 and older 20 | int internal_fd = dirfd(dir); 21 | return dir != 0 && internal_fd >= 0; 22 | } 23 | -------------------------------------------------------------------------------- /config/has_linkflag_no_undefined.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #if defined(_MSC_VER) 9 | // MSVC's link.exe does not support -Wl,... flags, but doesn't fail the linking. 10 | // The linker may be used by different compilers, not only MSVC. 11 | // Luckily, those compilers all pretend to be MSVC. 12 | #error "MSVC and compatible compilers don't support -Wl,... flags" 13 | #endif 14 | 15 | #if defined(__OpenBSD__) 16 | // On OpenBSD, shared libraries are not linked to libc, as there are multiple 17 | // libc versions installed, and loading multiple different versions into the 18 | // process is considered dangerous. Only the main executable is linked against 19 | // one of them, which will be used by all shared libraries loaded into the 20 | // process. This renders -Wl,--no-undefined unusable for shared libraries. 21 | #error "-Wl,--no-undefined is broken for shared libraries on OpenBSD" 22 | #endif 23 | 24 | int main() 25 | { 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /config/has_posix_at_apis.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | int main() 17 | { 18 | int fd1 = openat(AT_FDCWD, "foo", O_DIRECTORY | O_RDONLY); 19 | int fd2 = openat(fd1, "bar", O_DIRECTORY | O_RDONLY); 20 | int res = unlinkat(fd2, "zoo", 0); 21 | res |= unlinkat(fd1, "bar", AT_REMOVEDIR); 22 | res |= renameat(AT_FDCWD, "x", fd1, "y"); 23 | 24 | struct stat st; 25 | res |= fstatat(fd1, "y", &st, AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW); 26 | 27 | res |= linkat(fd1, "y", fd1, "z", 0); 28 | res |= symlinkat("foo/z", fd1, "sz"); 29 | 30 | char buf[128u]; 31 | res |= readlinkat(fd1, "sz", buf, sizeof(buf)); 32 | 33 | res |= mkdirat(fd1, "dir", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); 34 | 35 | res |= fchmodat(fd1, "x", S_IRUSR | S_IWUSR, 0); 36 | 37 | struct timespec times[2] = {}; 38 | res |= utimensat(fd1, "x", times, AT_SYMLINK_NOFOLLOW); 39 | 40 | return res != 0; 41 | } 42 | -------------------------------------------------------------------------------- /config/has_stat_st_birthtim.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | struct stat st; 17 | st.st_birthtim.tv_sec = 1; 18 | st.st_birthtim.tv_nsec = 10; 19 | } 20 | -------------------------------------------------------------------------------- /config/has_stat_st_birthtimensec.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | struct stat st; 17 | st.st_birthtime = 1; 18 | st.st_birthtimensec = 10; 19 | } 20 | -------------------------------------------------------------------------------- /config/has_stat_st_birthtimespec.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | struct stat st; 17 | st.st_birthtimespec.tv_sec = 1; 18 | st.st_birthtimespec.tv_nsec = 10; 19 | } 20 | -------------------------------------------------------------------------------- /config/has_stat_st_blksize.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | struct stat st; 17 | st.st_blksize = 10; 18 | } 19 | -------------------------------------------------------------------------------- /config/has_stat_st_mtim.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | struct stat st; 17 | st.st_mtim.tv_nsec = 10; 18 | } 19 | -------------------------------------------------------------------------------- /config/has_stat_st_mtimensec.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | struct stat st; 17 | st.st_mtimensec = 10; 18 | } 19 | -------------------------------------------------------------------------------- /config/has_stat_st_mtimespec.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | struct stat st; 17 | st.st_mtimespec.tv_nsec = 10; 18 | } 19 | -------------------------------------------------------------------------------- /config/has_statx.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | int main() 16 | { 17 | struct statx st; 18 | int res = statx(AT_FDCWD, ".", AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, STATX_BTIME, &st); 19 | st.stx_btime.tv_sec = 1; 20 | st.stx_btime.tv_nsec = 10; 21 | } 22 | -------------------------------------------------------------------------------- /config/has_statx_syscall.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #include "platform_config.hpp" 9 | 10 | #include 11 | #include 12 | 13 | // Note: Include other libc headers for stat() as well to ensure there is no conflict between 14 | // Linux kernel headers and libc headers. 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #if defined(__ANDROID__) && (__ANDROID_API__ < 30) 21 | // Even though statx syscall number is defined, it is blacklisted by seccomp in runtime until Android 11 22 | #error "statx syscall is not supported until Android 11" 23 | #endif 24 | 25 | #if !defined(__NR_statx) 26 | #error "No statx syscall" 27 | #endif 28 | 29 | int main() 30 | { 31 | struct statx st; 32 | int res = syscall(__NR_statx, AT_FDCWD, ".", AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, STATX_BTIME, &st); 33 | st.stx_btime.tv_sec = 1; 34 | st.stx_btime.tv_nsec = 10; 35 | } 36 | -------------------------------------------------------------------------------- /config/is_windows_ce.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Andrey Semashev 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | // See library home page at http://www.boost.org/libs/filesystem 7 | 8 | #if !defined(_WIN32_WCE) 9 | #error "This is not Windows CE" 10 | #endif 11 | 12 | int main() 13 | { 14 | } 15 | -------------------------------------------------------------------------------- /doc/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Boost Filesystem Library Example Jamfile 2 | 3 | # Copyright Beman Dawes 2010 4 | 5 | # Distributed under the Boost Software License, Version 1.0. 6 | # See www.boost.org/LICENSE_1_0.txt 7 | 8 | # Library home page: http://www.boost.org/libs/filesystem 9 | 10 | project 11 | : requirements 12 | /boost/filesystem//boost_filesystem 13 | static 14 | ; 15 | 16 | exe path_table : path_table.cpp ; 17 | install path_table-copy : path_table : . ; 18 | 19 | ############################################################################### 20 | alias boostdoc ; 21 | explicit boostdoc ; 22 | alias boostrelease ; 23 | explicit boostrelease ; 24 | -------------------------------------------------------------------------------- /doc/POSIX_filename_encoding.txt: -------------------------------------------------------------------------------- 1 | http://www.linuxfromscratch.org/blfs/view/svn/introduction/locale-issues.html 2 | 3 | "The POSIX standard mandates that the filename encoding is the encoding implied by the current LC_CTYPE locale category." 4 | 5 | ------- 6 | 7 | http://mail.nl.linux.org/linux-utf8/2001-02/msg00103.html 8 | 9 | From: Markus Kuhn 10 | 11 | Tom Tromey wrote on 2001-02-05 00:36 UTC: 12 | > Kai> IMAO, a *real* filesystem should use some encoding of ISO 10646 - 13 | > Kai> UTF-8, UTF-16, or UTF-32 are all viable options. The same should 14 | > Kai> be true for the kernel filename interfaces. 15 | > 16 | > I like this, but what should I do right now? 17 | 18 | The POSIX kernel file system interface is engraved into stone and 19 | extremely unlikely to change. File names are arbitrary binary strings, 20 | with only the '/' and '\0' bytes having any special semantics. You can 21 | use arbitrary coded character sets on it as long as they do not 22 | introduce '/' and '\0' bytes spuriously. Writers and readers have to 23 | somehow agree on what encoding to use and the only really practical way 24 | is to use the same encoding on all systems that share files. Eventually, 25 | everyone will be using UTF-8 for file names on POSIX systems. Right now, 26 | I would recommend users to use only ASCII for filenames, as this is 27 | already UTF-8 and therefore simplifies migration. Using the ISO 8859, 28 | JIS, etc. filenames should soon be considered deprecated practice. 29 | 30 | > I work on libgcj, the runtime component of gcj, the Java front end to 31 | > GCC. In libgcj of course we use UCS-2 everywhere, since that is what 32 | > Java does. Currently, for Unixy systems, we assume that all file 33 | > names are UTF-8. 34 | 35 | The best solution is to assume that the file names are in the 36 | locale-specific multi-byte encoding. Simply use mbrtowc and wcrtomb to 37 | convert between Unicode and the locale-dependent multi-byte encoding 38 | used in file names and text files if the ISO C 99 symbol 39 | __STDC_ISO_10646__ is defined (which guarantees that wchar_t = UCS). On 40 | Linux, this has been the case since glibc 2.2. 41 | 42 | > (Actually, we do something notably worse, which is 43 | > assume that file names are Java-style UTF-8, with the weird encoding 44 | > for \u0000.) 45 | 46 | \u0000 = NUL was never a character allowed in filenames under POSIX. 47 | Raise an exception if someone tries to use it in a filename. Problem 48 | solved. 49 | 50 | I never understood, why Java found it necessary to introduce two 51 | distinct ASCII NUL characters. 52 | 53 | ------ 54 | 55 | Interesting idea. Use iconv to create shift-jis or other mbcs test cases. 56 | -------------------------------------------------------------------------------- /doc/path_table.txt: -------------------------------------------------------------------------------- 1 | # Paths for the reference.html Path Decomposition Table 2 | # 3 | # This is the input file for path_table, which generates the actual html 4 | # 5 | # Copyright Beman Dawes 2010 6 | # 7 | # Distributed under the Boost Software License, Version 1.0. 8 | # See www.boost.org/LICENSE_1_0.txt 9 | # 10 | # Note that an empty line is treated as input rather than as a comment 11 | 12 | . 13 | .. 14 | foo 15 | / 16 | /foo 17 | foo/ 18 | /foo/ 19 | foo/bar 20 | /foo/bar 21 | //net 22 | //net/foo 23 | ///foo/// 24 | ///foo///bar 25 | /. 26 | ./ 27 | /.. 28 | ../ 29 | foo/. 30 | foo/.. 31 | foo/./ 32 | foo/./bar 33 | foo/.. 34 | foo/../ 35 | foo/../bar 36 | c: 37 | c:/ 38 | c:foo 39 | c:/foo 40 | c:foo/ 41 | c:/foo/ 42 | c:/foo/bar 43 | prn: 44 | c:\ 45 | c:foo 46 | c:\foo 47 | c:foo\ 48 | c:\foo\ 49 | c:\foo/ 50 | c:/foo\bar 51 | -------------------------------------------------------------------------------- /doc/styles.css: -------------------------------------------------------------------------------- 1 | body 2 | { 3 | font-family: arial, sans-serif; 4 | max-width: 90%; 5 | margin: 0px auto; 6 | } 7 | ins {background-color: #CCFFCC; text-decoration: none;} 8 | del {background-color: #FFCACA; text-decoration: none;} 9 | pre {background-color: #D7EEFF; font-family: "Courier New", "Courier", monospace;} 10 | code {font-size: 110%; font-family: "Courier New", "Courier", monospace;} 11 | table {font-size: 90%;} 12 | 13 | /* 14 | * (c) Copyright Beman Dawes, 2014 15 | * (c) Copyright Andrey Semashev, 2021 16 | * Distributed under the Boost Software License, Version 1.0. 17 | * See www.boost.org/LICENSE_1_0.txt 18 | */ 19 | -------------------------------------------------------------------------------- /doc/tickets.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Filesystem Tickets 9 | 10 | 11 | 12 | 13 |

 

14 |

Locale related

15 |

#3332 16 | boost::filesystem::path will get trouble in locale Chinese_Taiwan.950 (windows)
17 | #7211 path_locale 18 | destructor crashes when overloaded operator new and delete are present
19 | #8388 20 | windows_file_codecvt should be allocated with _NEW_CRT
21 | #8642 Global locale 22 | prevents from using Boost.Filesystem in global constructors and destructors
23 | #8930 24 | boost::path::root_directory() throws locale::facet::_S_create_c_locale name not 25 | valid
26 | #9182 27 | Boost-filesystem std::runtime_error: locale::facet::_S_create_c_locale name not 28 | valid failure on Xamarin.Android
29 | #9219 path::codecvt() 30 | is called when not required
31 | #9560 32 | operations_test_static unit test crashes during static initialization phase on 33 | Mac/10.7/32-bit/darwin-4.2.1
34 | #10205 FileSystem 35 | runtime error: locale::facet::_S_create_c_locale name not valid
36 |
37 |  

38 |

TR alignment

39 |

Work has started to bring the library into alignment with the C++ File System 40 | Technical Specification (HTML) 41 | (PDF). 42 | This work is occurring on the 43 | git 44 | ts-develop branch, and is currently very unstable.

45 |
    46 |
  • #10291 path 47 | doesn't have move constructor/assignment operator.
  • 48 |
49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | tut1 4 | tut2 5 | tut3 6 | tut4 7 | tut5 8 | path_info 9 | -------------------------------------------------------------------------------- /example/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Boost Filesystem Library Example Jamfile 2 | 3 | # (C) Copyright Vladimir Prus 2003 4 | 5 | # Distributed under the Boost Software License, Version 1.0. 6 | # See www.boost.org/LICENSE_1_0.txt 7 | 8 | # Library home page: http://www.boost.org/libs/filesystem 9 | 10 | project 11 | : requirements 12 | /boost/filesystem//boost_filesystem 13 | static 14 | ; 15 | 16 | exe tut0 : tut0.cpp ; 17 | exe tut1 : tut1.cpp ; 18 | exe tut2 : tut2.cpp ; 19 | exe tut3 : tut3.cpp : 11 ; 20 | exe tut4 : tut4.cpp : 11 ; 21 | exe tut5 : tut5.cpp ; 22 | exe tut6a : tut6a.cpp ; 23 | exe tut6b : tut6b.cpp ; 24 | exe tut6c : tut6c.cpp ; 25 | exe path_info : path_info.cpp : 11 ; 26 | exe file_status : file_status.cpp ; 27 | exe file_size : file_size.cpp ; 28 | exe simple_ls : simple_ls.cpp ; 29 | 30 | install tut1-copy : tut1 : . ; 31 | install tut2-copy : tut2 : . ; 32 | install tut3-copy : tut3 : . ; 33 | install tut4-copy : tut4 : . ; 34 | install tut5-copy : tut5 : . ; 35 | install tut6a-copy : tut6a : . ; 36 | install tut6b-copy : tut6b : . ; 37 | install tut6c-copy : tut6c : . ; 38 | install path_info-copy : path_info : . ; 39 | 40 | alias tutorial : tut1-copy tut2-copy tut3-copy tut4-copy tut5-copy tut6a-copy tut6b-copy tut6c-copy path_info-copy ; 41 | explicit tut1-copy tut2-copy tut3-copy tut4-copy tut5-copy tut6a-copy tut6b-copy tut6c-copy path_info-copy tutorial ; 42 | -------------------------------------------------------------------------------- /example/error_demo.cpp: -------------------------------------------------------------------------------- 1 | // error_demo.cpp --------------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2009 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | // // 12 | // The purpose of this program is to demonstrate how error reporting works. // 13 | // // 14 | //--------------------------------------------------------------------------------------// 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | using std::cout; 21 | using boost::filesystem::path; 22 | using boost::filesystem::filesystem_error; 23 | using boost::system::error_code; 24 | using boost::system::system_error; 25 | namespace fs = boost::filesystem; 26 | 27 | namespace { 28 | void report_system_error(const system_error& ex) 29 | { 30 | cout << " threw system_error:\n" 31 | << " ex.code().value() is " << ex.code().value() << '\n' 32 | << " ex.code().category().name() is " << ex.code().category().name() << '\n' 33 | << " ex.what() is " << ex.what() << '\n'; 34 | } 35 | 36 | void report_filesystem_error(const system_error& ex) 37 | { 38 | cout << " threw filesystem_error exception:\n" 39 | << " ex.code().value() is " << ex.code().value() << '\n' 40 | << " ex.code().category().name() is " << ex.code().category().name() << '\n' 41 | << " ex.what() is " << ex.what() << '\n'; 42 | } 43 | 44 | void report_status(fs::file_status s) 45 | { 46 | cout << " file_status::type() is "; 47 | switch (s.type()) 48 | { 49 | case fs::status_error: 50 | cout << "status_error\n"; 51 | break; 52 | case fs::file_not_found: 53 | cout << "file_not_found\n"; 54 | break; 55 | case fs::regular_file: 56 | cout << "regular_file\n"; 57 | break; 58 | case fs::directory_file: 59 | cout << "directory_file\n"; 60 | break; 61 | case fs::symlink_file: 62 | cout << "symlink_file\n"; 63 | break; 64 | case fs::block_file: 65 | cout << "block_file\n"; 66 | break; 67 | case fs::character_file: 68 | cout << "character_file\n"; 69 | break; 70 | case fs::fifo_file: 71 | cout << "fifo_file\n"; 72 | break; 73 | case fs::socket_file: 74 | cout << "socket_file\n"; 75 | break; 76 | case fs::type_unknown: 77 | cout << "type_unknown\n"; 78 | break; 79 | default: 80 | cout << "not a valid enumeration constant\n"; 81 | } 82 | } 83 | 84 | void report_error_code(const error_code& ec) 85 | { 86 | cout << " ec:\n" 87 | << " value() is " << ec.value() << '\n' 88 | << " category().name() is " << ec.category().name() << '\n' 89 | << " message() is " << ec.message() << '\n'; 90 | } 91 | 92 | bool threw_exception; 93 | 94 | } // namespace 95 | 96 | int main(int argc, char* argv[]) 97 | { 98 | if (argc < 2) 99 | { 100 | cout << "Usage: error_demo path\n"; 101 | return 1; 102 | } 103 | 104 | error_code ec; 105 | 106 | //// construct path - no error_code 107 | 108 | //try { path p1(argv[1]); } 109 | //catch (const system_error& ex) 110 | //{ 111 | // cout << "construct path without error_code"; 112 | // report_system_error(ex); 113 | //} 114 | 115 | //// construct path - with error_code 116 | 117 | path p(argv[1]); 118 | 119 | fs::file_status s; 120 | bool b(false); 121 | fs::directory_iterator di; 122 | 123 | // get status - no error_code 124 | 125 | cout << "\nstatus(\"" << p.string() << "\");\n"; 126 | threw_exception = false; 127 | 128 | try 129 | { 130 | s = fs::status(p); 131 | } 132 | catch (const system_error& ex) 133 | { 134 | report_filesystem_error(ex); 135 | threw_exception = true; 136 | } 137 | if (!threw_exception) 138 | cout << " Did not throw exception\n"; 139 | report_status(s); 140 | 141 | // get status - with error_code 142 | 143 | cout << "\nstatus(\"" << p.string() << "\", ec);\n"; 144 | s = fs::status(p, ec); 145 | report_status(s); 146 | report_error_code(ec); 147 | 148 | // query existence - no error_code 149 | 150 | cout << "\nexists(\"" << p.string() << "\");\n"; 151 | threw_exception = false; 152 | 153 | try 154 | { 155 | b = fs::exists(p); 156 | } 157 | catch (const system_error& ex) 158 | { 159 | report_filesystem_error(ex); 160 | threw_exception = true; 161 | } 162 | if (!threw_exception) 163 | { 164 | cout << " Did not throw exception\n" 165 | << " Returns: " << (b ? "true" : "false") << '\n'; 166 | } 167 | 168 | // query existence - with error_code 169 | 170 | // directory_iterator - no error_code 171 | 172 | cout << "\ndirectory_iterator(\"" << p.string() << "\");\n"; 173 | threw_exception = false; 174 | 175 | try 176 | { 177 | di = fs::directory_iterator(p); 178 | } 179 | catch (const system_error& ex) 180 | { 181 | report_filesystem_error(ex); 182 | threw_exception = true; 183 | } 184 | if (!threw_exception) 185 | { 186 | cout << " Did not throw exception\n" 187 | << (di == fs::directory_iterator() ? " Equal" : " Not equal") 188 | << " to the end iterator\n"; 189 | } 190 | 191 | // directory_iterator - with error_code 192 | 193 | cout << "\ndirectory_iterator(\"" << p.string() << "\", ec);\n"; 194 | di = fs::directory_iterator(p, ec); 195 | cout << (di == fs::directory_iterator() ? " Equal" : " Not equal") 196 | << " to the end iterator\n"; 197 | report_error_code(ec); 198 | 199 | return 0; 200 | } 201 | -------------------------------------------------------------------------------- /example/file_size.cpp: -------------------------------------------------------------------------------- 1 | // file_size program -------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes, 2004 4 | 5 | // Use, modification, and distribution is subject to the Boost Software 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | // See http://www.boost.org/libs/filesystem for documentation. 10 | 11 | #include 12 | #include 13 | 14 | namespace fs = boost::filesystem; 15 | 16 | int main(int argc, char* argv[]) 17 | { 18 | 19 | if (argc != 2) 20 | { 21 | std::cout << "Usage: file_size path\n"; 22 | return 1; 23 | } 24 | 25 | std::cout << "sizeof(intmax_t) is " << sizeof(boost::intmax_t) << '\n'; 26 | 27 | fs::path p(argv[1]); 28 | 29 | if (!fs::exists(p)) 30 | { 31 | std::cout << "not found: " << argv[1] << std::endl; 32 | return 1; 33 | } 34 | 35 | if (!fs::is_regular_file(p)) 36 | { 37 | std::cout << "not a regular file: " << argv[1] << std::endl; 38 | return 1; 39 | } 40 | 41 | std::cout << "size of " << argv[1] << " is " << fs::file_size(p) 42 | << std::endl; 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /example/file_status.cpp: -------------------------------------------------------------------------------- 1 | // status.cpp ------------------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2011 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | using std::cout; 17 | using std::endl; 18 | using namespace boost::filesystem; 19 | 20 | namespace { 21 | 22 | path p; 23 | 24 | void print_boost_macros() 25 | { 26 | std::cout << "Boost " 27 | << BOOST_VERSION / 100000 << '.' 28 | << BOOST_VERSION / 100 % 1000 << '.' 29 | << BOOST_VERSION % 100 << ", " 30 | #ifndef _WIN64 31 | << BOOST_COMPILER << ", " 32 | #else 33 | << BOOST_COMPILER << " with _WIN64 defined, " 34 | #endif 35 | << BOOST_STDLIB << ", " 36 | << BOOST_PLATFORM 37 | << std::endl; 38 | } 39 | 40 | const char* file_type_tab[] = { "status_error", "file_not_found", "regular_file", "directory_file", 41 | "symlink_file", "block_file", "character_file", "fifo_file", "socket_file", 42 | "type_unknown" }; 43 | 44 | const char* file_type_c_str(enum file_type t) 45 | { 46 | return file_type_tab[t]; 47 | } 48 | 49 | void show_status(file_status s, boost::system::error_code ec) 50 | { 51 | boost::system::error_condition econd; 52 | 53 | if (ec) 54 | { 55 | econd = ec.default_error_condition(); 56 | cout << "sets ec to indicate an error:\n" 57 | << " ec.value() is " << ec.value() << '\n' 58 | << " ec.message() is \"" << ec.message() << "\"\n" 59 | << " ec.default_error_condition().value() is " << econd.value() << '\n' 60 | << " ec.default_error_condition().message() is \"" << econd.message() << "\"\n"; 61 | } 62 | else 63 | cout << "clears ec.\n"; 64 | 65 | cout << "s.type() is " << s.type() 66 | << ", which is defined as \"" << file_type_c_str(s.type()) << "\"\n"; 67 | 68 | cout << "exists(s) is " << (exists(s) ? "true" : "false") << "\n"; 69 | cout << "status_known(s) is " << (status_known(s) ? "true" : "false") << "\n"; 70 | cout << "is_regular_file(s) is " << (is_regular_file(s) ? "true" : "false") << "\n"; 71 | cout << "is_directory(s) is " << (is_directory(s) ? "true" : "false") << "\n"; 72 | cout << "is_other(s) is " << (is_other(s) ? "true" : "false") << "\n"; 73 | cout << "is_symlink(s) is " << (is_symlink(s) ? "true" : "false") << "\n"; 74 | } 75 | 76 | void try_exists() 77 | { 78 | cout << "\nexists(" << p << ") "; 79 | try 80 | { 81 | bool result = exists(p); 82 | cout << "is " << (result ? "true" : "false") << "\n"; 83 | } 84 | catch (const filesystem_error& ex) 85 | { 86 | cout << "throws a filesystem_error exception: " << ex.what() << "\n"; 87 | } 88 | } 89 | 90 | } // namespace 91 | 92 | int cpp_main(int argc, char* argv[]) 93 | { 94 | print_boost_macros(); 95 | 96 | if (argc < 2) 97 | { 98 | std::cout << "Usage: file_status \n"; 99 | p = argv[0]; 100 | } 101 | else 102 | p = argv[1]; 103 | 104 | boost::system::error_code ec; 105 | file_status s = status(p, ec); 106 | cout << "\nfile_status s = status(" << p << ", ec) "; 107 | show_status(s, ec); 108 | 109 | s = symlink_status(p, ec); 110 | cout << "\nfile_status s = symlink_status(" << p << ", ec) "; 111 | show_status(s, ec); 112 | 113 | try_exists(); 114 | 115 | return 0; 116 | } 117 | -------------------------------------------------------------------------------- /example/mbcopy.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Filesystem mbcopy.cpp ---------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2005 4 | 5 | // Use, modification, and distribution is subject to the Boost Software 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | // Copy the files in a directory, using mbpath to represent the new file names 10 | // See http://../doc/path.htm#mbpath for more information 11 | 12 | // See deprecated_test for tests of deprecated features 13 | #define BOOST_FILESYSTEM_NO_DEPRECATED 14 | 15 | #include 16 | #ifdef BOOST_FILESYSTEM_NARROW_ONLY 17 | #error This compiler or standard library does not support wide-character strings or paths 18 | #endif 19 | 20 | #include "mbpath.hpp" 21 | #include 22 | #include 23 | #include 24 | #include "../src/utf8_codecvt_facet.hpp" 25 | 26 | namespace fs = boost::filesystem; 27 | 28 | namespace { 29 | 30 | // we can't use boost::filesystem::copy_file() because the argument types 31 | // differ, so provide a not-very-smart replacement. 32 | void copy_file(const fs::wpath& from, const user::mbpath& to) 33 | { 34 | fs::ifstream from_file(from, std::ios_base::in | std::ios_base::binary); 35 | if (!from_file) 36 | { 37 | std::cout << "input open failed\n"; 38 | return; 39 | } 40 | 41 | fs::ofstream to_file(to, std::ios_base::out | std::ios_base::binary); 42 | if (!to_file) 43 | { 44 | std::cout << "output open failed\n"; 45 | return; 46 | } 47 | 48 | char c; 49 | while (from_file.get(c)) 50 | { 51 | to_file.put(c); 52 | if (to_file.fail()) 53 | { 54 | std::cout << "write error\n"; 55 | return; 56 | } 57 | } 58 | 59 | if (!from_file.eof()) 60 | { 61 | std::cout << "read error\n"; 62 | } 63 | } 64 | 65 | } // namespace 66 | 67 | int main(int argc, char* argv[]) 68 | { 69 | if (argc != 2) 70 | { 71 | std::cout << "Copy files in the current directory to a target directory\n" 72 | << "Usage: mbcopy \n"; 73 | return 1; 74 | } 75 | 76 | // For encoding, use Boost UTF-8 codecvt 77 | std::locale global_loc = std::locale(); 78 | std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet); 79 | user::mbpath_traits::imbue(loc); 80 | 81 | std::string target_string(argv[1]); 82 | user::mbpath target_dir(user::mbpath_traits::to_internal(target_string)); 83 | 84 | if (!fs::is_directory(target_dir)) 85 | { 86 | std::cout << "Error: " << argv[1] << " is not a directory\n"; 87 | return 1; 88 | } 89 | 90 | for (fs::wdirectory_iterator it(L"."); 91 | it != fs::wdirectory_iterator(); ++it) 92 | { 93 | if (fs::is_regular_file(it->status())) 94 | { 95 | copy_file(*it, target_dir / it->path().filename()); 96 | } 97 | } 98 | 99 | return 0; 100 | } 101 | -------------------------------------------------------------------------------- /example/mbpath.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Filesystem mbpath.cpp ---------------------------------------------// 2 | 3 | // (c) Copyright Beman Dawes 2005 4 | 5 | // Use, modification, and distribution is subject to the Boost Software 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | // See Boost.Filesystem home page at http://www.boost.org/libs/filesystem 10 | 11 | #include 12 | #ifdef BOOST_FILESYSTEM_NARROW_ONLY 13 | #error This compiler or standard library does not support wide-character strings or paths 14 | #endif 15 | 16 | #include "mbpath.hpp" 17 | #include 18 | #include 19 | 20 | namespace fs = boost::filesystem; 21 | 22 | namespace { 23 | 24 | // ISO C calls this "the locale-specific native environment": 25 | std::locale loc(""); 26 | 27 | const std::codecvt< wchar_t, char, std::mbstate_t >* 28 | cvt(&std::use_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc)); 29 | 30 | } // namespace 31 | 32 | namespace user { 33 | 34 | mbpath_traits::external_string_type 35 | mbpath_traits::to_external(const mbpath& ph, const internal_string_type& src) 36 | { 37 | std::size_t work_size(cvt->max_length() * (src.size() + 1)); 38 | boost::scoped_array< char > work(new char[work_size]); 39 | std::mbstate_t state; 40 | const internal_string_type::value_type* from_next; 41 | external_string_type::value_type* to_next; 42 | if (cvt->out( 43 | state, src.c_str(), src.c_str() + src.size(), from_next, work.get(), 44 | work.get() + work_size, to_next) != std::codecvt_base::ok) 45 | boost::throw_exception< fs::basic_filesystem_error< mbpath > >( 46 | fs::basic_filesystem_error< mbpath >( 47 | "user::mbpath::to_external conversion error", 48 | ph, boost::system::error_code(EINVAL, boost::system::errno_ecat))); 49 | *to_next = '\0'; 50 | return external_string_type(work.get()); 51 | } 52 | 53 | mbpath_traits::internal_string_type 54 | mbpath_traits::to_internal(const external_string_type& src) 55 | { 56 | std::size_t work_size(src.size() + 1); 57 | boost::scoped_array< wchar_t > work(new wchar_t[work_size]); 58 | std::mbstate_t state; 59 | const external_string_type::value_type* from_next; 60 | internal_string_type::value_type* to_next; 61 | if (cvt->in( 62 | state, src.c_str(), src.c_str() + src.size(), from_next, work.get(), 63 | work.get() + work_size, to_next) != std::codecvt_base::ok) 64 | boost::throw_exception< fs::basic_filesystem_error< mbpath > >( 65 | fs::basic_filesystem_error< mbpath >( 66 | "user::mbpath::to_internal conversion error", 67 | boost::system::error_code(EINVAL, boost::system::errno_ecat))); 68 | *to_next = L'\0'; 69 | return internal_string_type(work.get()); 70 | } 71 | 72 | void mbpath_traits::imbue(const std::locale& new_loc) 73 | { 74 | loc = new_loc; 75 | cvt = &std::use_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc); 76 | } 77 | 78 | } // namespace user 79 | -------------------------------------------------------------------------------- /example/mbpath.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Filesystem mbpath.hpp ---------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2005 4 | 5 | // Use, modification, and distribution is subject to the Boost Software 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | // Encodes wide character paths as MBCS 10 | // See http://../doc/path.htm#mbpath for more information 11 | 12 | #include 13 | #include // for std::mbstate_t 14 | #include 15 | #include 16 | 17 | namespace user { 18 | 19 | struct mbpath_traits; 20 | 21 | typedef boost::filesystem::basic_path< std::wstring, mbpath_traits > mbpath; 22 | 23 | struct mbpath_traits 24 | { 25 | typedef std::wstring internal_string_type; 26 | typedef std::string external_string_type; 27 | 28 | static external_string_type to_external(const mbpath& ph, const internal_string_type& src); 29 | 30 | static internal_string_type to_internal(const external_string_type& src); 31 | 32 | static void imbue(const std::locale& loc); 33 | }; 34 | 35 | } // namespace user 36 | 37 | namespace boost { 38 | namespace filesystem { 39 | 40 | template<> 41 | struct is_basic_path< user::mbpath > 42 | { 43 | static const bool value = true; 44 | }; 45 | 46 | } // namespace filesystem 47 | } // namespace boost 48 | -------------------------------------------------------------------------------- /example/path_info.cpp: -------------------------------------------------------------------------------- 1 | // path_info.cpp ---------------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2009 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | using namespace boost::filesystem; 15 | 16 | const char* say_what(bool b) 17 | { 18 | return b ? "true" : "false"; 19 | } 20 | 21 | int main(int argc, char* argv[]) 22 | { 23 | if (argc < 2) 24 | { 25 | cout << "Usage: path_info path-element [path-element...]\n" 26 | "Composes a path via operator/= from one or more path-element arguments\n" 27 | "Example: path_info foo/bar baz\n" 28 | #ifdef BOOST_POSIX_API 29 | " would report info about the composed path foo/bar/baz\n"; 30 | #else // BOOST_WINDOWS_API 31 | " would report info about the composed path foo/bar\\baz\n"; 32 | #endif 33 | return 1; 34 | } 35 | 36 | path p; 37 | for (; argc > 1; --argc, ++argv) 38 | p /= argv[1]; // compose path p from the command line arguments 39 | 40 | cout << "\ncomposed path:\n"; 41 | cout << " operator<<()---------: " << p << "\n"; 42 | cout << " make_preferred()-----: " << p.make_preferred() << "\n"; 43 | 44 | cout << "\nelements:\n"; 45 | for (auto element : p) 46 | cout << " " << element << '\n'; 47 | 48 | cout << "\nobservers, native format:" << endl; 49 | #ifdef BOOST_POSIX_API 50 | cout << " native()-------------: " << p.native() << endl; 51 | cout << " c_str()--------------: " << p.c_str() << endl; 52 | #else // BOOST_WINDOWS_API 53 | wcout << L" native()-------------: " << p.native() << endl; 54 | wcout << L" c_str()--------------: " << p.c_str() << endl; 55 | #endif 56 | cout << " string()-------------: " << p.string() << endl; 57 | wcout << L" wstring()------------: " << p.wstring() << endl; 58 | 59 | cout << "\nobservers, generic format:\n"; 60 | cout << " generic_string()-----: " << p.generic_string() << endl; 61 | wcout << L" generic_wstring()----: " << p.generic_wstring() << endl; 62 | 63 | cout << "\ndecomposition:\n"; 64 | cout << " root_name()----------: " << p.root_name() << '\n'; 65 | cout << " root_directory()-----: " << p.root_directory() << '\n'; 66 | cout << " root_path()----------: " << p.root_path() << '\n'; 67 | cout << " relative_path()------: " << p.relative_path() << '\n'; 68 | cout << " parent_path()--------: " << p.parent_path() << '\n'; 69 | cout << " filename()-----------: " << p.filename() << '\n'; 70 | cout << " stem()---------------: " << p.stem() << '\n'; 71 | cout << " extension()----------: " << p.extension() << '\n'; 72 | 73 | cout << "\nquery:\n"; 74 | cout << " empty()--------------: " << say_what(p.empty()) << '\n'; 75 | cout << " is_absolute()--------: " << say_what(p.is_absolute()) << '\n'; 76 | cout << " has_root_name()------: " << say_what(p.has_root_name()) << '\n'; 77 | cout << " has_root_directory()-: " << say_what(p.has_root_directory()) << '\n'; 78 | cout << " has_root_path()------: " << say_what(p.has_root_path()) << '\n'; 79 | cout << " has_relative_path()--: " << say_what(p.has_relative_path()) << '\n'; 80 | cout << " has_parent_path()----: " << say_what(p.has_parent_path()) << '\n'; 81 | cout << " has_filename()-------: " << say_what(p.has_filename()) << '\n'; 82 | cout << " has_stem()-----------: " << say_what(p.has_stem()) << '\n'; 83 | cout << " has_extension()------: " << say_what(p.has_extension()) << '\n'; 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /example/simple_ls.cpp: -------------------------------------------------------------------------------- 1 | // simple_ls program -------------------------------------------------------// 2 | 3 | // Copyright Jeff Garland and Beman Dawes, 2002 4 | 5 | // Use, modification, and distribution is subject to the Boost Software 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | // See http://www.boost.org/libs/filesystem for documentation. 10 | 11 | // As an example program, we don't want to use any deprecated features 12 | #ifndef BOOST_FILESYSTEM_NO_DEPRECATED 13 | #define BOOST_FILESYSTEM_NO_DEPRECATED 14 | #endif 15 | #ifndef BOOST_SYSTEM_NO_DEPRECATED 16 | #define BOOST_SYSTEM_NO_DEPRECATED 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace fs = boost::filesystem; 25 | 26 | int main(int argc, char* argv[]) 27 | { 28 | fs::path p(fs::current_path()); 29 | 30 | if (argc > 1) 31 | p = fs::system_complete(argv[1]); 32 | else 33 | std::cout << "\nusage: simple_ls [path]" << std::endl; 34 | 35 | unsigned long file_count = 0; 36 | unsigned long dir_count = 0; 37 | unsigned long other_count = 0; 38 | unsigned long err_count = 0; 39 | 40 | if (!fs::exists(p)) 41 | { 42 | std::cout << "\nNot found: " << p << std::endl; 43 | return 1; 44 | } 45 | 46 | if (fs::is_directory(p)) 47 | { 48 | std::cout << "\nIn directory: " << p << "\n\n"; 49 | fs::directory_iterator end_iter; 50 | for (fs::directory_iterator dir_itr(p); 51 | dir_itr != end_iter; 52 | ++dir_itr) 53 | { 54 | try 55 | { 56 | if (fs::is_directory(dir_itr->status())) 57 | { 58 | ++dir_count; 59 | std::cout << dir_itr->path().filename() << " [directory]\n"; 60 | } 61 | else if (fs::is_regular_file(dir_itr->status())) 62 | { 63 | ++file_count; 64 | std::cout << dir_itr->path().filename() << "\n"; 65 | } 66 | else 67 | { 68 | ++other_count; 69 | std::cout << dir_itr->path().filename() << " [other]\n"; 70 | } 71 | } 72 | catch (const std::exception& ex) 73 | { 74 | ++err_count; 75 | std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl; 76 | } 77 | } 78 | std::cout << "\n" 79 | << file_count << " files\n" 80 | << dir_count << " directories\n" 81 | << other_count << " others\n" 82 | << err_count << " errors\n"; 83 | } 84 | else // must be a file 85 | { 86 | std::cout << "\nFound: " << p << "\n"; 87 | } 88 | 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /example/stems.cpp: -------------------------------------------------------------------------------- 1 | // filesystem example stems.cpp ------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2011 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | #include 12 | 13 | int main(int argc, char* argv[]) 14 | { 15 | if (argc < 2) 16 | { 17 | std::cout << "Usage: stems \n"; 18 | return 1; 19 | } 20 | 21 | boost::filesystem::path p(argv[1]), name(p.filename()); 22 | 23 | for (;;) 24 | { 25 | std::cout << "filename " << name << " has stem " << name.stem() 26 | << " and extension " << name.extension() << "\n"; 27 | if (name.stem().empty() || name.extension().empty()) 28 | return 0; 29 | name = name.stem(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /example/tchar.cpp: -------------------------------------------------------------------------------- 1 | // Example use of Microsoft TCHAR ----------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2008 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace fs = boost::filesystem; 16 | 17 | typedef std::basic_string< TCHAR > tstring; 18 | 19 | void func(fs::path const& p) 20 | { 21 | assert(fs::exists(p)); 22 | } 23 | 24 | int main() 25 | { 26 | // get a path that is known to exist 27 | fs::path cp = fs::current_path(); 28 | 29 | // demo: get tstring from the path 30 | tstring cp_as_tstring = cp.string< tstring >(); 31 | 32 | // demo: pass tstring to filesystem function taking path 33 | assert(fs::exists(cp_as_tstring)); 34 | 35 | // demo: pass tstring to user function taking path 36 | func(cp_as_tstring); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /example/tut0.cpp: -------------------------------------------------------------------------------- 1 | // filesystem tut0.cpp ---------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2009 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | #include 12 | 13 | namespace fs = boost::filesystem; 14 | 15 | int main(int argc, char* argv[]) 16 | { 17 | if (argc < 2) 18 | { 19 | std::cout << "Usage: tut0 path\n"; 20 | return 1; 21 | } 22 | std::cout << argv[1] << '\n'; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /example/tut1.cpp: -------------------------------------------------------------------------------- 1 | // filesystem tut1.cpp ---------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2009 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | #include 12 | 13 | using namespace boost::filesystem; 14 | 15 | int main(int argc, char* argv[]) 16 | { 17 | if (argc < 2) 18 | { 19 | std::cout << "Usage: tut1 path\n"; 20 | return 1; 21 | } 22 | std::cout << argv[1] << " " << file_size(argv[1]) << '\n'; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /example/tut2.cpp: -------------------------------------------------------------------------------- 1 | // filesystem tut2.cpp ---------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2009 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | using namespace boost::filesystem; 15 | 16 | int main(int argc, char* argv[]) 17 | { 18 | if (argc < 2) 19 | { 20 | cout << "Usage: tut2 path\n"; 21 | return 1; 22 | } 23 | 24 | path p(argv[1]); // avoid repeated path construction below 25 | 26 | if (exists(p)) // does path p actually exist? 27 | { 28 | if (is_regular_file(p)) // is path p a regular file? 29 | cout << p << " size is " << file_size(p) << '\n'; 30 | else if (is_directory(p)) // is path p a directory? 31 | cout << p << " is a directory\n"; 32 | else 33 | cout << p << " exists, but is not a regular file or directory\n"; 34 | } 35 | else 36 | cout << p << " does not exist\n"; 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /example/tut3.cpp: -------------------------------------------------------------------------------- 1 | // filesystem tut3.cpp ---------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2009 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | #include 12 | 13 | using std::cout; 14 | using namespace boost::filesystem; 15 | 16 | int main(int argc, char* argv[]) 17 | { 18 | if (argc < 2) 19 | { 20 | cout << "Usage: tut3 path\n"; 21 | return 1; 22 | } 23 | 24 | path p(argv[1]); 25 | 26 | try 27 | { 28 | if (exists(p)) 29 | { 30 | if (is_regular_file(p)) 31 | { 32 | cout << p << " size is " << file_size(p) << '\n'; 33 | } 34 | else if (is_directory(p)) 35 | { 36 | cout << p << " is a directory containing:\n"; 37 | 38 | for (directory_entry const& x : directory_iterator(p)) 39 | cout << " " << x.path() << '\n'; 40 | } 41 | else 42 | cout << p << " exists, but is not a regular file or directory\n"; 43 | } 44 | else 45 | cout << p << " does not exist\n"; 46 | } 47 | catch (filesystem_error& ex) 48 | { 49 | cout << ex.what() << '\n'; 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /example/tut4.cpp: -------------------------------------------------------------------------------- 1 | // filesystem tut4.cpp ---------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2009 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using std::cout; 16 | using namespace boost::filesystem; 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | if (argc < 2) 21 | { 22 | cout << "Usage: tut4 path\n"; 23 | return 1; 24 | } 25 | 26 | path p(argv[1]); 27 | 28 | try 29 | { 30 | if (exists(p)) 31 | { 32 | if (is_regular_file(p)) 33 | { 34 | cout << p << " size is " << file_size(p) << '\n'; 35 | } 36 | else if (is_directory(p)) 37 | { 38 | cout << p << " is a directory containing:\n"; 39 | 40 | std::vector< path > v; 41 | 42 | for (auto&& x : directory_iterator(p)) 43 | v.push_back(x.path()); 44 | 45 | std::sort(v.begin(), v.end()); 46 | 47 | for (auto&& x : v) 48 | cout << " " << x.filename() << '\n'; 49 | } 50 | else 51 | cout << p << " exists, but is not a regular file or directory\n"; 52 | } 53 | else 54 | cout << p << " does not exist\n"; 55 | } 56 | catch (filesystem_error& ex) 57 | { 58 | cout << ex.what() << '\n'; 59 | } 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /example/tut5.cpp: -------------------------------------------------------------------------------- 1 | // filesystem tut5.cpp ---------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2010 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace fs = boost::filesystem; 15 | 16 | int main() 17 | { 18 | // \u263A is "Unicode WHITE SMILING FACE = have a nice day!" 19 | std::string narrow_string("smile2"); 20 | std::wstring wide_string(L"smile2\u263A"); 21 | std::list< char > narrow_list; 22 | narrow_list.push_back('s'); 23 | narrow_list.push_back('m'); 24 | narrow_list.push_back('i'); 25 | narrow_list.push_back('l'); 26 | narrow_list.push_back('e'); 27 | narrow_list.push_back('3'); 28 | std::list< wchar_t > wide_list; 29 | wide_list.push_back(L's'); 30 | wide_list.push_back(L'm'); 31 | wide_list.push_back(L'i'); 32 | wide_list.push_back(L'l'); 33 | wide_list.push_back(L'e'); 34 | wide_list.push_back(L'3'); 35 | wide_list.push_back(L'\u263A'); 36 | 37 | { 38 | fs::ofstream f("smile"); 39 | } 40 | { 41 | fs::ofstream f(L"smile\u263A"); 42 | } 43 | { 44 | fs::ofstream f(narrow_string); 45 | } 46 | { 47 | fs::ofstream f(wide_string); 48 | } 49 | { 50 | fs::ofstream f(fs::path(narrow_list.begin(), narrow_list.end())); 51 | } 52 | { 53 | fs::ofstream f(fs::path(wide_list.begin(), wide_list.end())); 54 | } 55 | narrow_list.pop_back(); 56 | narrow_list.push_back('4'); 57 | wide_list.pop_back(); 58 | wide_list.pop_back(); 59 | wide_list.push_back(L'4'); 60 | wide_list.push_back(L'\u263A'); 61 | { 62 | fs::ofstream f(fs::path(narrow_list.begin(), narrow_list.end())); 63 | } 64 | { 65 | fs::ofstream f(fs::path(wide_list.begin(), wide_list.end())); 66 | } 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /example/tut6a.cpp: -------------------------------------------------------------------------------- 1 | // filesystem tut6a.cpp --------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2010 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace boost::filesystem; 15 | 16 | int main(int argc, char* argv[]) 17 | { 18 | if (argc < 2) 19 | { 20 | std::cout << "Usage: tut6a path\n"; 21 | return 1; 22 | } 23 | 24 | try 25 | { 26 | for (recursive_directory_iterator it(argv[1]); 27 | it != recursive_directory_iterator(); 28 | ++it) 29 | { 30 | if (it.depth() > 1) 31 | it.pop(); 32 | else 33 | { 34 | for (int i = 0; i <= it.depth(); ++i) 35 | std::cout << " "; 36 | 37 | std::cout << it->path() << '\n'; 38 | } 39 | } 40 | } 41 | catch (std::exception& ex) 42 | { 43 | std::cout << "************* exception *****************\n"; 44 | std::cout << ex.what() << '\n'; 45 | } 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /example/tut6b.cpp: -------------------------------------------------------------------------------- 1 | // filesystem tut6b.cpp --------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2010 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace boost::filesystem; 15 | 16 | int main(int argc, char* argv[]) 17 | { 18 | if (argc < 2) 19 | { 20 | std::cout << "Usage: tut6b path\n"; 21 | return 1; 22 | } 23 | 24 | try 25 | { 26 | for (recursive_directory_iterator it(argv[1]); 27 | it != recursive_directory_iterator();) 28 | { 29 | for (int i = 0; i <= it.depth(); ++i) 30 | std::cout << " "; 31 | 32 | std::cout << it->path() << '\n'; 33 | 34 | try 35 | { 36 | ++it; 37 | } 38 | catch (filesystem_error& ex) 39 | { 40 | std::cout << "************* filesystem_error *****************\n"; 41 | std::cout << ex.what() << '\n'; 42 | } 43 | } 44 | } 45 | catch (std::exception& ex) 46 | { 47 | std::cout << "************* exception *****************\n"; 48 | std::cout << ex.what() << '\n'; 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /example/tut6c.cpp: -------------------------------------------------------------------------------- 1 | // filesystem tut6c.cpp --------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2010 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace boost::filesystem; 16 | using namespace boost::system; 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | if (argc < 2) 21 | { 22 | std::cout << "Usage: tut6c path\n"; 23 | return 1; 24 | } 25 | 26 | error_code ec; 27 | for (recursive_directory_iterator it(argv[1], ec); 28 | it != recursive_directory_iterator();) 29 | { 30 | for (int i = 0; i <= it.depth(); ++i) 31 | std::cout << " "; 32 | 33 | std::cout << it->path() << '\n'; 34 | 35 | it.increment(ec); 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /include/boost/filesystem.hpp: -------------------------------------------------------------------------------- 1 | // boost/filesystem.hpp --------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2010 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | 12 | #ifndef BOOST_FILESYSTEM_FILESYSTEM_HPP 13 | #define BOOST_FILESYSTEM_FILESYSTEM_HPP 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #endif // BOOST_FILESYSTEM_FILESYSTEM_HPP 23 | -------------------------------------------------------------------------------- /include/boost/filesystem/cstdio.hpp: -------------------------------------------------------------------------------- 1 | // boost/filesystem/cstdio.hpp ------------------------------------------------------// 2 | 3 | // Copyright Andrey Semashev 2023 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | 12 | #ifndef BOOST_FILESYSTEM_CSTDIO_HPP 13 | #define BOOST_FILESYSTEM_CSTDIO_HPP 14 | 15 | #include 16 | #include 17 | #include 18 | #if defined(BOOST_WINDOWS_API) 19 | #include 20 | #include 21 | #include 22 | #include 23 | #endif 24 | 25 | #include // must be the last #include 26 | 27 | namespace boost { 28 | namespace filesystem { 29 | 30 | #if defined(BOOST_WINDOWS_API) 31 | 32 | inline std::FILE* fopen(filesystem::path const& p, const char* mode) 33 | { 34 | #if defined(__CYGWIN__) || (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) && defined(__STRICT_ANSI__)) 35 | // Cygwin and MinGW32 in strict ANSI mode do not declare _wfopen 36 | return std::fopen(p.string().c_str(), mode); 37 | #else 38 | // mode should only contain ASCII characters and is likely short 39 | struct small_array 40 | { 41 | wchar_t buf[128u]; 42 | wchar_t* p; 43 | 44 | small_array() noexcept : p(buf) {} 45 | ~small_array() noexcept 46 | { 47 | if (BOOST_UNLIKELY(p != buf)) 48 | std::free(p); 49 | } 50 | } 51 | wmode; 52 | std::size_t wmode_len = std::mbstowcs(wmode.p, mode, sizeof(wmode.buf) / sizeof(wchar_t)); 53 | if (BOOST_UNLIKELY(wmode_len >= (sizeof(wmode.buf) / sizeof(wchar_t)))) 54 | { 55 | wmode_len = std::mbstowcs(nullptr, mode, 0u); 56 | // Check for size overflow, including (size_t)-1, which indicates mbstowcs error 57 | if (BOOST_UNLIKELY(wmode_len >= (static_cast< std::size_t >(-1) / sizeof(wchar_t)))) 58 | return nullptr; 59 | 60 | wmode.p = static_cast< wchar_t* >(std::malloc((wmode_len + 1u) * sizeof(wchar_t))); 61 | if (BOOST_UNLIKELY(!wmode.p)) 62 | return nullptr; 63 | 64 | std::size_t wmode_len2 = std::mbstowcs(wmode.p, mode, wmode_len + 1u); 65 | if (BOOST_UNLIKELY(wmode_len2 > wmode_len)) 66 | return nullptr; 67 | } 68 | 69 | return ::_wfopen(p.c_str(), wmode.p); 70 | #endif 71 | } 72 | 73 | #else // defined(BOOST_WINDOWS_API) 74 | 75 | inline std::FILE* fopen(filesystem::path const& p, const char* mode) 76 | { 77 | return std::fopen(p.c_str(), mode); 78 | } 79 | 80 | #endif // defined(BOOST_WINDOWS_API) 81 | 82 | } // namespace filesystem 83 | } // namespace boost 84 | 85 | #include 86 | 87 | #endif // BOOST_FILESYSTEM_CSTDIO_HPP 88 | -------------------------------------------------------------------------------- /include/boost/filesystem/detail/footer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Andrey Semashev 2021. 3 | * Distributed under the Boost Software License, Version 1.0. 4 | * (See accompanying file LICENSE_1_0.txt or copy at 5 | * http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #if !defined(BOOST_FILESYSTEM_ENABLE_WARNINGS) 9 | 10 | #if defined(_MSC_VER) && !defined(__clang__) 11 | 12 | #pragma warning(pop) 13 | 14 | #elif (defined(__GNUC__) && !(defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC)) \ 15 | && (__GNUC__ * 100 + __GNUC_MINOR__) >= 406) || defined(__clang__) 16 | 17 | #pragma GCC diagnostic pop 18 | 19 | #endif 20 | 21 | #endif // !defined(BOOST_FILESYSTEM_ENABLE_WARNINGS) 22 | 23 | #include 24 | -------------------------------------------------------------------------------- /include/boost/filesystem/detail/header.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Andrey Semashev 2021. 3 | * Distributed under the Boost Software License, Version 1.0. 4 | * (See accompanying file LICENSE_1_0.txt or copy at 5 | * http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | #include 9 | 10 | #if !defined(BOOST_FILESYSTEM_ENABLE_WARNINGS) 11 | 12 | #if defined(_MSC_VER) && !defined(__clang__) 13 | 14 | #pragma warning(push, 3) 15 | // 'm_A' : class 'A' needs to have dll-interface to be used by clients of class 'B' 16 | #pragma warning(disable: 4251) 17 | // non dll-interface class 'A' used as base for dll-interface class 'B' 18 | #pragma warning(disable: 4275) 19 | // 'int' : forcing value to bool 'true' or 'false' (performance warning) 20 | #pragma warning(disable: 4800) 21 | // unreferenced formal parameter 22 | #pragma warning(disable: 4100) 23 | // conditional expression is constant 24 | #pragma warning(disable: 4127) 25 | // function marked as __forceinline not inlined 26 | #pragma warning(disable: 4714) 27 | // decorated name length exceeded, name was truncated 28 | #pragma warning(disable: 4503) 29 | // 'X': This function or variable may be unsafe. Consider using Y instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 30 | #pragma warning(disable: 4996) 31 | // qualifier applied to function type has no meaning; ignored 32 | #pragma warning(disable: 4180) 33 | // qualifier applied to reference type; ignored 34 | #pragma warning(disable: 4181) 35 | 36 | #elif (defined(__GNUC__) && !(defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC)) \ 37 | && (__GNUC__ * 100 + __GNUC_MINOR__) >= 406) || defined(__clang__) 38 | 39 | // Note: clang-cl goes here as well, as it seems to support gcc-style warning control pragmas. 40 | 41 | #pragma GCC diagnostic push 42 | // unused parameter 'arg' 43 | #pragma GCC diagnostic ignored "-Wunused-parameter" 44 | // unused function 'foo' 45 | #pragma GCC diagnostic ignored "-Wunused-function" 46 | 47 | #if defined(__clang__) 48 | // template argument uses unnamed type 49 | #pragma clang diagnostic ignored "-Wunnamed-type-template-args" 50 | #endif // defined(__clang__) 51 | 52 | #endif 53 | 54 | #endif // !defined(BOOST_FILESYSTEM_ENABLE_WARNINGS) 55 | -------------------------------------------------------------------------------- /include/boost/filesystem/detail/type_traits/conjunction.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Distributed under the Boost Software License, Version 1.0. 3 | * (See accompanying file LICENSE_1_0.txt or copy at 4 | * https://www.boost.org/LICENSE_1_0.txt) 5 | * 6 | * Copyright (c) 2024 Andrey Semashev 7 | */ 8 | /*! 9 | * \file filesystem/detail/type_traits/conjunction.hpp 10 | * 11 | * This header contains definition of \c conjunction type trait. 12 | */ 13 | 14 | #ifndef BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_CONJUNCTION_HPP_INCLUDED_ 15 | #define BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_CONJUNCTION_HPP_INCLUDED_ 16 | 17 | #include 18 | #include 19 | 20 | #if (defined(__cpp_lib_logical_traits) && (__cpp_lib_logical_traits >= 201510l)) || \ 21 | (defined(BOOST_MSSTL_VERSION) && (BOOST_MSSTL_VERSION >= 140) && (_MSC_FULL_VER >= 190023918) && (BOOST_CXX_VERSION >= 201703l)) 22 | 23 | namespace boost { 24 | namespace filesystem { 25 | namespace detail { 26 | 27 | using std::conjunction; 28 | 29 | } // namespace detail 30 | } // namespace filesystem 31 | } // namespace boost 32 | 33 | #else 34 | 35 | #include 36 | 37 | namespace boost { 38 | namespace filesystem { 39 | namespace detail { 40 | 41 | using boost::conjunction; 42 | 43 | } // namespace detail 44 | } // namespace filesystem 45 | } // namespace boost 46 | 47 | #endif 48 | 49 | #endif // BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_CONJUNCTION_HPP_INCLUDED_ 50 | -------------------------------------------------------------------------------- /include/boost/filesystem/detail/type_traits/disjunction.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Distributed under the Boost Software License, Version 1.0. 3 | * (See accompanying file LICENSE_1_0.txt or copy at 4 | * https://www.boost.org/LICENSE_1_0.txt) 5 | * 6 | * Copyright (c) 2024 Andrey Semashev 7 | */ 8 | /*! 9 | * \file filesystem/detail/type_traits/disjunction.hpp 10 | * 11 | * This header contains definition of \c disjunction type trait. 12 | */ 13 | 14 | #ifndef BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_DISJUNCTION_HPP_INCLUDED_ 15 | #define BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_DISJUNCTION_HPP_INCLUDED_ 16 | 17 | #include 18 | #include 19 | 20 | #if (defined(__cpp_lib_logical_traits) && (__cpp_lib_logical_traits >= 201510l)) || \ 21 | (defined(BOOST_MSSTL_VERSION) && (BOOST_MSSTL_VERSION >= 140) && (_MSC_FULL_VER >= 190023918) && (BOOST_CXX_VERSION >= 201703l)) 22 | 23 | namespace boost { 24 | namespace filesystem { 25 | namespace detail { 26 | 27 | using std::disjunction; 28 | 29 | } // namespace detail 30 | } // namespace filesystem 31 | } // namespace boost 32 | 33 | #else 34 | 35 | #include 36 | 37 | namespace boost { 38 | namespace filesystem { 39 | namespace detail { 40 | 41 | using boost::disjunction; 42 | 43 | } // namespace detail 44 | } // namespace filesystem 45 | } // namespace boost 46 | 47 | #endif 48 | 49 | #endif // BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_DISJUNCTION_HPP_INCLUDED_ 50 | -------------------------------------------------------------------------------- /include/boost/filesystem/detail/type_traits/negation.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Distributed under the Boost Software License, Version 1.0. 3 | * (See accompanying file LICENSE_1_0.txt or copy at 4 | * https://www.boost.org/LICENSE_1_0.txt) 5 | * 6 | * Copyright (c) 2024 Andrey Semashev 7 | */ 8 | /*! 9 | * \file filesystem/detail/type_traits/negation.hpp 10 | * 11 | * This header contains definition of \c negation type trait. 12 | */ 13 | 14 | #ifndef BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_NEGATION_HPP_INCLUDED_ 15 | #define BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_NEGATION_HPP_INCLUDED_ 16 | 17 | #include 18 | #include 19 | 20 | #if (defined(__cpp_lib_logical_traits) && (__cpp_lib_logical_traits >= 201510l)) || \ 21 | (defined(BOOST_MSSTL_VERSION) && (BOOST_MSSTL_VERSION >= 140) && (_MSC_FULL_VER >= 190023918) && (BOOST_CXX_VERSION >= 201703l)) 22 | 23 | namespace boost { 24 | namespace filesystem { 25 | namespace detail { 26 | 27 | using std::negation; 28 | 29 | } // namespace detail 30 | } // namespace filesystem 31 | } // namespace boost 32 | 33 | #else 34 | 35 | #include 36 | 37 | namespace boost { 38 | namespace filesystem { 39 | namespace detail { 40 | 41 | using boost::negation; 42 | 43 | } // namespace detail 44 | } // namespace filesystem 45 | } // namespace boost 46 | 47 | #endif 48 | 49 | #endif // BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_NEGATION_HPP_INCLUDED_ 50 | -------------------------------------------------------------------------------- /include/boost/filesystem/detail/utf8_codecvt_facet.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2001 Ronald Garcia, Indiana University (garcia@osl.iu.edu) 2 | // Andrew Lumsdaine, Indiana University (lums@osl.iu.edu). 3 | 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #ifndef BOOST_FILESYSTEM_UTF8_CODECVT_FACET_HPP 8 | #define BOOST_FILESYSTEM_UTF8_CODECVT_FACET_HPP 9 | 10 | #include 11 | 12 | #include 13 | 14 | #define BOOST_UTF8_BEGIN_NAMESPACE \ 15 | namespace boost { \ 16 | namespace filesystem { \ 17 | namespace detail { 18 | 19 | #define BOOST_UTF8_END_NAMESPACE \ 20 | } \ 21 | } \ 22 | } 23 | #define BOOST_UTF8_DECL BOOST_FILESYSTEM_DECL 24 | 25 | #include 26 | 27 | #undef BOOST_UTF8_BEGIN_NAMESPACE 28 | #undef BOOST_UTF8_END_NAMESPACE 29 | #undef BOOST_UTF8_DECL 30 | 31 | #include 32 | 33 | #endif // BOOST_FILESYSTEM_UTF8_CODECVT_FACET_HPP 34 | -------------------------------------------------------------------------------- /include/boost/filesystem/exception.hpp: -------------------------------------------------------------------------------- 1 | // boost/filesystem/exception.hpp -----------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2003 4 | // Copyright Andrey Semashev 2019 5 | 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // See http://www.boost.org/LICENSE_1_0.txt 8 | 9 | // Library home page: http://www.boost.org/libs/filesystem 10 | 11 | #ifndef BOOST_FILESYSTEM_EXCEPTION_HPP 12 | #define BOOST_FILESYSTEM_EXCEPTION_HPP 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include // must be the last #include 24 | 25 | namespace boost { 26 | namespace filesystem { 27 | 28 | //--------------------------------------------------------------------------------------// 29 | // // 30 | // class filesystem_error // 31 | // // 32 | //--------------------------------------------------------------------------------------// 33 | 34 | class BOOST_SYMBOL_VISIBLE filesystem_error : 35 | public system::system_error 36 | { 37 | // see http://www.boost.org/more/error_handling.html for design rationale 38 | 39 | public: 40 | BOOST_FILESYSTEM_DECL filesystem_error(const char* what_arg, system::error_code ec); 41 | BOOST_FILESYSTEM_DECL filesystem_error(std::string const& what_arg, system::error_code ec); 42 | BOOST_FILESYSTEM_DECL filesystem_error(const char* what_arg, path const& path1_arg, system::error_code ec); 43 | BOOST_FILESYSTEM_DECL filesystem_error(std::string const& what_arg, path const& path1_arg, system::error_code ec); 44 | BOOST_FILESYSTEM_DECL filesystem_error(const char* what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec); 45 | BOOST_FILESYSTEM_DECL filesystem_error(std::string const& what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec); 46 | 47 | BOOST_FILESYSTEM_DECL filesystem_error(filesystem_error const& that); 48 | BOOST_FILESYSTEM_DECL filesystem_error& operator=(filesystem_error const& that); 49 | 50 | BOOST_FILESYSTEM_DECL ~filesystem_error() noexcept; 51 | 52 | path const& path1() const noexcept 53 | { 54 | return m_imp_ptr.get() ? m_imp_ptr->m_path1 : get_empty_path(); 55 | } 56 | path const& path2() const noexcept 57 | { 58 | return m_imp_ptr.get() ? m_imp_ptr->m_path2 : get_empty_path(); 59 | } 60 | 61 | BOOST_FILESYSTEM_DECL const char* what() const noexcept override; 62 | 63 | private: 64 | BOOST_FILESYSTEM_DECL static path const& get_empty_path() noexcept; 65 | 66 | private: 67 | struct impl : 68 | public boost::intrusive_ref_counter< impl > 69 | { 70 | path m_path1; // may be empty() 71 | path m_path2; // may be empty() 72 | std::string m_what; // not built until needed 73 | 74 | impl() = default; 75 | explicit impl(path const& path1) : 76 | m_path1(path1) 77 | { 78 | } 79 | impl(path const& path1, path const& path2) : 80 | m_path1(path1), m_path2(path2) 81 | { 82 | } 83 | }; 84 | boost::intrusive_ptr< impl > m_imp_ptr; 85 | }; 86 | 87 | } // namespace filesystem 88 | } // namespace boost 89 | 90 | #include 91 | 92 | #endif // BOOST_FILESYSTEM_EXCEPTION_HPP 93 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Automatic redirection failed, please go to 7 | doc/index.htm. 8 |
9 |

© Copyright Beman Dawes, 2003

10 |

Distributed under the Boost Software License, Version 1.0. 11 | See http://www.boost.org/LICENSE_1_0.txt

12 | 13 | 14 | -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "filesystem", 3 | "name": "Filesystem", 4 | "authors": [ 5 | "Beman Dawes" 6 | ], 7 | "description": "The Boost Filesystem Library provides portable facilities to query and manipulate paths, files, and directories.", 8 | "category": [ 9 | "System" 10 | ], 11 | "maintainers": [ 12 | "Andrey Semashev " 13 | ], 14 | "cxxstd": "11" 15 | } 16 | -------------------------------------------------------------------------------- /src/atomic_ref.hpp: -------------------------------------------------------------------------------- 1 | // atomic.hpp ------------------------------------------------------------------------// 2 | 3 | // Copyright 2021 Andrey Semashev 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // See library home page at http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | 12 | #ifndef BOOST_FILESYSTEM_SRC_ATOMIC_REF_HPP_ 13 | #define BOOST_FILESYSTEM_SRC_ATOMIC_REF_HPP_ 14 | 15 | #include 16 | 17 | #if !defined(BOOST_FILESYSTEM_NO_CXX20_ATOMIC_REF) 18 | 19 | #include 20 | 21 | namespace atomic_ns = std; 22 | 23 | #else // !defined(BOOST_FILESYSTEM_NO_CXX20_ATOMIC_REF) 24 | 25 | #include 26 | #include 27 | 28 | namespace atomic_ns = boost; 29 | 30 | #endif // !defined(BOOST_FILESYSTEM_NO_CXX20_ATOMIC_REF) 31 | 32 | #endif // BOOST_FILESYSTEM_SRC_ATOMIC_REF_HPP_ 33 | -------------------------------------------------------------------------------- /src/atomic_tools.hpp: -------------------------------------------------------------------------------- 1 | // atomic_tools.hpp ------------------------------------------------------------------// 2 | 3 | // Copyright 2021 Andrey Semashev 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // See library home page at http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | 12 | #ifndef BOOST_FILESYSTEM_SRC_ATOMIC_TOOLS_HPP_ 13 | #define BOOST_FILESYSTEM_SRC_ATOMIC_TOOLS_HPP_ 14 | 15 | #include 16 | 17 | #if !defined(BOOST_FILESYSTEM_SINGLE_THREADED) 18 | 19 | #include "atomic_ref.hpp" 20 | 21 | namespace boost { 22 | namespace filesystem { 23 | namespace detail { 24 | 25 | //! Atomically loads the value 26 | template< typename T > 27 | BOOST_FORCEINLINE T atomic_load_relaxed(T& a) 28 | { 29 | return atomic_ns::atomic_ref< T >(a).load(atomic_ns::memory_order_relaxed); 30 | } 31 | 32 | //! Atomically stores the value 33 | template< typename T > 34 | BOOST_FORCEINLINE void atomic_store_relaxed(T& a, T val) 35 | { 36 | atomic_ns::atomic_ref< T >(a).store(val, atomic_ns::memory_order_relaxed); 37 | } 38 | 39 | } // namespace detail 40 | } // namespace filesystem 41 | } // namespace boost 42 | 43 | #else // !defined(BOOST_FILESYSTEM_SINGLE_THREADED) 44 | 45 | namespace boost { 46 | namespace filesystem { 47 | namespace detail { 48 | 49 | //! Atomically loads the value 50 | template< typename T > 51 | BOOST_FORCEINLINE T atomic_load_relaxed(T const& a) 52 | { 53 | return a; 54 | } 55 | 56 | //! Atomically stores the value 57 | template< typename T > 58 | BOOST_FORCEINLINE void atomic_store_relaxed(T& a, T val) 59 | { 60 | a = val; 61 | } 62 | 63 | } // namespace detail 64 | } // namespace filesystem 65 | } // namespace boost 66 | 67 | #endif // !defined(BOOST_FILESYSTEM_SINGLE_THREADED) 68 | 69 | #endif // BOOST_FILESYSTEM_SRC_ATOMIC_TOOLS_HPP_ 70 | -------------------------------------------------------------------------------- /src/codecvt_error_category.cpp: -------------------------------------------------------------------------------- 1 | // codecvt_error_category implementation file ----------------------------------------// 2 | 3 | // Copyright 2009 Beman Dawes 4 | // Copyright 2022 Andrey Semashev 5 | 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // See http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | // Library home page at http://www.boost.org/libs/filesystem 10 | 11 | //--------------------------------------------------------------------------------------// 12 | 13 | #include "platform_config.hpp" 14 | 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "private_config.hpp" 24 | 25 | #include // must be the last #include 26 | 27 | //--------------------------------------------------------------------------------------// 28 | 29 | namespace boost { 30 | namespace filesystem { 31 | 32 | namespace { 33 | 34 | #if (defined(BOOST_GCC) && BOOST_GCC >= 40600) || defined(BOOST_CLANG) 35 | #pragma GCC diagnostic push 36 | // '(anonymous namespace)::codecvt_error_cat' has virtual functions but non-virtual destructor 37 | // This is not a problem as instances of codecvt_error_cat are never destroyed through a pointer to base. 38 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 39 | #endif 40 | 41 | class codecvt_error_cat final : 42 | public boost::system::error_category 43 | { 44 | public: 45 | // clang up to version 3.8 requires a user-defined default constructor in order to be able to declare a static constant of the error category. 46 | BOOST_SYSTEM_CONSTEXPR codecvt_error_cat() noexcept {} 47 | const char* name() const noexcept override; 48 | std::string message(int ev) const override; 49 | }; 50 | 51 | const char* codecvt_error_cat::name() const noexcept 52 | { 53 | return "codecvt"; 54 | } 55 | 56 | std::string codecvt_error_cat::message(int ev) const 57 | { 58 | std::string str; 59 | switch (ev) 60 | { 61 | case std::codecvt_base::ok: 62 | str = "ok"; 63 | break; 64 | case std::codecvt_base::partial: 65 | str = "partial"; 66 | break; 67 | case std::codecvt_base::error: 68 | str = "error"; 69 | break; 70 | case std::codecvt_base::noconv: 71 | str = "noconv"; 72 | break; 73 | default: 74 | str = "unknown error"; 75 | break; 76 | } 77 | return str; 78 | } 79 | 80 | #if (defined(BOOST_GCC) && BOOST_GCC >= 40600) || defined(BOOST_CLANG) 81 | #pragma GCC diagnostic pop 82 | #endif 83 | 84 | } // unnamed namespace 85 | 86 | BOOST_FILESYSTEM_DECL boost::system::error_category const& codecvt_error_category() noexcept 87 | { 88 | static 89 | #if defined(BOOST_SYSTEM_HAS_CONSTEXPR) 90 | constexpr 91 | #else 92 | const 93 | #endif 94 | codecvt_error_cat codecvt_error_cat_const; 95 | return codecvt_error_cat_const; 96 | } 97 | 98 | // Try to initialize the error category instance as early as possible to make sure it is 99 | // available during global deinitialization stage. For MSVC, codecvt_error_category() will 100 | // be called early by MSVC-specific initialization routine in path.cpp. 101 | #if !defined(BOOST_SYSTEM_HAS_CONSTEXPR) && !defined(_MSC_VER) 102 | 103 | namespace { 104 | 105 | struct codecvt_error_category_initializer 106 | { 107 | codecvt_error_category_initializer() { boost::filesystem::codecvt_error_category(); } 108 | }; 109 | 110 | BOOST_FILESYSTEM_INIT_PRIORITY(BOOST_FILESYSTEM_PATH_GLOBALS_INIT_PRIORITY) BOOST_ATTRIBUTE_UNUSED BOOST_FILESYSTEM_ATTRIBUTE_RETAIN 111 | const codecvt_error_category_initializer g_codecvt_error_category_initializer; 112 | 113 | } // namespace 114 | 115 | #endif // !defined(BOOST_SYSTEM_HAS_CONSTEXPR) && !defined(_MSC_VER) 116 | 117 | } // namespace filesystem 118 | } // namespace boost 119 | 120 | #include 121 | -------------------------------------------------------------------------------- /src/exception.cpp: -------------------------------------------------------------------------------- 1 | // boost/filesystem/exception.hpp -----------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2003 4 | // Copyright Andrey Semashev 2019 5 | 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // See http://www.boost.org/LICENSE_1_0.txt 8 | 9 | // Library home page: http://www.boost.org/libs/filesystem 10 | 11 | #include "platform_config.hpp" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "error_handling.hpp" 21 | 22 | #include // must be the last #include 23 | 24 | namespace boost { 25 | namespace filesystem { 26 | 27 | BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const char* what_arg, system::error_code ec) : 28 | system::system_error(ec, what_arg) 29 | { 30 | try 31 | { 32 | m_imp_ptr.reset(new impl()); 33 | } 34 | catch (...) 35 | { 36 | m_imp_ptr.reset(); 37 | } 38 | } 39 | 40 | BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(std::string const& what_arg, system::error_code ec) : 41 | system::system_error(ec, what_arg) 42 | { 43 | try 44 | { 45 | m_imp_ptr.reset(new impl()); 46 | } 47 | catch (...) 48 | { 49 | m_imp_ptr.reset(); 50 | } 51 | } 52 | 53 | BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const char* what_arg, path const& path1_arg, system::error_code ec) : 54 | system::system_error(ec, what_arg) 55 | { 56 | try 57 | { 58 | m_imp_ptr.reset(new impl(path1_arg)); 59 | } 60 | catch (...) 61 | { 62 | m_imp_ptr.reset(); 63 | } 64 | } 65 | 66 | BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(std::string const& what_arg, path const& path1_arg, system::error_code ec) : 67 | system::system_error(ec, what_arg) 68 | { 69 | try 70 | { 71 | m_imp_ptr.reset(new impl(path1_arg)); 72 | } 73 | catch (...) 74 | { 75 | m_imp_ptr.reset(); 76 | } 77 | } 78 | 79 | BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const char* what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec) : 80 | system::system_error(ec, what_arg) 81 | { 82 | try 83 | { 84 | m_imp_ptr.reset(new impl(path1_arg, path2_arg)); 85 | } 86 | catch (...) 87 | { 88 | m_imp_ptr.reset(); 89 | } 90 | } 91 | 92 | BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(std::string const& what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec) : 93 | system::system_error(ec, what_arg) 94 | { 95 | try 96 | { 97 | m_imp_ptr.reset(new impl(path1_arg, path2_arg)); 98 | } 99 | catch (...) 100 | { 101 | m_imp_ptr.reset(); 102 | } 103 | } 104 | 105 | BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(filesystem_error const& that) : 106 | system::system_error(static_cast< system::system_error const& >(that)), 107 | m_imp_ptr(that.m_imp_ptr) 108 | { 109 | } 110 | 111 | BOOST_FILESYSTEM_DECL filesystem_error& filesystem_error::operator=(filesystem_error const& that) 112 | { 113 | static_cast< system::system_error& >(*this) = static_cast< system::system_error const& >(that); 114 | m_imp_ptr = that.m_imp_ptr; 115 | return *this; 116 | } 117 | 118 | BOOST_FILESYSTEM_DECL filesystem_error::~filesystem_error() noexcept 119 | { 120 | } 121 | 122 | BOOST_FILESYSTEM_DECL const char* filesystem_error::what() const noexcept 123 | { 124 | if (m_imp_ptr.get()) try 125 | { 126 | if (m_imp_ptr->m_what.empty()) 127 | { 128 | m_imp_ptr->m_what = system::system_error::what(); 129 | if (!m_imp_ptr->m_path1.empty()) 130 | { 131 | m_imp_ptr->m_what += ": \""; 132 | m_imp_ptr->m_what += m_imp_ptr->m_path1.string(); 133 | m_imp_ptr->m_what += "\""; 134 | } 135 | if (!m_imp_ptr->m_path2.empty()) 136 | { 137 | m_imp_ptr->m_what += ", \""; 138 | m_imp_ptr->m_what += m_imp_ptr->m_path2.string(); 139 | m_imp_ptr->m_what += "\""; 140 | } 141 | } 142 | 143 | return m_imp_ptr->m_what.c_str(); 144 | } 145 | catch (...) 146 | { 147 | m_imp_ptr->m_what.clear(); 148 | } 149 | 150 | return system::system_error::what(); 151 | } 152 | 153 | BOOST_FILESYSTEM_DECL path const& filesystem_error::get_empty_path() noexcept 154 | { 155 | static const path empty_path; 156 | return empty_path; 157 | } 158 | 159 | // error handling helpers declared in error_handling.hpp -----------------------------------------------------// 160 | 161 | void emit_error(err_t error_num, system::error_code* ec, const char* message) 162 | { 163 | if (!ec) 164 | BOOST_FILESYSTEM_THROW(filesystem_error(message, system::error_code(error_num, system::system_category()))); 165 | else 166 | ec->assign(error_num, system::system_category()); 167 | } 168 | 169 | void emit_error(err_t error_num, path const& p, system::error_code* ec, const char* message) 170 | { 171 | if (!ec) 172 | BOOST_FILESYSTEM_THROW(filesystem_error(message, p, system::error_code(error_num, system::system_category()))); 173 | else 174 | ec->assign(error_num, system::system_category()); 175 | } 176 | 177 | void emit_error(err_t error_num, path const& p1, path const& p2, system::error_code* ec, const char* message) 178 | { 179 | if (!ec) 180 | BOOST_FILESYSTEM_THROW(filesystem_error(message, p1, p2, system::error_code(error_num, system::system_category()))); 181 | else 182 | ec->assign(error_num, system::system_category()); 183 | } 184 | 185 | } // namespace filesystem 186 | } // namespace boost 187 | 188 | #include 189 | -------------------------------------------------------------------------------- /src/platform_config.hpp: -------------------------------------------------------------------------------- 1 | // platform_config.hpp --------------------------------------------------------------------// 2 | 3 | // Copyright 2020 Andrey Semashev 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // See library home page at http://www.boost.org/libs/filesystem 9 | 10 | #ifndef BOOST_FILESYSTEM_PLATFORM_CONFIG_HPP_ 11 | #define BOOST_FILESYSTEM_PLATFORM_CONFIG_HPP_ 12 | 13 | // define 64-bit offset macros BEFORE including boost/config.hpp (see ticket #5355) 14 | #if defined(__ANDROID__) && defined(__ANDROID_API__) && __ANDROID_API__ < 24 15 | // Android fully supports 64-bit file offsets only for API 24 and above. 16 | // 17 | // Trying to define _FILE_OFFSET_BITS=64 for APIs below 24 18 | // leads to compilation failure for one or another reason, 19 | // depending on target Android API level, Android NDK version, 20 | // used STL, order of include paths and more. 21 | // For more information, please see: 22 | // - https://github.com/boostorg/filesystem/issues/65 23 | // - https://github.com/boostorg/filesystem/pull/69 24 | // 25 | // Android NDK developers consider it the expected behavior. 26 | // See their official position here: 27 | // - https://github.com/android-ndk/ndk/issues/501#issuecomment-326447479 28 | // - https://android.googlesource.com/platform/bionic/+/a34817457feee026e8702a1d2dffe9e92b51d7d1/docs/32-bit-abi.md#32_bit-abi-bugs 29 | // 30 | // Thus we do not define _FILE_OFFSET_BITS in such case. 31 | #else 32 | // Defining _FILE_OFFSET_BITS=64 should kick in 64-bit off_t's 33 | // (and thus st_size) on 32-bit systems that provide the Large File 34 | // Support (LFS) interface, such as Linux, Solaris, and IRIX. 35 | // 36 | // At the time of this comment writing (March 2018), on most systems 37 | // _FILE_OFFSET_BITS=64 definition is harmless: 38 | // either the definition is supported and enables 64-bit off_t, 39 | // or the definition is not supported and is ignored, in which case 40 | // off_t does not change its default size for the target system 41 | // (which may be 32-bit or 64-bit already). 42 | // Thus it makes sense to have _FILE_OFFSET_BITS=64 defined by default, 43 | // instead of listing every system that supports the definition. 44 | // Those few systems, on which _FILE_OFFSET_BITS=64 is harmful, 45 | // for example this definition causes compilation failure on those systems, 46 | // should be exempt from defining _FILE_OFFSET_BITS by adding 47 | // an appropriate #elif block above with the appropriate comment. 48 | // 49 | // _FILE_OFFSET_BITS must be defined before any headers are included 50 | // to ensure that the definition is available to all included headers. 51 | // That is required at least on Solaris, and possibly on other 52 | // systems as well. 53 | #define _FILE_OFFSET_BITS 64 54 | #endif 55 | 56 | #if defined(__APPLE__) || defined(__MACH__) 57 | // Enable newer ABI on Mac OS 10.5 and later, which is needed for struct stat to have birthtime members 58 | #define _DARWIN_USE_64_BIT_INODE 1 59 | #endif 60 | 61 | #ifndef _POSIX_PTHREAD_SEMANTICS 62 | #define _POSIX_PTHREAD_SEMANTICS // Sun readdir_r() needs this 63 | #endif 64 | 65 | #if !defined(_INCLUDE_STDCSOURCE_199901) && (defined(hpux) || defined(_hpux) || defined(__hpux)) 66 | // For HP-UX, request that WCHAR_MAX and WCHAR_MIN be defined as macros, 67 | // not casts. See ticket 5048 68 | #define _INCLUDE_STDCSOURCE_199901 69 | #endif 70 | 71 | #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) || \ 72 | defined(__CYGWIN__) 73 | // Define target Windows version macros before including any other headers 74 | #include 75 | #endif 76 | 77 | #ifndef BOOST_SYSTEM_NO_DEPRECATED 78 | #define BOOST_SYSTEM_NO_DEPRECATED 79 | #endif 80 | 81 | #include 82 | 83 | #endif // BOOST_FILESYSTEM_PLATFORM_CONFIG_HPP_ 84 | -------------------------------------------------------------------------------- /src/portability.cpp: -------------------------------------------------------------------------------- 1 | // portability.cpp -------------------------------------------------------------------// 2 | 3 | // Copyright 2002-2005 Beman Dawes 4 | // Use, modification, and distribution is subject to the Boost Software 5 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy 6 | // at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | // See library home page at http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | 12 | #include "platform_config.hpp" 13 | 14 | #include 15 | #include 16 | 17 | #include // SGI MIPSpro compilers need this 18 | #include 19 | 20 | #include // must be the last #include 21 | 22 | namespace boost { 23 | namespace filesystem { 24 | 25 | namespace { 26 | 27 | BOOST_CONSTEXPR_OR_CONST char windows_invalid_chars[] = 28 | "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" 29 | "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" 30 | "<>:\"/\\|"; 31 | 32 | BOOST_CONSTEXPR_OR_CONST char posix_valid_chars[] = 33 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"; 34 | 35 | } // unnamed namespace 36 | 37 | // name_check functions ----------------------------------------------// 38 | 39 | #ifdef BOOST_WINDOWS 40 | BOOST_FILESYSTEM_DECL bool native(std::string const& name) 41 | { 42 | return windows_name(name); 43 | } 44 | #else 45 | BOOST_FILESYSTEM_DECL bool native(std::string const& name) 46 | { 47 | return !name.empty() && name[0] != ' ' && name.find('/') == std::string::npos; 48 | } 49 | #endif 50 | 51 | BOOST_FILESYSTEM_DECL bool portable_posix_name(std::string const& name) 52 | { 53 | return !name.empty() && name.find_first_not_of(posix_valid_chars, 0, sizeof(posix_valid_chars) - 1) == std::string::npos; 54 | } 55 | 56 | BOOST_FILESYSTEM_DECL bool windows_name(std::string const& name) 57 | { 58 | // note that the terminating '\0' is part of the string - thus the size below 59 | // is sizeof(windows_invalid_chars) rather than sizeof(windows_invalid_chars)-1. 60 | return !name.empty() && name[0] != ' ' && name.find_first_of(windows_invalid_chars, 0, sizeof(windows_invalid_chars)) == std::string::npos 61 | && *(name.end() - 1) != ' ' && (*(name.end() - 1) != '.' || name.size() == 1 || name == ".."); 62 | } 63 | 64 | BOOST_FILESYSTEM_DECL bool portable_name(std::string const& name) 65 | { 66 | return !name.empty() && (name == "." || name == ".." || (windows_name(name) && portable_posix_name(name) && name[0] != '.' && name[0] != '-')); 67 | } 68 | 69 | BOOST_FILESYSTEM_DECL bool portable_directory_name(std::string const& name) 70 | { 71 | return name == "." || name == ".." || (portable_name(name) && name.find('.') == std::string::npos); 72 | } 73 | 74 | BOOST_FILESYSTEM_DECL bool portable_file_name(std::string const& name) 75 | { 76 | std::string::size_type pos; 77 | return portable_name(name) && name != "." && name != ".." && ((pos = name.find('.')) == std::string::npos || (name.find('.', pos + 1) == std::string::npos && (pos + 5) > name.size())); 78 | } 79 | 80 | } // namespace filesystem 81 | } // namespace boost 82 | 83 | #include 84 | -------------------------------------------------------------------------------- /src/posix_tools.hpp: -------------------------------------------------------------------------------- 1 | // posix_tools.hpp -------------------------------------------------------------------// 2 | 3 | // Copyright 2021-2024 Andrey Semashev 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // See library home page at http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | 12 | #ifndef BOOST_FILESYSTEM_SRC_POSIX_TOOLS_HPP_ 13 | #define BOOST_FILESYSTEM_SRC_POSIX_TOOLS_HPP_ 14 | 15 | #include "platform_config.hpp" 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include // must be the last #include 26 | 27 | namespace boost { 28 | namespace filesystem { 29 | namespace detail { 30 | 31 | //! Platform-specific parameters for directory iterator construction 32 | struct directory_iterator_params 33 | { 34 | #if defined(BOOST_FILESYSTEM_HAS_FDOPENDIR_NOFOLLOW) 35 | //! File descriptor of the directory to iterate over. If not a negative value, the directory path is only used to generate paths returned by the iterator. 36 | boost::scope::unique_fd dir_fd; 37 | #endif 38 | }; 39 | 40 | //! status() implementation 41 | file_status status_impl 42 | ( 43 | path const& p, 44 | system::error_code* ec 45 | #if defined(BOOST_FILESYSTEM_HAS_POSIX_AT_APIS) || defined(BOOST_FILESYSTEM_USE_STATX) 46 | , int basedir_fd = AT_FDCWD 47 | #endif 48 | ); 49 | 50 | //! symlink_status() implementation 51 | file_status symlink_status_impl 52 | ( 53 | path const& p, 54 | system::error_code* ec 55 | #if defined(BOOST_FILESYSTEM_HAS_POSIX_AT_APIS) || defined(BOOST_FILESYSTEM_USE_STATX) 56 | , int basedir_fd = AT_FDCWD 57 | #endif 58 | ); 59 | 60 | #if defined(BOOST_POSIX_API) 61 | 62 | //! Opens a directory file and returns a file descriptor. Returns a negative value in case of error. 63 | boost::scope::unique_fd open_directory(path const& p, directory_options opts, system::error_code& ec); 64 | 65 | #if defined(BOOST_FILESYSTEM_HAS_POSIX_AT_APIS) 66 | //! Opens a directory file and returns a file descriptor. Returns a negative value in case of error. 67 | boost::scope::unique_fd openat_directory(int basedir_fd, path const& p, directory_options opts, system::error_code& ec); 68 | #endif // defined(BOOST_FILESYSTEM_HAS_POSIX_AT_APIS) 69 | 70 | #endif // defined(BOOST_POSIX_API) 71 | 72 | } // namespace detail 73 | } // namespace filesystem 74 | } // namespace boost 75 | 76 | #include 77 | 78 | #endif // BOOST_FILESYSTEM_SRC_POSIX_TOOLS_HPP_ 79 | -------------------------------------------------------------------------------- /src/private_config.hpp: -------------------------------------------------------------------------------- 1 | // private_config.hpp ----------------------------------------------------------------// 2 | 3 | // Copyright 2021 Andrey Semashev 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // See library home page at http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | 12 | #ifndef BOOST_FILESYSTEM_SRC_PRIVATE_CONFIG_HPP_ 13 | #define BOOST_FILESYSTEM_SRC_PRIVATE_CONFIG_HPP_ 14 | 15 | #include 16 | 17 | #if defined(BOOST_FILESYSTEM_HAS_INIT_PRIORITY) 18 | #define BOOST_FILESYSTEM_INIT_PRIORITY(n) __attribute__ ((init_priority(n))) 19 | #else 20 | #define BOOST_FILESYSTEM_INIT_PRIORITY(n) 21 | #endif 22 | 23 | // According to https://gcc.gnu.org/bugzilla//show_bug.cgi?id=65115, 24 | // the default C++ object initializers priority is 65535. We would like to 25 | // initialize function pointers earlier than that (with lower priority values), 26 | // before the other global objects initializers are run. Other than this, 27 | // these priority values are arbitrary. 28 | #define BOOST_FILESYSTEM_FUNC_PTR_INIT_PRIORITY 32767 29 | 30 | // Path globals initialization priority 31 | #define BOOST_FILESYSTEM_PATH_GLOBALS_INIT_PRIORITY 32768 32 | 33 | #if defined(__has_feature) && defined(__has_attribute) 34 | #if __has_feature(memory_sanitizer) && __has_attribute(no_sanitize) 35 | #define BOOST_FILESYSTEM_NO_SANITIZE_MEMORY __attribute__ ((no_sanitize("memory"))) 36 | #endif 37 | #endif // defined(__has_feature) && defined(__has_attribute) 38 | 39 | #ifndef BOOST_FILESYSTEM_NO_SANITIZE_MEMORY 40 | #define BOOST_FILESYSTEM_NO_SANITIZE_MEMORY 41 | #endif 42 | 43 | #if defined(_MSC_VER) 44 | #if _MSC_VER < 1300 || _MSC_VER > 1900 // 1300 == VC++ 7.0, 1900 == VC++ 14.0 45 | typedef void (__cdecl* init_func_ptr_t)(); 46 | #define BOOST_FILESYSTEM_INITRETSUCCESS_V 47 | #define BOOST_FILESYSTEM_INIT_FUNC void __cdecl 48 | #else 49 | typedef int (__cdecl* init_func_ptr_t)(); 50 | #define BOOST_FILESYSTEM_INITRETSUCCESS_V 0 51 | #define BOOST_FILESYSTEM_INIT_FUNC int __cdecl 52 | #endif 53 | #else // defined(_MSC_VER) 54 | typedef void (*init_func_ptr_t)(); 55 | #define BOOST_FILESYSTEM_INITRETSUCCESS_V 56 | #define BOOST_FILESYSTEM_INIT_FUNC void 57 | #endif // defined(_MSC_VER) 58 | 59 | #if defined(__has_attribute) 60 | #if __has_attribute(__used__) 61 | #define BOOST_FILESYSTEM_ATTRIBUTE_RETAIN __attribute__ ((__used__)) 62 | #endif 63 | #endif 64 | 65 | #if !defined(BOOST_FILESYSTEM_ATTRIBUTE_RETAIN) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 402 66 | #define BOOST_FILESYSTEM_ATTRIBUTE_RETAIN __attribute__ ((__used__)) 67 | #endif 68 | 69 | #if !defined(BOOST_FILESYSTEM_ATTRIBUTE_RETAIN) 70 | #define BOOST_FILESYSTEM_NO_ATTRIBUTE_RETAIN 71 | #define BOOST_FILESYSTEM_ATTRIBUTE_RETAIN 72 | #endif 73 | 74 | #endif // BOOST_FILESYSTEM_SRC_PRIVATE_CONFIG_HPP_ 75 | -------------------------------------------------------------------------------- /src/utf8_codecvt_facet.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Vladimir Prus 2004. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt 4 | // or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include "platform_config.hpp" 7 | 8 | #include 9 | 10 | #include 11 | 12 | #define BOOST_UTF8_BEGIN_NAMESPACE \ 13 | namespace boost { \ 14 | namespace filesystem { \ 15 | namespace detail { 16 | 17 | #define BOOST_UTF8_END_NAMESPACE \ 18 | } \ 19 | } \ 20 | } 21 | #define BOOST_UTF8_DECL BOOST_FILESYSTEM_DECL 22 | 23 | #include 24 | 25 | #undef BOOST_UTF8_BEGIN_NAMESPACE 26 | #undef BOOST_UTF8_END_NAMESPACE 27 | #undef BOOST_UTF8_DECL 28 | 29 | #include 30 | -------------------------------------------------------------------------------- /src/windows_file_codecvt.cpp: -------------------------------------------------------------------------------- 1 | // filesystem windows_file_codecvt.cpp -----------------------------------------// 2 | 3 | // Copyright Beman Dawes 2009 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | 12 | #include "platform_config.hpp" 13 | 14 | #include // for mbstate_t 15 | 16 | #ifdef BOOST_WINDOWS_API 17 | 18 | #include "windows_file_codecvt.hpp" 19 | 20 | #include 21 | 22 | #include // must be the last #include 23 | 24 | namespace boost { 25 | namespace filesystem { 26 | namespace detail { 27 | 28 | std::codecvt_base::result windows_file_codecvt::do_in( 29 | std::mbstate_t&, 30 | const char* from, const char* from_end, const char*& from_next, 31 | wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const 32 | { 33 | UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; 34 | 35 | int count; 36 | if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from, static_cast< int >(from_end - from), to, static_cast< int >(to_end - to))) == 0) 37 | { 38 | return error; // conversion failed 39 | } 40 | 41 | from_next = from_end; 42 | to_next = to + count; 43 | *to_next = L'\0'; 44 | return ok; 45 | } 46 | 47 | std::codecvt_base::result windows_file_codecvt::do_out( 48 | std::mbstate_t&, 49 | const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next, 50 | char* to, char* to_end, char*& to_next) const 51 | { 52 | UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; 53 | 54 | int count; 55 | if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from, static_cast< int >(from_end - from), to, static_cast< int >(to_end - to), 0, 0)) == 0) 56 | { 57 | return error; // conversion failed 58 | } 59 | 60 | from_next = from_end; 61 | to_next = to + count; 62 | *to_next = '\0'; 63 | return ok; 64 | } 65 | 66 | } // namespace detail 67 | } // namespace filesystem 68 | } // namespace boost 69 | 70 | #include 71 | 72 | #endif // BOOST_WINDOWS_API 73 | -------------------------------------------------------------------------------- /src/windows_file_codecvt.hpp: -------------------------------------------------------------------------------- 1 | // filesystem windows_file_codecvt.hpp -----------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2009 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #ifndef BOOST_FILESYSTEM_WINDOWS_FILE_CODECVT_HPP 11 | #define BOOST_FILESYSTEM_WINDOWS_FILE_CODECVT_HPP 12 | 13 | #include 14 | 15 | #ifdef BOOST_WINDOWS_API 16 | 17 | #include 18 | #include 19 | #include // std::mbstate_t 20 | #include 21 | 22 | #include // must be the last #include 23 | 24 | namespace boost { 25 | namespace filesystem { 26 | namespace detail { 27 | 28 | //------------------------------------------------------------------------------------// 29 | // // 30 | // class windows_file_codecvt // 31 | // // 32 | // Warning: partial implementation; even do_in and do_out only partially meet the // 33 | // standard library specifications as the "to" buffer must hold the entire result. // 34 | // // 35 | //------------------------------------------------------------------------------------// 36 | 37 | class BOOST_SYMBOL_VISIBLE windows_file_codecvt final : 38 | public std::codecvt< wchar_t, char, std::mbstate_t > 39 | { 40 | public: 41 | explicit windows_file_codecvt(std::size_t refs = 0) : 42 | std::codecvt< wchar_t, char, std::mbstate_t >(refs) 43 | { 44 | } 45 | 46 | protected: 47 | bool do_always_noconv() const noexcept override { return false; } 48 | 49 | // seems safest to assume variable number of characters since we don't 50 | // actually know what codepage is active 51 | int do_encoding() const noexcept override { return 0; } 52 | std::codecvt_base::result do_in(std::mbstate_t& state, const char* from, const char* from_end, const char*& from_next, wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const override; 53 | std::codecvt_base::result do_out(std::mbstate_t& state, const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next, char* to, char* to_end, char*& to_next) const override; 54 | std::codecvt_base::result do_unshift(std::mbstate_t&, char* /*from*/, char* /*to*/, char*& /*next*/) const override { return ok; } 55 | int do_length(std::mbstate_t&, const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const 56 | #if BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600)) 57 | throw() 58 | #endif 59 | override 60 | { return 0; } 61 | int do_max_length() const noexcept override { return 0; } 62 | }; 63 | 64 | } // namespace detail 65 | } // namespace filesystem 66 | } // namespace boost 67 | 68 | #include 69 | 70 | #endif // BOOST_WINDOWS_API 71 | 72 | #endif // BOOST_FILESYSTEM_WINDOWS_FILE_CODECVT_HPP 73 | -------------------------------------------------------------------------------- /test/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Boost Filesystem Library test Jamfile 2 | 3 | # (C) Copyright Beman Dawes 2002-2006 4 | # (C) Copyright Andrey Semashev 2020 5 | # Distributed under the Boost Software License, Version 1.0. 6 | # See www.boost.org/LICENSE_1_0.txt 7 | 8 | import testing ; 9 | import os ; 10 | 11 | # The rule checks we're running on Windows that supports mklink command (Vista and later) 12 | rule check-mklink ( properties * ) 13 | { 14 | local result ; 15 | 16 | if windows in $(properties) 17 | { 18 | # mklink is a builtin shell command, so we can't check if an executable exists. 19 | # Testing the exit status of the mklink command (in the hope that it will be different 20 | # when the command is not supported) is inconclusive as for some reason Windows 8.1 shell 21 | # always returns exit code of 1. We have to match the output of the command. :( 22 | # Note that the output may be localized, so pick some part that is likely to be stable regardless 23 | # of localization. 24 | local output = [ SHELL "mklink /?" : exit-status ] ; 25 | if [ MATCH (MKLINK) : $(output[1]) ] 26 | { 27 | result = BOOST_FILESYSTEM_HAS_MKLINK ; 28 | 29 | if ! $(.annouced-mklink) 30 | { 31 | ECHO " - Boost.Filesystem: mklink found" ; 32 | .annouced-mklink = 1 ; 33 | } 34 | } 35 | else 36 | { 37 | if ! $(.annouced-mklink) 38 | { 39 | ECHO " - Boost.Filesystem: mklink not found" ; 40 | .annouced-mklink = 1 ; 41 | } 42 | } 43 | } 44 | 45 | #ECHO Result: $(result) ; 46 | return $(result) ; 47 | } 48 | 49 | project 50 | : requirements 51 | . 52 | windows:_SCL_SECURE_NO_WARNINGS 53 | windows:_SCL_SECURE_NO_DEPRECATE 54 | windows:_CRT_SECURE_NO_WARNINGS 55 | windows:_CRT_SECURE_NO_DEPRECATE 56 | /boost/filesystem//boost_filesystem 57 | @check-mklink 58 | ; 59 | 60 | # Some tests are run both statically and as shared libraries since Filesystem 61 | # has a history of bugs that appear only in one type of build or the other. 62 | 63 | path-constant HERE : . ; 64 | 65 | local VIS ; 66 | 67 | if [ os.environ UBSAN ] 68 | { 69 | VIS = global 70 | -/boost/filesystem//boost_filesystem 71 | /boost/filesystem//boost_filesystem/global ; 72 | } 73 | 74 | run config_info.cpp : : : shared always_show_run_output ; 75 | run config_info.cpp : : : static always_show_run_output : config_info_static ; 76 | run convenience_test.cpp : : : BOOST_FILESYSTEM_VERSION=4 ; 77 | compile macro_default_test.cpp ; 78 | run odr1_test.cpp odr2_test.cpp ; 79 | run deprecated_test.cpp : : : BOOST_FILESYSTEM_VERSION=3 ; 80 | run fstream_test.cpp : : : $(VIS) BOOST_FILESYSTEM_VERSION=4 ; 81 | run cstdio_test.cpp : : : $(VIS) BOOST_FILESYSTEM_VERSION=4 ; 82 | run large_file_support_test.cpp : : : BOOST_FILESYSTEM_VERSION=4 ; 83 | run locale_info.cpp : : : BOOST_FILESYSTEM_VERSION=4 always_show_run_output ; 84 | run operations_test.cpp : : : shared BOOST_FILESYSTEM_VERSION=4 always_show_run_output ; 85 | run operations_test.cpp : : : static BOOST_FILESYSTEM_VERSION=4 : operations_test_static ; 86 | run operations_test.cpp : : : shared BOOST_FILESYSTEM_VERSION=3 : operations_test_v3 ; 87 | run operations_unit_test.cpp : $(HERE) : : shared BOOST_FILESYSTEM_VERSION=4 always_show_run_output ; 88 | run copy_test.cpp : : : BOOST_FILESYSTEM_VERSION=4 /boost/exception//boost_exception ; 89 | compile-fail cf_path_nullptr_test.cpp ; 90 | compile path_iter_ctor_overload_test.cpp ; 91 | compile path_operator_ambiguity.cpp : gcc:on ; 92 | run path_test.cpp : : : shared BOOST_FILESYSTEM_VERSION=4 ; 93 | run path_test.cpp : : : static BOOST_FILESYSTEM_VERSION=4 : path_test_static ; 94 | run path_test.cpp : : : shared BOOST_FILESYSTEM_VERSION=3 : path_test_v3 ; 95 | run path_unit_test.cpp : : : shared $(VIS) BOOST_FILESYSTEM_VERSION=4 ; 96 | run path_unit_test.cpp : : : static $(VIS) BOOST_FILESYSTEM_VERSION=4 : path_unit_test_static ; 97 | run path_unit_test.cpp : : : shared $(VIS) BOOST_FILESYSTEM_VERSION=3 : path_unit_test_v3 ; 98 | run relative_test.cpp : : : BOOST_FILESYSTEM_VERSION=4 ; 99 | run ../example/simple_ls.cpp : : : BOOST_FILESYSTEM_VERSION=4 ; 100 | run ../example/file_status.cpp : : : BOOST_FILESYSTEM_VERSION=4 ; 101 | run foreach_test.cpp : : : BOOST_FILESYSTEM_VERSION=4 /boost/foreach//boost_foreach ; 102 | 103 | # `quick` target (for CI) 104 | run quick.cpp : : : BOOST_FILESYSTEM_VERSION=4 ; 105 | 106 | # Tests for specific issues 107 | run issues/70-71-copy.cpp : : : BOOST_FILESYSTEM_VERSION=4 ; 108 | 109 | run issues/99_canonical_with_junction_point.cpp : : : BOOST_FILESYSTEM_VERSION=4 ; 110 | run issues/reparse_tag_file_placeholder.cpp : : : BOOST_FILESYSTEM_VERSION=4 ; 111 | 112 | if [ os.environ BOOST_FILESYSTEM_TEST_WITH_EXAMPLES ] 113 | { 114 | build-project ../example ; 115 | } 116 | -------------------------------------------------------------------------------- /test/cf_path_nullptr_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Andrey Semashev. 2 | // 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | boost::filesystem::path p(nullptr); 14 | p = nullptr; 15 | } 16 | -------------------------------------------------------------------------------- /test/config_info.cpp: -------------------------------------------------------------------------------- 1 | // boost/libs/filesystem/test/config_info.cpp ----------------------------------------// 2 | 3 | // Copyright Beman Dawes 2017 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | 12 | #include 13 | #include 14 | #include "macro_value.hpp" 15 | 16 | using std::cout; 17 | using std::endl; 18 | 19 | int main() 20 | { 21 | cout << "Verify macro reporting works correctly\n"; 22 | cout << " NOSUCHMACRO: " << BOOST_MACRO_VALUE(NOSUCHMACRO) << endl; 23 | #define SUCHAMACRO 24 | cout << " SUCHAMACRO: " << BOOST_MACRO_VALUE(SUCHAMACRO) << endl; 25 | cout << " BOOST_VERSION: " << BOOST_MACRO_VALUE(BOOST_VERSION) << endl; 26 | 27 | cout << "Report macro values that may be useful in debugging various test programs\n"; 28 | cout << " BOOST_VERSION: " << BOOST_MACRO_VALUE(BOOST_VERSION) << endl; 29 | cout << " BOOST_FILESYSTEM_VERSION: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_VERSION) << endl; 30 | cout << " BOOST_FILESYSTEM_DEPRECATED: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_DEPRECATED) << endl; 31 | cout << " BOOST_FILESYSTEM_SOURCE: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_SOURCE) << endl; 32 | cout << " BOOST_FILESYSTEM_DYN_LINK: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_DYN_LINK) << endl; 33 | cout << " BOOST_FILESYSTEM_STATIC_LINK: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_STATIC_LINK) << endl; 34 | cout << " BOOST_ALL_NO_LIB: " << BOOST_MACRO_VALUE(BOOST_ALL_NO_LIB) << endl; 35 | cout << " BOOST_FILESYSTEM_NO_LIB: " << BOOST_MACRO_VALUE(BOOST_FILESYSTEM_NO_LIB) << endl; 36 | cout << " BOOST_LIB_NAME: " << BOOST_MACRO_VALUE(BOOST_LIB_NAME) << endl; 37 | cout << " BOOST_POSIX_API: " << BOOST_MACRO_VALUE(BOOST_POSIX_API) << endl; 38 | cout << " BOOST_WINDOWS_API: " << BOOST_MACRO_VALUE(BOOST_WINDOWS_API) << endl; 39 | cout << " _MSC_VER: " << BOOST_MACRO_VALUE(_MSC_VER) << endl; 40 | cout << " __MINGW32__: " << BOOST_MACRO_VALUE(__MINGW32__) << endl; 41 | //cout << " : " << BOOST_MACRO_VALUE() << endl; 42 | //cout << " : " << BOOST_MACRO_VALUE() << endl; 43 | //cout << " : " << BOOST_MACRO_VALUE() << endl; 44 | //cout << " : " << BOOST_MACRO_VALUE() << endl; 45 | //cout << " : " << BOOST_MACRO_VALUE() << endl; 46 | //cout << " : " << BOOST_MACRO_VALUE() << endl; 47 | //cout << " : " << BOOST_MACRO_VALUE() << endl; 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /test/convenience_test.cpp: -------------------------------------------------------------------------------- 1 | // libs/filesystem/test/convenience_test.cpp -----------------------------------------// 2 | 3 | // Copyright Beman Dawes, 2002 4 | // Copyright Vladimir Prus, 2002 5 | // Use, modification, and distribution is subject to the Boost Software 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | // See library home page at http://www.boost.org/libs/filesystem 10 | 11 | #include 12 | 13 | // See deprecated_test for tests of deprecated features 14 | #ifndef BOOST_FILESYSTEM_NO_DEPRECATED 15 | #define BOOST_FILESYSTEM_NO_DEPRECATED 16 | #endif 17 | #ifndef BOOST_SYSTEM_NO_DEPRECATED 18 | #define BOOST_SYSTEM_NO_DEPRECATED 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace fs = boost::filesystem; 33 | using fs::path; 34 | namespace sys = boost::system; 35 | 36 | namespace { 37 | template< typename F > 38 | bool throws_fs_error(F func) 39 | { 40 | try 41 | { 42 | func(); 43 | } 44 | 45 | catch (const fs::filesystem_error&) 46 | { 47 | return true; 48 | } 49 | return false; 50 | } 51 | 52 | void create_recursive_iterator(const fs::path& ph) 53 | { 54 | fs::recursive_directory_iterator it(ph); 55 | } 56 | } // namespace 57 | 58 | // ------------------------------------------------------------------------------------// 59 | 60 | int cpp_main(int, char*[]) 61 | { 62 | 63 | // create_directories() tests --------------------------------------------------------// 64 | 65 | BOOST_TEST(!fs::create_directories("/")); // should be harmless 66 | 67 | path unique_dir = fs::unique_path(); // unique name in case tests running in parallel 68 | path unique_yy = unique_dir / "yy"; 69 | path unique_yya = unique_dir / "yya"; 70 | path unique_yy_zz = unique_dir / "yy" / "zz"; 71 | 72 | fs::remove_all(unique_dir); // make sure slate is blank 73 | BOOST_TEST(!fs::exists(unique_dir)); // reality check 74 | 75 | BOOST_TEST(fs::create_directories(unique_dir)); 76 | BOOST_TEST(fs::exists(unique_dir)); 77 | BOOST_TEST(fs::is_directory(unique_dir)); 78 | 79 | BOOST_TEST(fs::create_directories(unique_yy_zz)); 80 | BOOST_TEST(fs::exists(unique_dir)); 81 | BOOST_TEST(fs::exists(unique_yy)); 82 | BOOST_TEST(fs::exists(unique_yy_zz)); 83 | BOOST_TEST(fs::is_directory(unique_dir)); 84 | BOOST_TEST(fs::is_directory(unique_yy)); 85 | BOOST_TEST(fs::is_directory(unique_yy_zz)); 86 | 87 | path is_a_file(unique_dir / "uu"); 88 | { 89 | std::ofstream f(is_a_file.string().c_str()); 90 | BOOST_TEST(!!f); 91 | } 92 | BOOST_TEST(throws_fs_error( 93 | boost::bind(fs::create_directories, is_a_file))); 94 | BOOST_TEST(throws_fs_error( 95 | boost::bind(fs::create_directories, is_a_file / "aa"))); 96 | 97 | // recursive_directory_iterator tests ----------------------------------------// 98 | 99 | sys::error_code ec; 100 | fs::recursive_directory_iterator it("/no-such-path", ec); 101 | BOOST_TEST(ec); 102 | 103 | BOOST_TEST(throws_fs_error( 104 | boost::bind(create_recursive_iterator, "/no-such-path"))); 105 | 106 | fs::remove(unique_dir / "uu"); 107 | 108 | #ifdef BOOST_WINDOWS_API 109 | // These tests depends on ordering of directory entries, and that's guaranteed 110 | // on Windows but not necessarily on other operating systems 111 | { 112 | std::ofstream f(unique_yya.string().c_str()); 113 | BOOST_TEST(!!f); 114 | } 115 | 116 | for (it = fs::recursive_directory_iterator(unique_dir); 117 | it != fs::recursive_directory_iterator(); ++it) 118 | { 119 | std::cout << it->path() << '\n'; 120 | } 121 | 122 | it = fs::recursive_directory_iterator(unique_dir); 123 | BOOST_TEST(it->path() == unique_yy); 124 | BOOST_TEST(it.depth() == 0); 125 | ++it; 126 | BOOST_TEST(it->path() == unique_yy_zz); 127 | BOOST_TEST(it.depth() == 1); 128 | it.pop(); 129 | BOOST_TEST(it->path() == unique_yya); 130 | BOOST_TEST(it.depth() == 0); 131 | it++; 132 | BOOST_TEST(it == fs::recursive_directory_iterator()); 133 | 134 | it = fs::recursive_directory_iterator(unique_dir); 135 | BOOST_TEST(it->path() == unique_yy); 136 | it.disable_recursion_pending(); 137 | ++it; 138 | BOOST_TEST(it->path() == unique_yya); 139 | ++it; 140 | BOOST_TEST(it == fs::recursive_directory_iterator()); 141 | 142 | fs::remove(unique_yya); 143 | #endif 144 | 145 | it = fs::recursive_directory_iterator(unique_yy_zz); 146 | BOOST_TEST(it == fs::recursive_directory_iterator()); 147 | 148 | it = fs::recursive_directory_iterator(unique_dir); 149 | BOOST_TEST(it->path() == unique_yy); 150 | BOOST_TEST(it.depth() == 0); 151 | ++it; 152 | BOOST_TEST(it->path() == unique_yy_zz); 153 | BOOST_TEST(it.depth() == 1); 154 | it++; 155 | BOOST_TEST(it == fs::recursive_directory_iterator()); 156 | 157 | it = fs::recursive_directory_iterator(unique_dir); 158 | BOOST_TEST(it->path() == unique_yy); 159 | it.disable_recursion_pending(); 160 | ++it; 161 | BOOST_TEST(it == fs::recursive_directory_iterator()); 162 | 163 | it = fs::recursive_directory_iterator(unique_dir); 164 | BOOST_TEST(it->path() == unique_yy); 165 | ++it; 166 | it.pop(); 167 | BOOST_TEST(it == fs::recursive_directory_iterator()); 168 | 169 | ec.clear(); 170 | BOOST_TEST(!ec); 171 | // check that two argument failed constructor creates the end iterator 172 | BOOST_TEST(fs::recursive_directory_iterator("nosuchdir", ec) == fs::recursive_directory_iterator()); 173 | BOOST_TEST(ec); 174 | 175 | fs::remove_all(unique_dir); // clean up behind ourselves 176 | 177 | return ::boost::report_errors(); 178 | } 179 | -------------------------------------------------------------------------------- /test/cstdio_test.cpp: -------------------------------------------------------------------------------- 1 | // cstdio_test.cpp ------------------------------------------------------------------// 2 | 3 | // Copyright Andrey Semashev 2023 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include // for std::fclose 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | namespace fs = boost::filesystem; 25 | 26 | namespace { 27 | 28 | bool cleanup = true; 29 | 30 | class auto_fclose 31 | { 32 | private: 33 | std::FILE* m_file; 34 | 35 | public: 36 | auto_fclose() noexcept : m_file(nullptr) {} 37 | explicit auto_fclose(std::FILE* file) noexcept : m_file(file) {} 38 | ~auto_fclose() noexcept 39 | { 40 | if (m_file) 41 | std::fclose(m_file); 42 | } 43 | 44 | std::FILE* get() const noexcept { return m_file; } 45 | 46 | auto_fclose(auto_fclose const&) = delete; 47 | auto_fclose& operator=(auto_fclose const&) = delete; 48 | }; 49 | 50 | void test(fs::path const& p) 51 | { 52 | fs::remove(p); 53 | { 54 | std::cout << " in test 1\n"; 55 | auto_fclose file(fs::fopen(p, "w")); 56 | BOOST_TEST(file.get() != nullptr); 57 | } 58 | { 59 | std::cout << " in test 2\n"; 60 | auto_fclose file(fs::fopen(p, "r")); 61 | BOOST_TEST(file.get() != nullptr); 62 | } 63 | { 64 | std::cout << " in test 3\n"; 65 | auto_fclose file(fs::fopen(p / p.filename(), "w")); // should fail 66 | BOOST_TEST(file.get() == nullptr); 67 | } 68 | 69 | if (cleanup) 70 | fs::remove(p); 71 | } 72 | 73 | } // namespace 74 | 75 | int cpp_main(int argc, char*[]) 76 | { 77 | if (argc > 1) 78 | cleanup = false; 79 | 80 | // test narrow characters 81 | std::cout << "narrow character tests:\n"; 82 | test(fs::unique_path("narrow_fopen_test-%%%%-%%%%.txt")); 83 | 84 | // So that tests are run with known encoding, use Boost UTF-8 codecvt 85 | std::locale global_loc = std::locale(); 86 | std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet()); 87 | fs::path::imbue(loc); 88 | 89 | // test with some wide characters 90 | // \u2780 is circled 1 against white background == e2 9e 80 in UTF-8 91 | // \u2781 is circled 2 against white background == e2 9e 81 in UTF-8 92 | // \u263A is a white smiling face 93 | std::cout << "\nwide character tests:\n"; 94 | std::wstring ws(L"wide_fopen_test_"); 95 | ws.push_back(static_cast< wchar_t >(0x2780)); 96 | ws.push_back(static_cast< wchar_t >(0x263A)); 97 | ws.append(L"-%%%%-%%%%.txt"); 98 | test(fs::unique_path(ws)); 99 | 100 | return ::boost::report_errors(); 101 | } 102 | -------------------------------------------------------------------------------- /test/deprecated_test.cpp: -------------------------------------------------------------------------------- 1 | // deprecated_test program --------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2002 4 | // Copyright Vladimir Prus 2002 5 | 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // See http://www.boost.org/LICENSE_1_0.txt 8 | 9 | // Library home page: http://www.boost.org/libs/filesystem 10 | 11 | // This test verifies that various deprecated names still work. This is 12 | // important to preserve existing code that uses the old names. 13 | 14 | #define BOOST_FILESYSTEM_DEPRECATED 15 | #define BOOST_FILESYSTEM_ALLOW_DEPRECATED 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | namespace fs = boost::filesystem; 26 | using boost::filesystem::path; 27 | 28 | #define PATH_CHECK(a, b) check(a, b, __LINE__) 29 | 30 | namespace { 31 | std::string platform(BOOST_PLATFORM); 32 | 33 | std::list< char > l; // see main() for initialization to s, t, r, i, n, g 34 | std::list< wchar_t > wl; // see main() for initialization to w, s, t, r, i, n, g 35 | std::vector< char > v; // see main() for initialization to f, u, z 36 | std::vector< wchar_t > wv; // see main() for initialization to w, f, u, z 37 | 38 | void check(const fs::path& source, const std::string& expected, int line) 39 | { 40 | if (source.generic_string() == expected) 41 | return; 42 | 43 | ++::boost::detail::test_errors(); 44 | 45 | std::cout << __FILE__ << '(' << line << ") source.string(): \"" << source.string() 46 | << "\" != expected: \"" << expected 47 | << "\"" << std::endl; 48 | } 49 | 50 | // path_container_ctor_test ---------------------------------------------------------// 51 | 52 | void path_container_ctor_test() 53 | { 54 | path x4v(v); // std::vector 55 | PATH_CHECK(x4v, "fuz"); 56 | BOOST_TEST_EQ(x4v.native().size(), 3U); 57 | 58 | path x5v(wv); // std::vector 59 | PATH_CHECK(x5v, "wfuz"); 60 | BOOST_TEST_EQ(x5v.native().size(), 4U); 61 | 62 | // non-contiguous containers 63 | path x10(l); // std::list 64 | PATH_CHECK(x10, "string"); 65 | BOOST_TEST_EQ(x10.native().size(), 6U); 66 | 67 | path xll(wl); // std::list 68 | PATH_CHECK(xll, "wstring"); 69 | BOOST_TEST_EQ(xll.native().size(), 7U); 70 | } 71 | 72 | } // unnamed namespace 73 | 74 | //--------------------------------------------------------------------------------------// 75 | 76 | int cpp_main(int /*argc*/, char* /*argv*/[]) 77 | { 78 | // The choice of platform is make at runtime rather than compile-time 79 | // so that compile errors for all platforms will be detected even though 80 | // only the current platform is runtime tested. 81 | platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin") ? "Windows" : "POSIX"; 82 | std::cout << "Platform is " << platform << '\n'; 83 | 84 | l.push_back('s'); 85 | l.push_back('t'); 86 | l.push_back('r'); 87 | l.push_back('i'); 88 | l.push_back('n'); 89 | l.push_back('g'); 90 | 91 | wl.push_back(L'w'); 92 | wl.push_back(L's'); 93 | wl.push_back(L't'); 94 | wl.push_back(L'r'); 95 | wl.push_back(L'i'); 96 | wl.push_back(L'n'); 97 | wl.push_back(L'g'); 98 | 99 | v.push_back('f'); 100 | v.push_back('u'); 101 | v.push_back('z'); 102 | 103 | wv.push_back(L'w'); 104 | wv.push_back(L'f'); 105 | wv.push_back(L'u'); 106 | wv.push_back(L'z'); 107 | 108 | BOOST_TEST(fs::initial_path() == fs::current_path()); 109 | 110 | //path::default_name_check(fs::no_check); 111 | 112 | fs::directory_entry de("foo.bar", fs::file_status(fs::regular_file, fs::owner_all), fs::file_status(fs::directory_file, fs::group_all)); 113 | 114 | BOOST_TEST(de.path() == "foo.bar"); 115 | BOOST_TEST(de.status() == fs::file_status(fs::regular_file, fs::owner_all)); 116 | BOOST_TEST(de.symlink_status() == fs::file_status(fs::directory_file, fs::group_all)); 117 | BOOST_TEST(de < fs::directory_entry("goo.bar", fs::file_status(), fs::file_status())); 118 | BOOST_TEST(de == fs::directory_entry("foo.bar", fs::file_status(), fs::file_status())); 119 | BOOST_TEST(de != fs::directory_entry("goo.bar", fs::file_status(), fs::file_status())); 120 | de.replace_filename("bar.foo", fs::file_status(), fs::file_status()); 121 | BOOST_TEST(de.path() == "bar.foo"); 122 | 123 | const fs::path temp_dir(fs::current_path() / ".." / fs::unique_path("deprecated_test-%%%%-%%%%-%%%%")); 124 | std::cout << "temp_dir is " << temp_dir.string() << std::endl; 125 | 126 | fs::create_directory(temp_dir); 127 | 128 | path_container_ctor_test(); 129 | 130 | std::cout << "post-test removal of " << temp_dir << std::endl; 131 | BOOST_TEST(fs::remove_all(temp_dir) != 0); 132 | 133 | return ::boost::report_errors(); 134 | } 135 | -------------------------------------------------------------------------------- /test/design_use_cases.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Minimal class path 5 | 6 | class path 7 | { 8 | public: 9 | path(const char*) 10 | { 11 | std::cout << "path( const char * )\n"; 12 | } 13 | path(const std::string&) 14 | { 15 | std::cout << "path( std::string & )\n"; 16 | } 17 | 18 | // for maximum efficiency, either signature must work 19 | #ifdef BY_VALUE 20 | operator const std::string() const 21 | #else 22 | operator const std::string&() const 23 | #endif 24 | { 25 | std::cout << "operator string\n"; 26 | return m_path; 27 | } 28 | 29 | #ifdef NAMED_CONVERSION 30 | std::string string() const 31 | { 32 | std::cout << "std::string string() const\n"; 33 | return m_path; 34 | } 35 | #endif 36 | 37 | private: 38 | std::string m_path; 39 | }; 40 | 41 | bool operator==(const path&, const path&) 42 | { 43 | std::cout << "operator==( const path &, const path & )\n"; 44 | return true; 45 | } 46 | 47 | // These are the critical use cases. If any of these don't compile, usability 48 | // is unacceptably degraded. 49 | 50 | void f(const path&) 51 | { 52 | std::cout << "f( const path & )\n"; 53 | } 54 | 55 | int main() 56 | { 57 | f("foo"); 58 | f(std::string("foo")); 59 | f(path("foo")); 60 | 61 | std::cout << '\n'; 62 | 63 | std::string s1(path("foo")); 64 | std::string s2 = path("foo"); 65 | s2 = path("foo"); 66 | 67 | #ifdef NAMED_CONVERSION 68 | s2 = path("foo").string(); 69 | #endif 70 | 71 | std::cout << '\n'; 72 | 73 | // these must call bool path( const path &, const path & ); 74 | path("foo") == path("foo"); 75 | path("foo") == "foo"; 76 | path("foo") == std::string("foo"); 77 | "foo" == path("foo"); 78 | std::string("foo") == path("foo"); 79 | 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /test/equivalent.cpp: -------------------------------------------------------------------------------- 1 | // equivalent program -------------------------------------------------------// 2 | 3 | // Copyright (c) 2004 Beman Dawes 4 | 5 | // Use, modification, and distribution is subject to the Boost Software 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy 7 | // at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | // See library home page at http://www.boost.org/libs/filesystem 10 | 11 | //----------------------------------------------------------------------------// 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main(int argc, char* argv[]) 18 | { 19 | boost::filesystem::path::default_name_check(boost::filesystem::native); 20 | if (argc != 3) 21 | { 22 | std::cout << "Usage: equivalent path1 path2\n"; 23 | return 2; 24 | } 25 | 26 | bool eq; 27 | try 28 | { 29 | eq = boost::filesystem::equivalent(argv[1], argv[2]); 30 | } 31 | catch (const std::exception& ex) 32 | { 33 | std::cout << ex.what() << "\n"; 34 | return 3; 35 | } 36 | 37 | std::cout << (eq ? "Paths are equivalent\n" : "Paths are not equivalent\n"); 38 | return !eq; 39 | } 40 | -------------------------------------------------------------------------------- /test/foreach_test.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright 2018 Peter Dimov. 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // 6 | // See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt 8 | 9 | // See library home page at http://www.boost.org/libs/filesystem 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace fs = boost::filesystem; 16 | 17 | int main() 18 | { 19 | { 20 | fs::directory_iterator const it; 21 | 22 | BOOST_FOREACH(fs::path const& p, it) 23 | { 24 | p.string(); 25 | } 26 | } 27 | 28 | #if !defined(BOOST_NO_CXX11_RANGE_BASED_FOR) 29 | 30 | { 31 | fs::directory_iterator const it; 32 | 33 | for (fs::path const& p : it) 34 | { 35 | p.string(); 36 | } 37 | } 38 | 39 | #endif 40 | 41 | { 42 | fs::recursive_directory_iterator it; 43 | 44 | BOOST_FOREACH(fs::path const& p, it) 45 | { 46 | p.string(); 47 | } 48 | } 49 | 50 | #if !defined(BOOST_NO_CXX11_RANGE_BASED_FOR) 51 | 52 | { 53 | fs::recursive_directory_iterator const it; 54 | 55 | for (fs::path const& p : it) 56 | { 57 | p.string(); 58 | } 59 | } 60 | 61 | #endif 62 | } 63 | -------------------------------------------------------------------------------- /test/issues/10038.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | boost::filesystem::copy_file("a", "b"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /test/issues/10205.cpp: -------------------------------------------------------------------------------- 1 | // Linux test; before running: export LANG=foo 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | std::string pathname = "/some/filesystem/path/%%%%"; 11 | 12 | boost::filesystem::path path(pathname); 13 | 14 | std::wcout << path.wstring() << std::endl; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/issues/10485.cpp: -------------------------------------------------------------------------------- 1 | // Copyright iamvfx@gmail.com 2014 2 | 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See http://www.boost.org/LICENSE_1_0.txt 5 | 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | boost::filesystem::path dir("/"); 12 | for (char c : dir.filename().string()) 13 | printf("%c\n", c); 14 | } 15 | -------------------------------------------------------------------------------- /test/issues/10641.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | namespace fs = boost::filesystem; 5 | int main(int argc, char** argv) 6 | { 7 | 8 | try 9 | { 10 | fs::path my_path("test/test.txt"); 11 | cout << "current path is " << my_path << endl; 12 | cout << "parent path is " << my_path.parent_path() << endl; 13 | } 14 | catch (std::exception& e) 15 | { 16 | cerr << endl 17 | << "Error during execution: " << e.what() << endl 18 | << endl; 19 | return EXIT_FAILURE; 20 | } 21 | return EXIT_SUCCESS; 22 | } 23 | -------------------------------------------------------------------------------- /test/issues/11166-remove-race.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | boost::condition_variable cond; 6 | boost::mutex mut; 7 | 8 | #define FNAME ("remove-test") 9 | void remover() 10 | { 11 | while (1) 12 | { 13 | boost::filesystem::remove(FNAME); 14 | } 15 | } 16 | 17 | void creater() 18 | { 19 | for (int i = 0; i < 100000; i++) 20 | std::fstream(FNAME, std::fstream::out); 21 | } 22 | 23 | int main() 24 | { 25 | boost::filesystem::remove(FNAME); 26 | boost::filesystem::remove(FNAME); 27 | 28 | std::cout << "If you got this far, it's OK to remove a file that doesn't exist\n" 29 | "Now trying with one creator thread and two remover threads.\n" 30 | "This is likely to crash after just a few seconds at most." 31 | << std::endl; 32 | 33 | boost::thread c(creater), r1(remover), r2(remover); 34 | 35 | c.join(); 36 | r1.interrupt(); 37 | r1.join(); 38 | r2.interrupt(); 39 | r2.join(); 40 | } 41 | -------------------------------------------------------------------------------- /test/issues/11228--filtered-recursive_directory_iterator-range.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fs = boost::filesystem; 9 | using namespace boost::adaptors; 10 | 11 | int main() 12 | { 13 | fs::recursive_directory_iterator beg("."), end; 14 | 15 | auto fileFilter = [](fs::path const& path) { 16 | return is_regular_file(path); 17 | }; 18 | 19 | std::vector< fs::path > paths; 20 | copy(boost::make_iterator_range(beg, end) | filtered(fileFilter), std::back_inserter(paths)); 21 | 22 | for (auto& p : paths) 23 | std::cout << p << "\n"; 24 | } -------------------------------------------------------------------------------- /test/issues/3332/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace fs = boost::filesystem; 8 | 9 | int main(void) 10 | { 11 | 12 | std::locale global_loc = std::locale(); 13 | std::locale loc(global_loc, new stdext::cvt::codecvt_cp950< wchar_t >); 14 | fs::path::imbue(loc); 15 | 16 | std::cout << "HEADS UP! PIPE OUTPUT TO FILE AND INSPECT WITH HEX OR CP950 EDITOR.\n" 17 | "WINDOWS COMMAND PROMPT FONTS DON'T SUPPORT CHINESE,\n" 18 | "EVEN WITH CODEPAGE SET AND EVEN AS OF WIN 10 TECH PREVIEW." 19 | << std::endl; 20 | 21 | fs::recursive_directory_iterator end; 22 | fs::recursive_directory_iterator iter("C:/boost/test-files/utf-8"); 23 | 24 | while (iter != end) 25 | { 26 | if (fs::is_directory(*iter)) 27 | { 28 | std::cout << "[directory] " << iter->path().generic_string() << std::endl; 29 | } 30 | else if (fs::is_regular_file(*iter)) 31 | { 32 | std::cout << " [file] " << iter->path().generic_string() << std::endl; 33 | } 34 | ++iter; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /test/issues/4329.-basename.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using boost::filesystem::path; 4 | 5 | int main() 6 | { 7 | std::cout << path("a").stem() << std::endl; 8 | std::cout << path("a/").stem() << std::endl; 9 | std::cout << path("a/b").stem() << std::endl; 10 | std::cout << path("a/b/").stem() << std::endl; 11 | std::cout << path("a/b/c").stem() << std::endl; 12 | std::cout << path("a/b/c/").stem() << std::endl; 13 | std::cout << path("a/b/c/d").stem() << std::endl; 14 | std::cout << path("a/b/c/d/").stem() << std::endl; 15 | std::cout << path("a/b/c/d/e").stem() << std::endl; 16 | std::cout << path("a/b/c/d/e/").stem() << std::endl; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/issues/5300-temp-dir-path-130.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/filesystem/f4bb6d0f3ebe9f8b90243d8a98989191925d49d2/test/issues/5300-temp-dir-path-130.cpp -------------------------------------------------------------------------------- /test/issues/6638-global-init-fails-3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace boost::filesystem; 6 | 7 | // The original bug report was that this broke: 8 | // path p(L"C:\\TEMP\\"); 9 | // path r(p / "narrow"); 10 | // That code now works, but ... 11 | 12 | // Nils Gladitz has provided this example ... 13 | 14 | class Test 15 | { 16 | public: 17 | ~Test() 18 | { 19 | path p(L"C:\\TEMP\\"); 20 | path r(p / "narrow"); 21 | } 22 | }; 23 | 24 | // path p("narrow"); 25 | 26 | // fails if static linked and Test object is global variable, but does not fail if 27 | // path p("narrow") line above is not commented out, and also does not fail if the 28 | // Test test2 line below is commented out. 29 | 30 | Test test1; 31 | Test test2; 32 | 33 | int cpp_main(int, char*[]) 34 | { 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /test/issues/70-71-copy.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright 2018 Peter Dimov. 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // 6 | // See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt 8 | 9 | // See library home page at http://www.boost.org/libs/filesystem 10 | 11 | #include 12 | #include 13 | 14 | namespace fs = boost::filesystem; 15 | 16 | int main() 17 | { 18 | BOOST_TEST_THROWS(fs::copy("/tmp/non-existent-a", "/tmp/non-existent-b"), std::exception); 19 | return boost::report_errors(); 20 | } 21 | -------------------------------------------------------------------------------- /test/issues/8930.cpp: -------------------------------------------------------------------------------- 1 | // Before running this test: export LANG=foo 2 | 3 | #include 4 | int main() 5 | { 6 | boost::filesystem::path("/abc").root_directory(); 7 | } 8 | -------------------------------------------------------------------------------- /test/issues/9054_static_const_codecvt_segfault_pre_main.cpp: -------------------------------------------------------------------------------- 1 | #include "boost/filesystem.hpp" 2 | 3 | static const boost::filesystem::path::codecvt_type& dummy = 4 | boost::filesystem::path::codecvt(); 5 | 6 | int main() 7 | { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /test/issues/9219.cpp: -------------------------------------------------------------------------------- 1 | // Boost 9219.cpp --------------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2014 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | // // 12 | // In researching filesystem issues it is convenient to have a program that can be // 13 | // quickly modified to test reported problems. That's the purpose of this file and // 14 | // its associated Visual Studio and Boost.Build infrastructure. // 15 | // // 16 | //--------------------------------------------------------------------------------------// 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | using std::cout; 27 | using std::endl; 28 | namespace fs = boost::filesystem; 29 | 30 | //------------------------------------ cpp_main --------------------------------------// 31 | 32 | int cpp_main(int argc, char* argv[]) 33 | { 34 | cout << "Hello, 9219" << endl; 35 | cout << "This is a test for non-Windows systems" << endl; 36 | 37 | BOOST_TEST(fs::exists(const_cast< char* >("."))); 38 | 39 | return ::boost::report_errors(); 40 | } // cpp_main 41 | -------------------------------------------------------------------------------- /test/issues/99_canonical_with_junction_point.cpp: -------------------------------------------------------------------------------- 1 | // Boost operations_test.cpp ---------------------------------------------------------// 2 | 3 | // Copyright Alexander Grund 2020 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | 12 | #if defined(BOOST_FILESYSTEM_HAS_MKLINK) 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace fs = boost::filesystem; 21 | 22 | struct TmpDir 23 | { 24 | fs::path path; 25 | TmpDir(const fs::path& base) : 26 | path(fs::absolute(base) / fs::unique_path()) 27 | { 28 | fs::create_directories(path); 29 | } 30 | ~TmpDir() 31 | { 32 | boost::system::error_code ec; 33 | fs::remove_all(path, ec); 34 | } 35 | }; 36 | 37 | //! Converts root path of the argument to canonical form, i.e. "C:\" instead of "c:\". 38 | inline fs::path canonicalize_root_path(fs::path const& p) 39 | { 40 | fs::path root_path = p.root_path(); 41 | if (root_path.empty()) 42 | return p; 43 | root_path = fs::canonical(root_path); 44 | fs::path rel_path = p.relative_path(); 45 | if (!rel_path.empty()) 46 | root_path.append(rel_path); 47 | return root_path; 48 | } 49 | 50 | // Test fs::canonical for various path in a Windows directory junction point 51 | // This failed before due to broken handling of absolute paths and ignored ReparseTag 52 | int main() 53 | { 54 | // Note: Use cacnonical form of the root path in all subsequent paths to make path comparisons more stable 55 | const fs::path cwd = canonicalize_root_path(fs::current_path()); 56 | const TmpDir tmp(cwd); 57 | const fs::path junction = tmp.path / "junction"; 58 | const fs::path real = tmp.path / "real"; 59 | const fs::path subDir = "sub"; 60 | fs::create_directories(real / subDir); 61 | fs::current_path(tmp.path); 62 | BOOST_TEST(std::system("mklink /J junction real") == 0); 63 | BOOST_TEST(fs::exists(junction)); 64 | 65 | // Due to a bug there was a dependency on the current path so try the below for all: 66 | std::vector< fs::path > paths; 67 | paths.push_back(cwd); 68 | paths.push_back(junction); 69 | paths.push_back(real); 70 | paths.push_back(junction / subDir); 71 | paths.push_back(real / subDir); 72 | for (std::vector< fs::path >::iterator it = paths.begin(); it != paths.end(); ++it) 73 | { 74 | std::cout << "Testing in " << *it << std::endl; 75 | fs::current_path(*it); 76 | 77 | // Used by canonical, must work too 78 | BOOST_TEST(fs::read_symlink(junction) == real); 79 | 80 | BOOST_TEST(fs::canonical(junction) == real); 81 | BOOST_TEST(fs::canonical(junction / subDir) == real / subDir); 82 | } 83 | 84 | // Restore the original current directory so that temp directory can be removed 85 | fs::current_path(cwd); 86 | 87 | return boost::report_errors(); 88 | } 89 | 90 | #else // defined(BOOST_FILESYSTEM_HAS_MKLINK) 91 | 92 | int main() 93 | { 94 | std::cout << "Skipping test as the target system does not support mklink." << std::endl; 95 | return 0; 96 | } 97 | 98 | #endif // defined(BOOST_FILESYSTEM_HAS_MKLINK) 99 | -------------------------------------------------------------------------------- /test/issues/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Boost Filesystem test/issues Jamfile 2 | 3 | # Copyright Beman Dawes 2014 4 | 5 | # Distributed under the Boost Software License, Version 1.0. 6 | # See www.boost.org/LICENSE_1_0.txt 7 | 8 | # Library home page: http://www.boost.org/libs/filesystem 9 | 10 | project 11 | : requirements 12 | /boost/filesystem//boost_filesystem 13 | static 14 | ; 15 | 16 | test-suite "filesystem-issues" : 17 | # [ run 9054_static_const_codecvt_segfault_pre_main.cpp 18 | # : : : shared : 9054_shared ] 19 | # [ run 9054_static_const_codecvt_segfault_pre_main.cpp 20 | # : : : static : 9054_static ] 21 | # [ run hello_filesystem.cpp 22 | # : : : shared : hello_shared ] 23 | # [ run hello_filesystem.cpp 24 | # : : : static : hello_static ] 25 | # [ run 9219.cpp 26 | # : : : shared : 9219_shared ] 27 | # [ run 9219.cpp 28 | # : : : static : 9219_static ] 29 | # [ run 10485.cpp 30 | # : : : shared always_show_run_output ] 31 | # [ run copy_file-compilation-error-2015-05-04.cpp ] 32 | [ run 6638-convert_aux-fails-init-global.cpp 33 | : : : shared : 6638_shared ] 34 | [ run 6638-convert_aux-fails-init-global.cpp 35 | : : : static : 6638_static ] 36 | 37 | ; 38 | 39 | -------------------------------------------------------------------------------- /test/issues/boost-no-inspect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/filesystem/f4bb6d0f3ebe9f8b90243d8a98989191925d49d2/test/issues/boost-no-inspect -------------------------------------------------------------------------------- /test/issues/copy_file-compilation-error-2015-05-04.cpp: -------------------------------------------------------------------------------- 1 | // Rob Conde reports this fails 2 | // to compile for Boost 1.58 with g++ 4.4.7 but is OK with FC++ 2013 3 | 4 | #include "boost/filesystem/operations.hpp" 5 | 6 | void myFunc() 7 | { 8 | using namespace boost::filesystem; 9 | 10 | copy_options opt(copy_options::overwrite_existing); 11 | 12 | copy_file(path("p1"), path("p2"), copy_options::overwrite_existing); 13 | // copy_file(path("p1"),path("p2"),opt); 14 | } -------------------------------------------------------------------------------- /test/issues/fchmodat_AT_SYMLINK_NOFOLLOW_6659.cpp: -------------------------------------------------------------------------------- 1 | // Test program to demonstrate that Linux does not support AT_SYMLINK_NOFOLLOW 2 | 3 | // Copyright Duncan Exon Smith 2012 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Test this by running: 9 | // 10 | // rm -rf data && mkdir data && g++ -otest-fchmodat fchmodat_AT_SYMLINK_NOFOLLOW_6659.cpp && (cd data && ../test-fchmodat) 11 | // 12 | // If no assertions go off, then it looks like fchmodat is supported, 13 | // but AT_SYMLINK_NOFOLLOW is not supported. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #ifdef NDEBUG 22 | #error This program depends on assert() so makes no sense if NDEBUG is defined 23 | #endif 24 | 25 | int main(int argc, char* argv[]) 26 | { 27 | { 28 | std::ofstream file("out"); 29 | file << "contents"; 30 | } 31 | 32 | assert(!::symlink("out", "sym")); 33 | 34 | assert(!::fchmodat(AT_FDCWD, "out", S_IRUSR | S_IWUSR | S_IXUSR, 0)); 35 | assert(!::fchmodat(AT_FDCWD, "sym", S_IRUSR | S_IWUSR | S_IXUSR, 0)); 36 | 37 | assert(::fchmodat(AT_FDCWD, "sym", S_IRUSR | S_IWUSR | S_IXUSR, AT_SYMLINK_NOFOLLOW) == -1); 38 | assert(errno == ENOTSUP); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /test/issues/hello_filesystem.cpp: -------------------------------------------------------------------------------- 1 | // Boost hello_filesystem.cpp --------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2014 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | // // 12 | // In researching filesystem issues it is convenient to have a program that can be // 13 | // quickly modified to test reported problems. That's the purpose of this file and // 14 | // its associated Visual Studio and Boost.Build infrastructure. // 15 | // // 16 | //--------------------------------------------------------------------------------------// 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | using std::cout; 27 | using std::endl; 28 | namespace fs = boost::filesystem; 29 | 30 | //------------------------------------ cpp_main --------------------------------------// 31 | 32 | int cpp_main(int argc, char* argv[]) 33 | { 34 | cout << "Hello, filesystem world" << endl; 35 | 36 | BOOST_TEST(fs::exists(".")); 37 | 38 | return ::boost::report_errors(); 39 | } // cpp_main 40 | -------------------------------------------------------------------------------- /test/issues/readme.txt: -------------------------------------------------------------------------------- 1 | This directory contains tests related to specific issues. 2 | 3 | The names are intended to indicate both the function or condition being tested 4 | and the issue number. 5 | 6 | ----- 7 | Copyright Beman Dawes 2012 8 | Distributed under the Boost Software License, Version 1.0. 9 | See http://www.boost.org/LICENSE_1_0.txt 10 | -------------------------------------------------------------------------------- /test/issues/recurse_dir_iter_5403.cpp: -------------------------------------------------------------------------------- 1 | // Boost Filesystem recurse_dir_iter_test.cpp ----------------------------------------// 2 | 3 | // Copyright Beman Dawes 2014. 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | 12 | // See deprecated_test for tests of deprecated features 13 | #ifndef BOOST_FILESYSTEM_NO_DEPRECATED 14 | #define BOOST_FILESYSTEM_NO_DEPRECATED 15 | #endif 16 | #ifndef BOOST_SYSTEM_NO_DEPRECATED 17 | #define BOOST_SYSTEM_NO_DEPRECATED 18 | #endif 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace fs = boost::filesystem; 28 | using boost::system::error_code; 29 | 30 | #include 31 | 32 | using std::cout; 33 | using std::endl; 34 | 35 | namespace { 36 | typedef int errno_t; 37 | std::string platform(BOOST_PLATFORM); 38 | bool report_throws = false; 39 | bool cleanup = true; 40 | bool skip_long_windows_tests = false; 41 | 42 | } // unnamed namespace 43 | 44 | //------------------------------------------------------------------------------------// 45 | // // 46 | // main // 47 | // // 48 | //------------------------------------------------------------------------------------// 49 | 50 | int cpp_main(int argc, char* argv[]) 51 | { 52 | // document state of critical macros 53 | #ifdef BOOST_POSIX_API 54 | cout << "BOOST_POSIX_API is defined\n"; 55 | #endif 56 | #ifdef BOOST_WINDOWS_API 57 | cout << "BOOST_WINDOWS_API is defined\n"; 58 | #endif 59 | 60 | for (; argc > 1; --argc, ++argv) 61 | { 62 | //if (*argv[1]=='-' && *(argv[1]+1)=='t') 63 | // report_throws = true; 64 | //else if (*argv[1]=='-' && *(argv[1]+1)=='x') 65 | // cleanup = false; 66 | //else if (*argv[1]=='-' && *(argv[1]+1)=='w') 67 | // skip_long_windows_tests = true; 68 | } 69 | 70 | // The choice of platform to test is made at runtime rather than compile-time 71 | // so that compile errors for all platforms will be detected even though 72 | // only the current platform is runtime tested. 73 | #if defined(BOOST_POSIX_API) 74 | platform = "POSIX"; 75 | #elif defined(BOOST_WINDOWS_API) 76 | platform = "Windows"; 77 | #else 78 | #error neither BOOST_POSIX_API nor BOOST_WINDOWS_API is defined. See boost/system/api_config.hpp 79 | #endif 80 | cout << "API is " << platform << endl; 81 | cout << "initial_path() is " << fs::initial_path() << endl; 82 | fs::path ip = fs::initial_path(); 83 | 84 | for (fs::path::const_iterator it = ip.begin(); it != ip.end(); ++it) 85 | { 86 | if (it != ip.begin()) 87 | cout << ", "; 88 | cout << *it; 89 | } 90 | cout << endl; 91 | 92 | // From the root, walk the directory tree looking for a permissions error 93 | 94 | fs::recursive_directory_iterator it("/"); 95 | fs::recursive_directory_iterator end_it; 96 | 97 | // The increment function has an invarient that it always makes progress, 98 | // so even if an error occurs this loop will eventually terminate. 99 | 100 | while (it != end_it) 101 | { 102 | error_code ec; 103 | fs::path init_path = it->path(); 104 | it.increment(ec); 105 | if (ec) 106 | { 107 | cout << "initial path: " << init_path << endl; 108 | cout << "error_code: " << ec.value() << " with msg: " << ec.message() << endl; 109 | if (it != end_it) 110 | cout << "post-increment path: " << it->path() << endl; 111 | } 112 | } 113 | 114 | cout << "returning from main()" << endl; 115 | return ::boost::report_errors(); 116 | } 117 | -------------------------------------------------------------------------------- /test/issues/reparse_tag_file_placeholder.cpp: -------------------------------------------------------------------------------- 1 | // Boost reparse_tag_file_placeholder.cpp ---------------------------------------------------------// 2 | 3 | // Copyright Roman Savchenko 2020 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | 12 | #if defined(BOOST_FILESYSTEM_HAS_MKLINK) 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #ifdef _MSC_VER 24 | #pragma comment(lib, "Advapi32.lib") 25 | #endif 26 | 27 | // Test correct boost::filesystem::status when reparse point ReparseTag set to IO_REPARSE_TAG_FILE_PLACEHOLDER 28 | // https://docs.microsoft.com/en-us/windows/compatibility/placeholder-files?redirectedfrom=MSDN 29 | 30 | // from ntifs.h, which can only be used by drivers 31 | typedef struct _REPARSE_DATA_BUFFER 32 | { 33 | ULONG ReparseTag; 34 | USHORT ReparseDataLength; 35 | USHORT Reserved; 36 | union 37 | { 38 | struct 39 | { 40 | USHORT SubstituteNameOffset; 41 | USHORT SubstituteNameLength; 42 | USHORT PrintNameOffset; 43 | USHORT PrintNameLength; 44 | ULONG Flags; 45 | WCHAR PathBuffer[1]; 46 | } SymbolicLinkReparseBuffer; 47 | struct 48 | { 49 | USHORT SubstituteNameOffset; 50 | USHORT SubstituteNameLength; 51 | USHORT PrintNameOffset; 52 | USHORT PrintNameLength; 53 | WCHAR PathBuffer[1]; 54 | } MountPointReparseBuffer; 55 | struct 56 | { 57 | UCHAR DataBuffer[1]; 58 | } GenericReparseBuffer; 59 | }; 60 | } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; 61 | 62 | #ifndef IO_REPARSE_TAG_FILE_PLACEHOLDER 63 | #define IO_REPARSE_TAG_FILE_PLACEHOLDER (0x80000015L) 64 | #endif 65 | 66 | #ifndef FSCTL_SET_REPARSE_POINT 67 | #define FSCTL_SET_REPARSE_POINT (0x000900a4) 68 | #endif 69 | 70 | #ifndef REPARSE_DATA_BUFFER_HEADER_SIZE 71 | #define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER, GenericReparseBuffer) 72 | #endif 73 | 74 | bool obtain_restore_privilege() 75 | { 76 | HANDLE hToken; 77 | if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) 78 | { 79 | DWORD err = GetLastError(); 80 | std::cout << "OpenProcessToken() failed with: " << err << std::endl; 81 | return false; 82 | } 83 | 84 | TOKEN_PRIVILEGES tp; 85 | if (!LookupPrivilegeValue(nullptr, SE_RESTORE_NAME, &tp.Privileges[0].Luid)) 86 | { 87 | DWORD err = GetLastError(); 88 | CloseHandle(hToken); 89 | std::cout << "LookupPrivilegeValue() failed with: " << err << std::endl; 90 | return false; 91 | } 92 | 93 | tp.PrivilegeCount = 1; 94 | tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 95 | 96 | if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr)) 97 | { 98 | DWORD err = GetLastError(); 99 | CloseHandle(hToken); 100 | std::cout << "AdjustTokenPrivileges() failed with: " << err << std::endl; 101 | return false; 102 | } 103 | 104 | CloseHandle(hToken); 105 | return true; 106 | } 107 | 108 | bool create_io_reparse_file_placeholder(const wchar_t* name) 109 | { 110 | if (!obtain_restore_privilege()) 111 | { 112 | return false; 113 | } 114 | 115 | HANDLE hHandle = CreateFileW(name, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_FLAG_OPEN_REPARSE_POINT, 0); 116 | if (hHandle == INVALID_HANDLE_VALUE) 117 | { 118 | DWORD err = GetLastError(); 119 | std::cout << "CreateFile() failed with: " << err << std::endl; 120 | return false; 121 | } 122 | 123 | PREPARSE_DATA_BUFFER pReparse = reinterpret_cast< PREPARSE_DATA_BUFFER >(GlobalAlloc(GPTR, MAXIMUM_REPARSE_DATA_BUFFER_SIZE)); 124 | if (!pReparse) 125 | { 126 | DWORD err = GetLastError(); 127 | CloseHandle(hHandle); 128 | std::cout << "GlobalAlloc() failed with: " << err << std::endl; 129 | return false; 130 | } 131 | //note: IO_REPARSE_TAG_FILE_PLACEHOLDER - just to show that reparse point could be not only symlink or junction 132 | pReparse->ReparseTag = IO_REPARSE_TAG_FILE_PLACEHOLDER; 133 | 134 | DWORD dwLen; 135 | bool ret = !!DeviceIoControl(hHandle, FSCTL_SET_REPARSE_POINT, pReparse, pReparse->ReparseDataLength + REPARSE_DATA_BUFFER_HEADER_SIZE, nullptr, 0, &dwLen, nullptr); 136 | if (!ret) 137 | { 138 | DWORD err = GetLastError(); 139 | std::cout << "DeviceIoControl() failed with: " << err << std::endl; 140 | } 141 | 142 | CloseHandle(hHandle); 143 | GlobalFree(pReparse); 144 | return ret; 145 | } 146 | 147 | int main() 148 | { 149 | boost::filesystem::path rpt = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(L"bfs_reparse_point_test-%%%%-%%%%.txt"); 150 | std::cout << "Creating file placeholder reparse point: " << rpt.string() << std::endl; 151 | 152 | BOOST_TEST(create_io_reparse_file_placeholder(rpt.native().c_str())); 153 | BOOST_TEST_NO_THROW(BOOST_TEST(boost::filesystem::status(rpt).type() == boost::filesystem::reparse_file)); 154 | BOOST_TEST_NO_THROW(BOOST_TEST(boost::filesystem::remove(rpt))); 155 | 156 | return boost::report_errors(); 157 | } 158 | 159 | #else // defined(BOOST_FILESYSTEM_HAS_MKLINK) 160 | 161 | int main() 162 | { 163 | std::cout << "Skipping test as the target system does not support mklink." << std::endl; 164 | return 0; 165 | } 166 | 167 | #endif // defined(BOOST_FILESYSTEM_HAS_MKLINK) 168 | -------------------------------------------------------------------------------- /test/large_file_support_test.cpp: -------------------------------------------------------------------------------- 1 | // Boost large_file_support_test.cpp ---------------------------------------// 2 | 3 | // Copyright Beman Dawes 2004. 4 | // Use, modification, and distribution is subject to the Boost Software 5 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | // See library home page at http://www.boost.org/libs/filesystem 9 | 10 | // See deprecated_test for tests of deprecated features 11 | #define BOOST_FILESYSTEM_NO_DEPRECATED 12 | #define BOOST_SYSTEM_NO_DEPRECATED 13 | 14 | #include 15 | #include 16 | 17 | namespace fs = boost::filesystem; 18 | 19 | int main() 20 | { 21 | if (fs::detail::possible_large_file_size_support()) 22 | { 23 | std::cout << "It appears that file sizes greater that 2 gigabytes are possible\n" 24 | "for this configuration on this platform since the operating system\n" 25 | "does use a large enough integer type to report large file sizes.\n\n" 26 | "Whether or not such support is actually present depends on the OS\n"; 27 | return 0; 28 | } 29 | std::cout << "The operating system is using an integer type to report file sizes\n" 30 | "that can not represent file sizes greater that 2 gigabytes (31-bits).\n" 31 | "Thus the Filesystem Library will not correctly deal with such large\n" 32 | "files. If you think that this operatiing system should be able to\n" 33 | "support large files, please report the problem to the Boost developers\n" 34 | "mailing list.\n"; 35 | return 1; 36 | } 37 | -------------------------------------------------------------------------------- /test/locale_info.cpp: -------------------------------------------------------------------------------- 1 | // locale_info.cpp ---------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2011 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | #ifdef _MSC_VER 15 | #pragma warning(push) 16 | #pragma warning(disable : 4996) // ... Function call with parameters that may be unsafe 17 | #endif 18 | 19 | namespace { 20 | void facet_info(const locale& loc, const char* msg) 21 | { 22 | cout << "has_facet >(" 23 | << msg << ") is " 24 | << (has_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc) ? "true\n" : "false\n"); 25 | } 26 | 27 | void default_info() 28 | { 29 | try 30 | { 31 | locale loc; 32 | cout << "\nlocale default construction OK" << endl; 33 | facet_info(loc, "locale()"); 34 | } 35 | catch (const exception& ex) 36 | { 37 | cout << "\nlocale default construction threw: " << ex.what() << endl; 38 | } 39 | } 40 | 41 | void null_string_info() 42 | { 43 | try 44 | { 45 | locale loc(""); 46 | cout << "\nlocale(\"\") construction OK" << endl; 47 | facet_info(loc, "locale(\"\")"); 48 | } 49 | catch (const exception& ex) 50 | { 51 | cout << "\nlocale(\"\") construction threw: " << ex.what() << endl; 52 | } 53 | } 54 | 55 | void classic_info() 56 | { 57 | try 58 | { 59 | locale loc(locale::classic()); 60 | cout << "\nlocale(locale::classic()) copy construction OK" << endl; 61 | facet_info(loc, "locale::classic()"); 62 | } 63 | catch (const exception& ex) 64 | { 65 | cout << "\nlocale(locale::clasic()) copy construction threw: " << ex.what() << endl; 66 | } 67 | } 68 | } // namespace 69 | 70 | int main() 71 | { 72 | const char* lang = getenv("LANG"); 73 | cout << "\nLANG environmental variable is " 74 | << (lang ? lang : "not present") << endl; 75 | 76 | default_info(); 77 | null_string_info(); 78 | classic_info(); 79 | 80 | return 0; 81 | } 82 | 83 | #ifdef _MSC_VER 84 | #pragma warning(pop) 85 | #endif 86 | -------------------------------------------------------------------------------- /test/long_path_test.cpp: -------------------------------------------------------------------------------- 1 | // long_path_test.cpp ----------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2011 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // See http://www.boost.org/libs/btree for documentation. 9 | 10 | // See http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | using namespace boost::filesystem; 19 | 20 | #include 21 | #include 22 | 23 | namespace { 24 | } // unnamed namespace 25 | 26 | int cpp_main(int, char*[]) 27 | { 28 | 29 | std::string prefix("d:\\temp\\"); 30 | std::cout << "prefix is " << prefix << '\n'; 31 | 32 | const std::size_t safe_size = 260 - prefix.size() - 100; // Windows MAX_PATH is 260 33 | 34 | std::string safe_x_string(safe_size, 'x'); 35 | std::string safe_y_string(safe_size, 'y'); 36 | std::string path_escape("\\\\?\\"); 37 | 38 | path x_p(prefix + safe_x_string); 39 | path y_p(path_escape + prefix + safe_x_string + "\\" + safe_y_string); 40 | 41 | std::cout << "x_p.native().size() is " << x_p.native().size() << '\n'; 42 | std::cout << "y_p.native().size() is " << y_p.native().size() << '\n'; 43 | 44 | create_directory(x_p); 45 | BOOST_TEST(exists(x_p)); 46 | create_directory(y_p); 47 | BOOST_TEST(exists(y_p)); 48 | 49 | //std::cout << "directory x.../y... ready for testing, where ... is " << safe_size 50 | // << " repeats of x and y, respectively\n"; 51 | 52 | BOOST_TEST(exists(x_p)); 53 | 54 | //remove_all(x_p); 55 | 56 | return ::boost::report_errors(); 57 | } 58 | -------------------------------------------------------------------------------- /test/macro_default_test.cpp: -------------------------------------------------------------------------------- 1 | // macro_default_test program --------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2012 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #undef BOOST_ALL_DYN_LINK 11 | #undef BOOST_ALL_STATIC_LINK 12 | #undef BOOST_FILESYSTEM_DYN_LINK 13 | #undef BOOST_FILESYSTEM_STATIC_LINK 14 | #undef BOOST_SYSTEM_DYN_LINK 15 | #undef BOOST_SYSTEM_STATIC_LINK 16 | 17 | #ifndef BOOST_ALL_NO_LIB 18 | #define BOOST_ALL_NO_LIB 19 | #endif 20 | 21 | #include 22 | #include 23 | 24 | #ifndef BOOST_FILESYSTEM_STATIC_LINK 25 | #error BOOST_FILESYSTEM_STATIC_LINK not set by default 26 | #endif 27 | 28 | #ifndef BOOST_SYSTEM_STATIC_LINK 29 | #error BOOST_SYSTEM_STATIC_LINK not set by default 30 | #endif 31 | 32 | int main() 33 | { 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/macro_value.hpp: -------------------------------------------------------------------------------- 1 | // boost/filesystem/detail/macro_value.hpp -------------------------------------------// 2 | 3 | // (C) Copyright John Maddock 2001 - 2003 4 | // (C) Copyright Jens Maurer 2001 5 | // (C) Copyright Peter Dimov 2001 6 | // (C) Copyright Darin Adler 2001 7 | // (C) Copyright Beman Dawes 2002 8 | 9 | // Distributed under the Boost Software License, Version 1.0. 10 | // See http://www.boost.org/LICENSE_1_0.txt 11 | 12 | // Library home page: http://www.boost.org/libs/filesystem 13 | 14 | //--------------------------------------------------------------------------------------// 15 | 16 | #ifndef BOOST_FILESYSTEM_MACRO_VALUE_HPP 17 | #define BOOST_FILESYSTEM_MACRO_VALUE_HPP 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace boost { 24 | namespace detail { 25 | 26 | inline const char* macro_value(const char* name, const char* value) 27 | { 28 | static const char* no_value = "[no value]"; 29 | static const char* not_defined = "[not defined]"; 30 | 31 | BOOST_ASSERT_MSG(name, "name argument must not be a null pointer"); 32 | BOOST_ASSERT_MSG(value, "value argument must not be a null pointer"); 33 | 34 | return strcmp(name, value + 1) ? ((*value && *(value + 1)) ? (value + 1) : no_value) : not_defined; // name == value+1 so the macro is not defined 35 | } 36 | 37 | } // namespace detail 38 | } // namespace boost 39 | 40 | #define BOOST_MACRO_VALUE(X) boost::detail::macro_value(#X, BOOST_STRINGIZE(=X)) 41 | 42 | #endif // BOOST_FILESYSTEM_MACRO_VALUE_HPP 43 | -------------------------------------------------------------------------------- /test/odr1_test.cpp: -------------------------------------------------------------------------------- 1 | // Boost Filesystem odr1_test.cpp ----------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2014. 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | 12 | namespace boost { 13 | namespace filesystem { 14 | void tu2(); 15 | } 16 | } // namespace boost 17 | 18 | int main() 19 | { 20 | boost::filesystem::tu2(); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/odr2_test.cpp: -------------------------------------------------------------------------------- 1 | // Boost Filesystem odr2_test.cpp ----------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2014. 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | 12 | namespace boost { 13 | namespace filesystem { 14 | 15 | void tu2() 16 | { 17 | } 18 | 19 | } // namespace filesystem 20 | } // namespace boost 21 | -------------------------------------------------------------------------------- /test/path_iter_ctor_overload_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Andrey Semashev. 2 | // 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // The test verifies that \c boost::filesystem::path constructors 9 | // from iterators don't interfere with initializer list constructor. 10 | // 11 | // https://github.com/boostorg/filesystem/issues/287 12 | 13 | #include 14 | #include 15 | 16 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) 17 | 18 | #include 19 | 20 | void test(std::initializer_list< boost::filesystem::path > paths) 21 | { 22 | } 23 | 24 | void test(boost::filesystem::path const& path) 25 | { 26 | } 27 | 28 | int main() 29 | { 30 | boost::filesystem::path a, b; 31 | test({a, b}); 32 | } 33 | 34 | #else // !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) 35 | 36 | int main() 37 | { 38 | } 39 | 40 | #endif // !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) 41 | -------------------------------------------------------------------------------- /test/path_operator_ambiguity.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Andrey Semashev 2023 2 | // 3 | // Use, modification, and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // See library home page at http://www.boost.org/libs/filesystem 8 | // 9 | // This test verifies that a using directive does not introduce operator 10 | // ambiguity with the standard library. 11 | // https://github.com/boostorg/filesystem/issues/285 12 | 13 | #include 14 | #include 15 | 16 | using namespace boost::filesystem; 17 | 18 | bool test_eq(char* arg) 19 | { 20 | return std::string("abc") == arg; 21 | } 22 | 23 | bool test_ne(char* arg) 24 | { 25 | return std::string("def") != arg; 26 | } 27 | 28 | bool test_lt(char* arg) 29 | { 30 | return std::string("ghi") < arg; 31 | } 32 | 33 | bool test_gt(char* arg) 34 | { 35 | return std::string("jkl") > arg; 36 | } 37 | 38 | bool test_le(char* arg) 39 | { 40 | return std::string("mno") <= arg; 41 | } 42 | 43 | bool test_ge(char* arg) 44 | { 45 | return std::string("pqr") >= arg; 46 | } 47 | 48 | int main(int, char* argv[]) 49 | { 50 | return test_eq(argv[0]) + test_ne(argv[0]) + 51 | test_lt(argv[0]) + test_gt(argv[0]) + 52 | test_le(argv[0]) + test_ge(argv[0]); 53 | } 54 | -------------------------------------------------------------------------------- /test/path_times.cpp: -------------------------------------------------------------------------------- 1 | // Boost Filesystem path_times.cpp ---------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2013 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #include 11 | 12 | #ifndef BOOST_FILESYSTEM_NO_DEPRECATED 13 | #define BOOST_FILESYSTEM_NO_DEPRECATED 14 | #endif 15 | #ifndef BOOST_SYSTEM_NO_DEPRECATED 16 | #define BOOST_SYSTEM_NO_DEPRECATED 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | namespace fs = boost::filesystem; 26 | using namespace boost::timer; 27 | 28 | #include 29 | #include 30 | 31 | using std::cout; 32 | using std::endl; 33 | 34 | namespace { 35 | boost::int64_t max_cycles; 36 | 37 | template< class STD_STRING > 38 | nanosecond_type time_ctor(const STD_STRING& s) 39 | { 40 | boost::timer::auto_cpu_timer tmr; 41 | boost::int64_t count = 0; 42 | do 43 | { 44 | fs::path p(s); 45 | ++count; 46 | } while (count < max_cycles); 47 | 48 | boost::timer::cpu_times elapsed = tmr.elapsed(); 49 | return elapsed.user + elapsed.system; 50 | } 51 | 52 | nanosecond_type time_loop() 53 | { 54 | boost::timer::auto_cpu_timer tmr; 55 | boost::int64_t count = 0; 56 | do 57 | { 58 | ++count; 59 | } while (count < max_cycles); 60 | 61 | boost::timer::cpu_times elapsed = tmr.elapsed(); 62 | return elapsed.user + elapsed.system; 63 | } 64 | } // unnamed namespace 65 | 66 | //--------------------------------------------------------------------------------------// 67 | // main // 68 | //--------------------------------------------------------------------------------------// 69 | 70 | int cpp_main(int argc, char* argv[]) 71 | { 72 | if (argc != 2) 73 | { 74 | cout << "Usage: path_times \n"; 75 | return 1; 76 | } 77 | 78 | max_cycles = std::atoi(argv[1]) * 1000000LL; 79 | cout << "testing " << std::atoi(argv[1]) << " million cycles" << endl; 80 | 81 | cout << "time_loop" << endl; 82 | nanosecond_type x = time_loop(); 83 | 84 | cout << "time_ctor with string" << endl; 85 | nanosecond_type s = time_ctor(std::string("/foo/bar/baz")); 86 | 87 | cout << "time_ctor with wstring" << endl; 88 | nanosecond_type w = time_ctor(std::wstring(L"/foo/bar/baz")); 89 | 90 | if (s > w) 91 | cout << "narrow/wide CPU-time ratio = " << long double(s) / w << endl; 92 | else 93 | cout << "wide/narrow CPU-time ratio = " << long double(w) / s << endl; 94 | 95 | cout << "returning from main()" << endl; 96 | return 0; 97 | } 98 | -------------------------------------------------------------------------------- /test/quick.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright 2017 Peter Dimov. 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // 6 | // See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt 8 | 9 | // See library home page at http://www.boost.org/libs/system 10 | 11 | #include 12 | #include 13 | 14 | namespace fs = boost::filesystem; 15 | 16 | int main() 17 | { 18 | fs::path p1("a"); 19 | fs::path p2 = p1 / "b"; 20 | 21 | BOOST_TEST_EQ(p2, "a/b"); 22 | 23 | return boost::report_errors(); 24 | } 25 | -------------------------------------------------------------------------------- /test/relative_test.cpp: -------------------------------------------------------------------------------- 1 | // filesystem relative_test.cpp ---------------------------------------------------- // 2 | 3 | // Copyright Beman Dawes 2015 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | // ---------------------------------------------------------------------------------- // 11 | // 12 | // At least initially, development is easier if these tests are in a separate file. 13 | // 14 | // ---------------------------------------------------------------------------------- // 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | using boost::filesystem::path; 22 | using std::cout; 23 | using std::endl; 24 | 25 | namespace { 26 | 27 | void lexically_relative_test() 28 | { 29 | cout << "lexically_relative_test..." << endl; 30 | 31 | BOOST_TEST(path("").lexically_relative("") == ""); 32 | BOOST_TEST(path("").lexically_relative("/foo") == ""); 33 | BOOST_TEST(path("/foo").lexically_relative("") == ""); 34 | BOOST_TEST(path("/foo").lexically_relative("/foo") == "."); 35 | BOOST_TEST(path("").lexically_relative("foo") == ""); 36 | BOOST_TEST(path("foo").lexically_relative("") == ""); 37 | BOOST_TEST(path("foo").lexically_relative("foo") == "."); 38 | 39 | BOOST_TEST(path("a/b/c").lexically_relative("a") == "b/c"); 40 | BOOST_TEST(path("a//b//c").lexically_relative("a") == "b/c"); 41 | BOOST_TEST(path("a/b/c").lexically_relative("a/b") == "c"); 42 | BOOST_TEST(path("a///b//c").lexically_relative("a//b") == "c"); 43 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/c") == "."); 44 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/c/x") == ".."); 45 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/c/x/y") == "../.."); 46 | BOOST_TEST(path("a/b/c").lexically_relative("a/x") == "../b/c"); 47 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/x") == "../c"); 48 | BOOST_TEST(path("a/b/c").lexically_relative("a/x/y") == "../../b/c"); 49 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/x/y") == "../../c"); 50 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/c/x/y/z") == "../../.."); 51 | BOOST_TEST(path("a/b/c").lexically_relative("a/") == "b/c"); 52 | BOOST_TEST(path("a/b/c").lexically_relative("a/.") == "b/c"); 53 | BOOST_TEST(path("a/b/c").lexically_relative("a/./") == "b/c"); 54 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/..") == ""); 55 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/../") == ""); 56 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/d/..") == "c"); 57 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/d/../") == "c"); 58 | 59 | // paths unrelated except first element, and first element is root directory 60 | BOOST_TEST(path("/a/b/c").lexically_relative("/x") == "../a/b/c"); 61 | BOOST_TEST(path("/a/b/c").lexically_relative("/x/y") == "../../a/b/c"); 62 | BOOST_TEST(path("/a/b/c").lexically_relative("/x/y/z") == "../../../a/b/c"); 63 | 64 | // paths unrelated 65 | BOOST_TEST(path("a/b/c").lexically_relative("x") == ""); 66 | BOOST_TEST(path("a/b/c").lexically_relative("x/y") == ""); 67 | BOOST_TEST(path("a/b/c").lexically_relative("x/y/z") == ""); 68 | BOOST_TEST(path("a/b/c").lexically_relative("/x") == ""); 69 | BOOST_TEST(path("a/b/c").lexically_relative("/x/y") == ""); 70 | BOOST_TEST(path("a/b/c").lexically_relative("/x/y/z") == ""); 71 | BOOST_TEST(path("a/b/c").lexically_relative("/a/b/c") == ""); 72 | 73 | // TODO: add some Windows-only test cases that probe presence or absence of 74 | // drive specifier-and root-directory 75 | 76 | // Some tests from Jamie Allsop's paper 77 | BOOST_TEST(path("/a/d").lexically_relative("/a/b/c") == "../../d"); 78 | BOOST_TEST(path("/a/b/c").lexically_relative("/a/d") == "../b/c"); 79 | #ifdef BOOST_WINDOWS_API 80 | BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == "../y"); 81 | #else 82 | BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == ""); 83 | #endif 84 | BOOST_TEST(path("d:\\y").lexically_relative("c:\\x") == ""); 85 | 86 | // From issue #1976 87 | BOOST_TEST(path("/foo/new").lexically_relative("/foo/bar") == "../new"); 88 | } 89 | 90 | void lexically_proximate_test() 91 | { 92 | cout << "lexically_proximate_test..." << endl; 93 | // paths unrelated 94 | BOOST_TEST(path("a/b/c").lexically_proximate("x") == "a/b/c"); 95 | } 96 | 97 | } // unnamed namespace 98 | 99 | //--------------------------------------------------------------------------------------// 100 | // // 101 | // main // 102 | // // 103 | //--------------------------------------------------------------------------------------// 104 | 105 | int test_main(int, char*[]) 106 | { 107 | // document state of critical macros 108 | #ifdef BOOST_POSIX_API 109 | cout << "BOOST_POSIX_API" << endl; 110 | #endif 111 | #ifdef BOOST_WINDOWS_API 112 | cout << "BOOST_WINDOWS_API" << endl; 113 | #endif 114 | 115 | lexically_relative_test(); 116 | lexically_proximate_test(); 117 | 118 | return ::boost::report_errors(); 119 | } 120 | -------------------------------------------------------------------------------- /test/sample_test.cpp: -------------------------------------------------------------------------------- 1 | // filesystem sample_test.cpp ----------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2012 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // --------------------------------------------------------------------------// 9 | // 10 | // This program provides a template for bug reporting test cases. 11 | // 12 | // --------------------------------------------------------------------------// 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #ifndef BOOST_LIGHTWEIGHT_MAIN 21 | #include 22 | #else 23 | #include 24 | #endif 25 | 26 | namespace fs = boost::filesystem; 27 | using fs::path; 28 | using std::cout; 29 | using std::endl; 30 | using std::string; 31 | using std::wstring; 32 | 33 | namespace { 34 | bool cleanup = true; 35 | } 36 | 37 | // cpp_main ----------------------------------------------------------------// 38 | 39 | int cpp_main(int argc, char* argv[]) 40 | { 41 | if (argc > 1 && std::strcmp(argv[1], "--no-cleanup") == 0) 42 | cleanup = false; 43 | 44 | // Test cases go after this block of comments 45 | // Use test case macros from boost/core/lightweight_test.hpp: 46 | // 47 | // BOOST_TEST(predicate); // test passes if predicate evaluates to true 48 | // BOOST_TEST_EQ(x, y); // test passes if x == y 49 | // BOOST_TEST_NE(x, y); // test passes if x != y 50 | // BOOST_ERROR(msg); // test fails, outputs msg 51 | // Examples: 52 | // BOOST_TEST(path("f00").size() == 3); // test passes 53 | // BOOST_TEST_EQ(path("f00").size(), 3); // test passes 54 | // BOOST_MSG("Oops!"); // test fails, outputs "Oops!" 55 | 56 | if (cleanup) 57 | { 58 | // Remove any test files or directories here 59 | } 60 | 61 | return ::boost::report_errors(); 62 | } 63 | -------------------------------------------------------------------------------- /test/test_cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Andrey Semashev 2 | # 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt 5 | # 6 | # NOTE: This does NOT run the unit tests for Boost.Filesystem. 7 | # It only tests, if the CMakeLists.txt file in it's root works as expected 8 | 9 | cmake_minimum_required(VERSION 3.5...3.16) 10 | 11 | project(BoostFilesystemCMakeSelfTest) 12 | 13 | # Use experimental superproject to pull library dependencies recursively 14 | set(BOOST_ENABLE_CMAKE 1) 15 | add_subdirectory(../../../.. "${CMAKE_CURRENT_BINARY_DIR}/boost_superproject") 16 | 17 | add_definitions(-DBOOST_ALL_NO_LIB) 18 | 19 | add_executable(boost_filesystem_cmake_self_test main.cpp) 20 | target_link_libraries(boost_filesystem_cmake_self_test Boost::filesystem) 21 | -------------------------------------------------------------------------------- /test/test_cmake/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Andrey Semashev 2 | // 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // See accompanying file LICENSE_1_0.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #include 8 | 9 | int main() 10 | { 11 | boost::filesystem::path p("."); 12 | boost::filesystem::is_directory(p); 13 | } 14 | -------------------------------------------------------------------------------- /test/test_codecvt.hpp: -------------------------------------------------------------------------------- 1 | // test_codecvt.hpp ------------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2009, 2010 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | #ifndef BOOST_FILESYSTEM_TEST_CODECVT_HPP 11 | #define BOOST_FILESYSTEM_TEST_CODECVT_HPP 12 | 13 | #include 14 | #include 15 | #include // for mbstate_t 16 | 17 | //------------------------------------------------------------------------------------// 18 | // // 19 | // class test_codecvt // 20 | // // 21 | // Warning: partial implementation; even do_in and do_out only partially meet the // 22 | // standard library specifications as the "to" buffer must hold the entire result. // 23 | // // 24 | // The value of a wide character is the value of the corresponding narrow character // 25 | // plus 1. This ensures that compares against expected values will fail if the // 26 | // code conversion did not occur as expected. // 27 | // // 28 | //------------------------------------------------------------------------------------// 29 | 30 | class test_codecvt : 31 | public std::codecvt< wchar_t, char, std::mbstate_t > 32 | { 33 | public: 34 | explicit test_codecvt() : 35 | std::codecvt< wchar_t, char, std::mbstate_t >() 36 | { 37 | } 38 | 39 | protected: 40 | virtual bool do_always_noconv() const throw() { return false; } 41 | virtual int do_encoding() const throw() { return 0; } 42 | 43 | virtual std::codecvt_base::result do_in(std::mbstate_t&, const char* from, const char* from_end, const char*& from_next, wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const 44 | { 45 | for (; from != from_end && to != to_end; ++from, ++to) 46 | *to = wchar_t(*from + 1); 47 | if (to == to_end) 48 | return error; 49 | *to = L'\0'; 50 | from_next = from; 51 | to_next = to; 52 | return ok; 53 | } 54 | 55 | virtual std::codecvt_base::result do_out(std::mbstate_t&, const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next, char* to, char* to_end, char*& to_next) const 56 | { 57 | for (; from != from_end && to != to_end; ++from, ++to) 58 | *to = static_cast< char >(*from - 1); 59 | if (to == to_end) 60 | return error; 61 | *to = '\0'; 62 | from_next = from; 63 | to_next = to; 64 | return ok; 65 | } 66 | 67 | virtual std::codecvt_base::result do_unshift(std::mbstate_t&, char* /*from*/, char* /*to*/, char*& /*next*/) const { return ok; } 68 | virtual int do_length(std::mbstate_t&, const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; } 69 | virtual int do_max_length() const throw() { return 0; } 70 | }; 71 | 72 | #endif // BOOST_FILESYSTEM_TEST_CODECVT_HPP 73 | -------------------------------------------------------------------------------- /test/windows_attributes.cpp: -------------------------------------------------------------------------------- 1 | // windows_attributes ----------------------------------------------------------------// 2 | 3 | // Copyright Beman Dawes 2010 4 | 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // See http://www.boost.org/LICENSE_1_0.txt 7 | 8 | // Library home page: http://www.boost.org/libs/filesystem 9 | 10 | //--------------------------------------------------------------------------------------// 11 | 12 | // Useful for debugging status related issues // 13 | 14 | //--------------------------------------------------------------------------------------// 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using std::make_pair; 25 | namespace fs = boost::filesystem; 26 | 27 | int cpp_main(int argc, char* argv[]) 28 | { 29 | typedef std::map< DWORD, std::string > decode_type; 30 | decode_type table; 31 | 32 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_ARCHIVE, "FILE_ATTRIBUTE_ARCHIVE")); 33 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_COMPRESSED, "FILE_ATTRIBUTE_COMPRESSED")); 34 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_DEVICE, "FILE_ATTRIBUTE_DEVICE")); 35 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_DIRECTORY, "FILE_ATTRIBUTE_DIRECTORY")); 36 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_ENCRYPTED, "FILE_ATTRIBUTE_ENCRYPTED")); 37 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_HIDDEN, "FILE_ATTRIBUTE_HIDDEN")); 38 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, "FILE_ATTRIBUTE_NOT_CONTENT_INDEXED")); 39 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_OFFLINE, "FILE_ATTRIBUTE_OFFLINE")); 40 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_READONLY, "FILE_ATTRIBUTE_READONLY")); 41 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_REPARSE_POINT, "FILE_ATTRIBUTE_REPARSE_POINT")); 42 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_SPARSE_FILE, "FILE_ATTRIBUTE_SPARSE_FILE")); 43 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_SYSTEM, "FILE_ATTRIBUTE_SYSTEM")); 44 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_TEMPORARY, "FILE_ATTRIBUTE_TEMPORARY")); 45 | table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_VIRTUAL, "FILE_ATTRIBUTE_VIRTUAL")); 46 | 47 | if (argc < 2) 48 | { 49 | std::cout << "Usage: windows_attributes path\n"; 50 | return 1; 51 | } 52 | 53 | // report Win32 ::GetFileAttributesA() 54 | 55 | DWORD at(::GetFileAttributesA(argv[1])); 56 | if (at == INVALID_FILE_ATTRIBUTES) 57 | { 58 | std::cout << "GetFileAttributes(\"" << argv[1] 59 | << "\") returned INVALID_FILE_ATTRIBUTES\n"; 60 | return 0; 61 | } 62 | 63 | std::cout << "GetFileAttributes(\"" << argv[1] 64 | << "\") returned "; 65 | 66 | bool bar = false; 67 | for (decode_type::iterator it = table.begin(); it != table.end(); ++it) 68 | { 69 | if (!(it->first & at)) 70 | continue; 71 | if (bar) 72 | std::cout << " | "; 73 | bar = true; 74 | std::cout << it->second; 75 | at &= ~it->first; 76 | } 77 | std::cout << std::endl; 78 | 79 | if (at) 80 | std::cout << "plus unknown attributes " << at << std::endl; 81 | 82 | // report Boost Filesystem file_type 83 | 84 | fs::file_status stat = fs::status(argv[1]); 85 | 86 | const char* types[] = 87 | { 88 | "status_error", 89 | "file_not_found", 90 | "regular_file", 91 | "directory_file", 92 | // the following may not apply to some operating systems or file systems 93 | "symlink_file", 94 | "block_file", 95 | "character_file", 96 | "fifo_file", 97 | "socket_file", 98 | "reparse_file", // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink 99 | "type_unknown" // file does exist", but isn't one of the above types or 100 | // we don't have strong enough permission to find its type 101 | }; 102 | 103 | std::cout << "boost::filesystem::status().type() is " << types[stat.type()] << std::endl; 104 | 105 | return 0; 106 | } 107 | --------------------------------------------------------------------------------