mirror of
https://github.com/likle/cwalk.git
synced 2026-10-28 09:44:01 +00:00
converted line endings to unix
This commit is contained in:
1 parent
2434a7a719
commit
cfe8282fce
35 files changed
+6398
-6398
No files matched your search
+29
-29
@@ -1,29 +1,29 @@
|
||||
version: 0.1.0.{build}
|
||||
image: Visual Studio 2017
|
||||
configuration: Release
|
||||
|
||||
platform:
|
||||
- Win32
|
||||
- x64
|
||||
|
||||
clone_folder: c:\projects\cwalk
|
||||
|
||||
init:
|
||||
- cmd: set arch_str=
|
||||
- cmd: if "%PLATFORM%"=="x64" (set arch_str= Win64)
|
||||
- cmd: echo %PLATFORM%
|
||||
- cmd: echo %APPVEYOR_BUILD_WORKER_IMAGE%
|
||||
- cmd: if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" ( set GENERATOR="Visual Studio 15 2017%arch_str%" )
|
||||
- cmd: if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" ( set GENERATOR="Visual Studio 14 2015%arch_str%" )
|
||||
- cmd: if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2013" ( set GENERATOR="Visual Studio 12 2013%arch_str%" )
|
||||
- cmd: echo %GENERATOR%
|
||||
|
||||
before_build:
|
||||
- cmd: mkdir build.win && cd build.win && cmake --version && cmake .. -DENABLE_TESTS=1 -G %GENERATOR%
|
||||
|
||||
build:
|
||||
project: c:\projects\cwalk\build.win\cwalk.sln
|
||||
verbosity: minimal
|
||||
|
||||
test_script:
|
||||
- cmd: c:\projects\cwalk\build.win\Release\cwalktest.exe
|
||||
version: 0.1.0.{build}
|
||||
image: Visual Studio 2017
|
||||
configuration: Release
|
||||
|
||||
platform:
|
||||
- Win32
|
||||
- x64
|
||||
|
||||
clone_folder: c:\projects\cwalk
|
||||
|
||||
init:
|
||||
- cmd: set arch_str=
|
||||
- cmd: if "%PLATFORM%"=="x64" (set arch_str= Win64)
|
||||
- cmd: echo %PLATFORM%
|
||||
- cmd: echo %APPVEYOR_BUILD_WORKER_IMAGE%
|
||||
- cmd: if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" ( set GENERATOR="Visual Studio 15 2017%arch_str%" )
|
||||
- cmd: if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" ( set GENERATOR="Visual Studio 14 2015%arch_str%" )
|
||||
- cmd: if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2013" ( set GENERATOR="Visual Studio 12 2013%arch_str%" )
|
||||
- cmd: echo %GENERATOR%
|
||||
|
||||
before_build:
|
||||
- cmd: mkdir build.win && cd build.win && cmake --version && cmake .. -DENABLE_TESTS=1 -G %GENERATOR%
|
||||
|
||||
build:
|
||||
project: c:\projects\cwalk\build.win\cwalk.sln
|
||||
verbosity: minimal
|
||||
|
||||
test_script:
|
||||
- cmd: c:\projects\cwalk\build.win\Release\cwalktest.exe
|
||||
+16
-16
@@ -1,17 +1,17 @@
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BreakBeforeBraces: Mozilla
|
||||
IndentWidth: 2
|
||||
ContinuationIndentWidth: 2
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: 'Never'
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: 'None'
|
||||
AllowShortIfStatementsOnASingleLine: 'false'
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
PenaltyBreakAssignment: 10000
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BreakBeforeBraces: Mozilla
|
||||
IndentWidth: 2
|
||||
ContinuationIndentWidth: 2
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: 'Never'
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: 'None'
|
||||
AllowShortIfStatementsOnASingleLine: 'false'
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
PenaltyBreakAssignment: 10000
|
||||
PenaltyBreakBeforeFirstCallParameter: 100000
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
ignore:
|
||||
ignore:
|
||||
- "test"
|
||||
+31
-31
@@ -1,31 +1,31 @@
|
||||
language: c
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
dist: bionic
|
||||
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- gcc-7
|
||||
- cmake
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
before_script:
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake -DENABLE_COVERAGE=1 -DENABLE_TESTS=1 ..
|
||||
|
||||
script:
|
||||
- make
|
||||
- make test
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
language: c
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
dist: bionic
|
||||
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- gcc-7
|
||||
- cmake
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
before_script:
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake -DENABLE_COVERAGE=1 -DENABLE_TESTS=1 ..
|
||||
|
||||
script:
|
||||
- make
|
||||
- make test
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
+285
-285
@@ -1,285 +1,285 @@
|
||||
cmake_minimum_required(VERSION 3.9.2)
|
||||
|
||||
# set project name
|
||||
project(cwalk
|
||||
VERSION 1.2.7
|
||||
DESCRIPTION "A simple path library"
|
||||
HOMEPAGE_URL "https://likle.github.io/cwalk/"
|
||||
LANGUAGES C)
|
||||
|
||||
# include utilities
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
include(EnableWarnings)
|
||||
include(CTest)
|
||||
include(CreateTestList)
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# configure requirements
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
# setup target and directory names
|
||||
set(INCLUDE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
set(SOURCE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
set(TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test")
|
||||
|
||||
# enable coverage if requested
|
||||
if(ENABLE_COVERAGE)
|
||||
message("-- Coverage enabled")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
|
||||
endif()
|
||||
|
||||
# enable sanitizer
|
||||
if(ENABLE_SANITIZER)
|
||||
message("-- Sanitizer enabled")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=${ENABLE_SANITIZER}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=${ENABLE_SANITIZER}")
|
||||
endif()
|
||||
|
||||
# add the main executable
|
||||
add_library(cwalk
|
||||
"${INCLUDE_DIRECTORY}/cwalk.h"
|
||||
"${SOURCE_DIRECTORY}/cwalk.c")
|
||||
enable_warnings(cwalk)
|
||||
target_include_directories(cwalk PUBLIC
|
||||
$<BUILD_INTERFACE:${INCLUDE_DIRECTORY}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
set_target_properties(cwalk PROPERTIES PUBLIC_HEADER "${INCLUDE_DIRECTORY}/cwalk.h")
|
||||
set_target_properties(cwalk PROPERTIES DEFINE_SYMBOL CWK_EXPORTS)
|
||||
|
||||
# add shared library macro
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_compile_definitions(cwalk PUBLIC CWK_SHARED)
|
||||
endif()
|
||||
|
||||
# enable tests
|
||||
if(ENABLE_TESTS)
|
||||
message("-- Tests enabled")
|
||||
enable_testing()
|
||||
|
||||
create_test_list(DEFAULT cwalktest)
|
||||
create_test(DEFAULT absolute simple)
|
||||
create_test(DEFAULT absolute absolute_path)
|
||||
create_test(DEFAULT absolute unix_relative_base)
|
||||
create_test(DEFAULT absolute windows_relative_base)
|
||||
create_test(DEFAULT absolute mixed)
|
||||
create_test(DEFAULT absolute normalization)
|
||||
create_test(DEFAULT absolute too_far)
|
||||
create_test(DEFAULT absolute check)
|
||||
create_test(DEFAULT absolute buffer_reuse)
|
||||
create_test(DEFAULT basename simple)
|
||||
create_test(DEFAULT basename empty)
|
||||
create_test(DEFAULT basename trailing_separator)
|
||||
create_test(DEFAULT basename trailing_separators)
|
||||
create_test(DEFAULT basename no_separators)
|
||||
create_test(DEFAULT basename special_directories)
|
||||
create_test(DEFAULT basename root)
|
||||
create_test(DEFAULT basename windows)
|
||||
create_test(DEFAULT basename change_simple)
|
||||
create_test(DEFAULT basename change_empty_path)
|
||||
create_test(DEFAULT basename change_only_root)
|
||||
create_test(DEFAULT basename change_empty_basename)
|
||||
create_test(DEFAULT basename change_relative)
|
||||
create_test(DEFAULT basename change_trim)
|
||||
create_test(DEFAULT basename change_trim_only_root)
|
||||
create_test(DEFAULT dirname simple)
|
||||
create_test(DEFAULT dirname empty)
|
||||
create_test(DEFAULT dirname trailing_separator)
|
||||
create_test(DEFAULT dirname trailing_separators)
|
||||
create_test(DEFAULT dirname no_separators)
|
||||
create_test(DEFAULT dirname special_directories)
|
||||
create_test(DEFAULT dirname root)
|
||||
create_test(DEFAULT dirname three_segments)
|
||||
create_test(DEFAULT dirname relative)
|
||||
create_test(DEFAULT extension get_simple)
|
||||
create_test(DEFAULT extension get_without)
|
||||
create_test(DEFAULT extension get_first)
|
||||
create_test(DEFAULT extension get_last)
|
||||
create_test(DEFAULT extension get_multiple)
|
||||
create_test(DEFAULT extension check_simple)
|
||||
create_test(DEFAULT extension check_empty)
|
||||
create_test(DEFAULT extension check_without)
|
||||
create_test(DEFAULT extension change_simple)
|
||||
create_test(DEFAULT extension change_no_basename)
|
||||
create_test(DEFAULT extension change_no_extension)
|
||||
create_test(DEFAULT extension change_with_dot)
|
||||
create_test(DEFAULT extension change_overlap)
|
||||
create_test(DEFAULT extension change_overlap_long)
|
||||
create_test(DEFAULT extension change_hidden_file)
|
||||
create_test(DEFAULT extension change_with_trailing_slash)
|
||||
create_test(DEFAULT guess empty_string)
|
||||
create_test(DEFAULT guess windows_root)
|
||||
create_test(DEFAULT guess unix_root)
|
||||
create_test(DEFAULT guess windows_separator)
|
||||
create_test(DEFAULT guess unix_separator)
|
||||
create_test(DEFAULT guess hidden_file)
|
||||
create_test(DEFAULT guess extension)
|
||||
create_test(DEFAULT guess unguessable)
|
||||
create_test(DEFAULT intersection simple)
|
||||
create_test(DEFAULT intersection trailing_separator)
|
||||
create_test(DEFAULT intersection double_separator)
|
||||
create_test(DEFAULT intersection empty)
|
||||
create_test(DEFAULT intersection unequal_roots)
|
||||
create_test(DEFAULT intersection relative_absolute_mix)
|
||||
create_test(DEFAULT intersection same_roots)
|
||||
create_test(DEFAULT intersection one_root_only)
|
||||
create_test(DEFAULT intersection relative_base)
|
||||
create_test(DEFAULT intersection relative_other)
|
||||
create_test(DEFAULT intersection skipped_end)
|
||||
create_test(DEFAULT is_absolute absolute)
|
||||
create_test(DEFAULT is_absolute unc)
|
||||
create_test(DEFAULT is_absolute device_unc)
|
||||
create_test(DEFAULT is_absolute device_dot)
|
||||
create_test(DEFAULT is_absolute device_question_mark)
|
||||
create_test(DEFAULT is_absolute relative)
|
||||
create_test(DEFAULT is_absolute windows_backslash)
|
||||
create_test(DEFAULT is_absolute windows_slash)
|
||||
create_test(DEFAULT is_absolute unix_backslash)
|
||||
create_test(DEFAULT is_absolute unix_drive)
|
||||
create_test(DEFAULT is_absolute absolute_drive)
|
||||
create_test(DEFAULT is_absolute relative_drive)
|
||||
create_test(DEFAULT is_absolute relative_windows)
|
||||
create_test(DEFAULT is_absolute root)
|
||||
create_test(DEFAULT is_absolute dir)
|
||||
create_test(DEFAULT is_relative absolute)
|
||||
create_test(DEFAULT is_relative unc)
|
||||
create_test(DEFAULT is_relative device_unc)
|
||||
create_test(DEFAULT is_relative device_dot)
|
||||
create_test(DEFAULT is_relative device_question_mark)
|
||||
create_test(DEFAULT is_relative relative)
|
||||
create_test(DEFAULT is_relative windows_backslash)
|
||||
create_test(DEFAULT is_relative windows_slash)
|
||||
create_test(DEFAULT is_relative unix_backslash)
|
||||
create_test(DEFAULT is_relative unix_drive)
|
||||
create_test(DEFAULT is_relative absolute_drive)
|
||||
create_test(DEFAULT is_relative relative_drive)
|
||||
create_test(DEFAULT is_relative relative_windows)
|
||||
create_test(DEFAULT join simple)
|
||||
create_test(DEFAULT join navigate_back)
|
||||
create_test(DEFAULT join empty)
|
||||
create_test(DEFAULT join two_absolute)
|
||||
create_test(DEFAULT join two_unc)
|
||||
create_test(DEFAULT join with_two_roots)
|
||||
create_test(DEFAULT join back_after_root)
|
||||
create_test(DEFAULT join relative_back_after_root)
|
||||
create_test(DEFAULT join multiple)
|
||||
create_test(DEFAULT normalize do_nothing)
|
||||
create_test(DEFAULT normalize navigate_back)
|
||||
create_test(DEFAULT normalize relative_too_far)
|
||||
create_test(DEFAULT normalize absolute_too_far)
|
||||
create_test(DEFAULT normalize terminated)
|
||||
create_test(DEFAULT normalize double_separator)
|
||||
create_test(DEFAULT normalize remove_current)
|
||||
create_test(DEFAULT normalize mixed)
|
||||
create_test(DEFAULT normalize overlap)
|
||||
create_test(DEFAULT normalize empty)
|
||||
create_test(DEFAULT normalize only_separators)
|
||||
create_test(DEFAULT normalize back_after_root)
|
||||
create_test(DEFAULT normalize forward_slashes)
|
||||
create_test(DEFAULT relative simple)
|
||||
create_test(DEFAULT relative relative)
|
||||
create_test(DEFAULT relative long_base)
|
||||
create_test(DEFAULT relative long_target)
|
||||
create_test(DEFAULT relative equal)
|
||||
create_test(DEFAULT relative same_base)
|
||||
create_test(DEFAULT relative base_skipped_end)
|
||||
create_test(DEFAULT relative target_skipped_end)
|
||||
create_test(DEFAULT relative base_div_skipped_end)
|
||||
create_test(DEFAULT relative target_div_skipped_end)
|
||||
create_test(DEFAULT relative skip_all)
|
||||
create_test(DEFAULT relative different_roots)
|
||||
create_test(DEFAULT relative relative_and_absolute)
|
||||
create_test(DEFAULT relative check)
|
||||
create_test(DEFAULT relative root_path_unix)
|
||||
create_test(DEFAULT relative root_path_windows)
|
||||
create_test(DEFAULT relative root_forward_slashes)
|
||||
create_test(DEFAULT root absolute)
|
||||
create_test(DEFAULT root unc)
|
||||
create_test(DEFAULT root device_unc)
|
||||
create_test(DEFAULT root device_dot)
|
||||
create_test(DEFAULT root device_question_mark)
|
||||
create_test(DEFAULT root relative)
|
||||
create_test(DEFAULT root windows_backslash)
|
||||
create_test(DEFAULT root windows_slash)
|
||||
create_test(DEFAULT root unix_backslash)
|
||||
create_test(DEFAULT root unix_drive)
|
||||
create_test(DEFAULT root absolute_drive)
|
||||
create_test(DEFAULT root relative_drive)
|
||||
create_test(DEFAULT root relative_windows)
|
||||
create_test(DEFAULT root change_simple)
|
||||
create_test(DEFAULT root change_empty)
|
||||
create_test(DEFAULT root change_separators)
|
||||
create_test(DEFAULT root change_overlapping)
|
||||
create_test(DEFAULT root change_without_root)
|
||||
create_test(DEFAULT segment first)
|
||||
create_test(DEFAULT segment last)
|
||||
create_test(DEFAULT segment next)
|
||||
create_test(DEFAULT segment next_too_far)
|
||||
create_test(DEFAULT segment previous_absolute)
|
||||
create_test(DEFAULT segment previous_relative)
|
||||
create_test(DEFAULT segment previous_absolute_one_char_first)
|
||||
create_test(DEFAULT segment previous_relative_one_char_first)
|
||||
create_test(DEFAULT segment previous_too_far)
|
||||
create_test(DEFAULT segment previous_too_far_root)
|
||||
create_test(DEFAULT segment type)
|
||||
create_test(DEFAULT segment back_with_root)
|
||||
create_test(DEFAULT segment change_simple)
|
||||
create_test(DEFAULT segment change_first)
|
||||
create_test(DEFAULT segment change_last)
|
||||
create_test(DEFAULT segment change_trim)
|
||||
create_test(DEFAULT segment change_empty)
|
||||
create_test(DEFAULT segment change_with_separator)
|
||||
create_test(DEFAULT segment change_overlap)
|
||||
create_test(DEFAULT windows change_style)
|
||||
create_test(DEFAULT windows get_root)
|
||||
create_test(DEFAULT windows get_unc_root)
|
||||
create_test(DEFAULT windows get_root_separator)
|
||||
create_test(DEFAULT windows get_root_relative)
|
||||
create_test(DEFAULT windows intersection_case)
|
||||
create_test(DEFAULT windows root_backslash)
|
||||
create_test(DEFAULT windows root_empty)
|
||||
write_test_file(DEFAULT "${TEST_DIRECTORY}/tests.h")
|
||||
|
||||
add_executable(cwalktest
|
||||
"${TEST_DIRECTORY}/main.c"
|
||||
"${TEST_DIRECTORY}/absolute_test.c"
|
||||
"${TEST_DIRECTORY}/basename_test.c"
|
||||
"${TEST_DIRECTORY}/dirname_test.c"
|
||||
"${TEST_DIRECTORY}/extension_test.c"
|
||||
"${TEST_DIRECTORY}/guess_test.c"
|
||||
"${TEST_DIRECTORY}/intersection_test.c"
|
||||
"${TEST_DIRECTORY}/is_absolute_test.c"
|
||||
"${TEST_DIRECTORY}/is_relative_test.c"
|
||||
"${TEST_DIRECTORY}/join_test.c"
|
||||
"${TEST_DIRECTORY}/normalize_test.c"
|
||||
"${TEST_DIRECTORY}/relative_test.c"
|
||||
"${TEST_DIRECTORY}/root_test.c"
|
||||
"${TEST_DIRECTORY}/segment_test.c"
|
||||
"${TEST_DIRECTORY}/windows_test.c")
|
||||
enable_warnings(cwalktest)
|
||||
|
||||
target_link_libraries(cwalktest PRIVATE cwalk)
|
||||
endif()
|
||||
|
||||
write_basic_package_version_file("CwalkConfigVersion.cmake"
|
||||
VERSION ${cwalk_VERSION}
|
||||
COMPATIBILITY SameMajorVersion)
|
||||
|
||||
configure_file(cwalk.pc.in ${PROJECT_BINARY_DIR}/cwalk.pc @ONLY)
|
||||
|
||||
install(TARGETS cwalk
|
||||
EXPORT CwalkTargets)
|
||||
|
||||
install(FILES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CwalkConfig.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cwalk)
|
||||
|
||||
install(FILES
|
||||
${PROJECT_BINARY_DIR}/cwalk.pc
|
||||
DESTINATION lib/pkgconfig/)
|
||||
|
||||
install(EXPORT CwalkTargets
|
||||
FILE CwalkTargets.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cwalk)
|
||||
cmake_minimum_required(VERSION 3.9.2)
|
||||
|
||||
# set project name
|
||||
project(cwalk
|
||||
VERSION 1.2.7
|
||||
DESCRIPTION "A simple path library"
|
||||
HOMEPAGE_URL "https://likle.github.io/cwalk/"
|
||||
LANGUAGES C)
|
||||
|
||||
# include utilities
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
include(EnableWarnings)
|
||||
include(CTest)
|
||||
include(CreateTestList)
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# configure requirements
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
# setup target and directory names
|
||||
set(INCLUDE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
set(SOURCE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
set(TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test")
|
||||
|
||||
# enable coverage if requested
|
||||
if(ENABLE_COVERAGE)
|
||||
message("-- Coverage enabled")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
|
||||
endif()
|
||||
|
||||
# enable sanitizer
|
||||
if(ENABLE_SANITIZER)
|
||||
message("-- Sanitizer enabled")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=${ENABLE_SANITIZER}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=${ENABLE_SANITIZER}")
|
||||
endif()
|
||||
|
||||
# add the main executable
|
||||
add_library(cwalk
|
||||
"${INCLUDE_DIRECTORY}/cwalk.h"
|
||||
"${SOURCE_DIRECTORY}/cwalk.c")
|
||||
enable_warnings(cwalk)
|
||||
target_include_directories(cwalk PUBLIC
|
||||
$<BUILD_INTERFACE:${INCLUDE_DIRECTORY}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
set_target_properties(cwalk PROPERTIES PUBLIC_HEADER "${INCLUDE_DIRECTORY}/cwalk.h")
|
||||
set_target_properties(cwalk PROPERTIES DEFINE_SYMBOL CWK_EXPORTS)
|
||||
|
||||
# add shared library macro
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_compile_definitions(cwalk PUBLIC CWK_SHARED)
|
||||
endif()
|
||||
|
||||
# enable tests
|
||||
if(ENABLE_TESTS)
|
||||
message("-- Tests enabled")
|
||||
enable_testing()
|
||||
|
||||
create_test_list(DEFAULT cwalktest)
|
||||
create_test(DEFAULT absolute simple)
|
||||
create_test(DEFAULT absolute absolute_path)
|
||||
create_test(DEFAULT absolute unix_relative_base)
|
||||
create_test(DEFAULT absolute windows_relative_base)
|
||||
create_test(DEFAULT absolute mixed)
|
||||
create_test(DEFAULT absolute normalization)
|
||||
create_test(DEFAULT absolute too_far)
|
||||
create_test(DEFAULT absolute check)
|
||||
create_test(DEFAULT absolute buffer_reuse)
|
||||
create_test(DEFAULT basename simple)
|
||||
create_test(DEFAULT basename empty)
|
||||
create_test(DEFAULT basename trailing_separator)
|
||||
create_test(DEFAULT basename trailing_separators)
|
||||
create_test(DEFAULT basename no_separators)
|
||||
create_test(DEFAULT basename special_directories)
|
||||
create_test(DEFAULT basename root)
|
||||
create_test(DEFAULT basename windows)
|
||||
create_test(DEFAULT basename change_simple)
|
||||
create_test(DEFAULT basename change_empty_path)
|
||||
create_test(DEFAULT basename change_only_root)
|
||||
create_test(DEFAULT basename change_empty_basename)
|
||||
create_test(DEFAULT basename change_relative)
|
||||
create_test(DEFAULT basename change_trim)
|
||||
create_test(DEFAULT basename change_trim_only_root)
|
||||
create_test(DEFAULT dirname simple)
|
||||
create_test(DEFAULT dirname empty)
|
||||
create_test(DEFAULT dirname trailing_separator)
|
||||
create_test(DEFAULT dirname trailing_separators)
|
||||
create_test(DEFAULT dirname no_separators)
|
||||
create_test(DEFAULT dirname special_directories)
|
||||
create_test(DEFAULT dirname root)
|
||||
create_test(DEFAULT dirname three_segments)
|
||||
create_test(DEFAULT dirname relative)
|
||||
create_test(DEFAULT extension get_simple)
|
||||
create_test(DEFAULT extension get_without)
|
||||
create_test(DEFAULT extension get_first)
|
||||
create_test(DEFAULT extension get_last)
|
||||
create_test(DEFAULT extension get_multiple)
|
||||
create_test(DEFAULT extension check_simple)
|
||||
create_test(DEFAULT extension check_empty)
|
||||
create_test(DEFAULT extension check_without)
|
||||
create_test(DEFAULT extension change_simple)
|
||||
create_test(DEFAULT extension change_no_basename)
|
||||
create_test(DEFAULT extension change_no_extension)
|
||||
create_test(DEFAULT extension change_with_dot)
|
||||
create_test(DEFAULT extension change_overlap)
|
||||
create_test(DEFAULT extension change_overlap_long)
|
||||
create_test(DEFAULT extension change_hidden_file)
|
||||
create_test(DEFAULT extension change_with_trailing_slash)
|
||||
create_test(DEFAULT guess empty_string)
|
||||
create_test(DEFAULT guess windows_root)
|
||||
create_test(DEFAULT guess unix_root)
|
||||
create_test(DEFAULT guess windows_separator)
|
||||
create_test(DEFAULT guess unix_separator)
|
||||
create_test(DEFAULT guess hidden_file)
|
||||
create_test(DEFAULT guess extension)
|
||||
create_test(DEFAULT guess unguessable)
|
||||
create_test(DEFAULT intersection simple)
|
||||
create_test(DEFAULT intersection trailing_separator)
|
||||
create_test(DEFAULT intersection double_separator)
|
||||
create_test(DEFAULT intersection empty)
|
||||
create_test(DEFAULT intersection unequal_roots)
|
||||
create_test(DEFAULT intersection relative_absolute_mix)
|
||||
create_test(DEFAULT intersection same_roots)
|
||||
create_test(DEFAULT intersection one_root_only)
|
||||
create_test(DEFAULT intersection relative_base)
|
||||
create_test(DEFAULT intersection relative_other)
|
||||
create_test(DEFAULT intersection skipped_end)
|
||||
create_test(DEFAULT is_absolute absolute)
|
||||
create_test(DEFAULT is_absolute unc)
|
||||
create_test(DEFAULT is_absolute device_unc)
|
||||
create_test(DEFAULT is_absolute device_dot)
|
||||
create_test(DEFAULT is_absolute device_question_mark)
|
||||
create_test(DEFAULT is_absolute relative)
|
||||
create_test(DEFAULT is_absolute windows_backslash)
|
||||
create_test(DEFAULT is_absolute windows_slash)
|
||||
create_test(DEFAULT is_absolute unix_backslash)
|
||||
create_test(DEFAULT is_absolute unix_drive)
|
||||
create_test(DEFAULT is_absolute absolute_drive)
|
||||
create_test(DEFAULT is_absolute relative_drive)
|
||||
create_test(DEFAULT is_absolute relative_windows)
|
||||
create_test(DEFAULT is_absolute root)
|
||||
create_test(DEFAULT is_absolute dir)
|
||||
create_test(DEFAULT is_relative absolute)
|
||||
create_test(DEFAULT is_relative unc)
|
||||
create_test(DEFAULT is_relative device_unc)
|
||||
create_test(DEFAULT is_relative device_dot)
|
||||
create_test(DEFAULT is_relative device_question_mark)
|
||||
create_test(DEFAULT is_relative relative)
|
||||
create_test(DEFAULT is_relative windows_backslash)
|
||||
create_test(DEFAULT is_relative windows_slash)
|
||||
create_test(DEFAULT is_relative unix_backslash)
|
||||
create_test(DEFAULT is_relative unix_drive)
|
||||
create_test(DEFAULT is_relative absolute_drive)
|
||||
create_test(DEFAULT is_relative relative_drive)
|
||||
create_test(DEFAULT is_relative relative_windows)
|
||||
create_test(DEFAULT join simple)
|
||||
create_test(DEFAULT join navigate_back)
|
||||
create_test(DEFAULT join empty)
|
||||
create_test(DEFAULT join two_absolute)
|
||||
create_test(DEFAULT join two_unc)
|
||||
create_test(DEFAULT join with_two_roots)
|
||||
create_test(DEFAULT join back_after_root)
|
||||
create_test(DEFAULT join relative_back_after_root)
|
||||
create_test(DEFAULT join multiple)
|
||||
create_test(DEFAULT normalize do_nothing)
|
||||
create_test(DEFAULT normalize navigate_back)
|
||||
create_test(DEFAULT normalize relative_too_far)
|
||||
create_test(DEFAULT normalize absolute_too_far)
|
||||
create_test(DEFAULT normalize terminated)
|
||||
create_test(DEFAULT normalize double_separator)
|
||||
create_test(DEFAULT normalize remove_current)
|
||||
create_test(DEFAULT normalize mixed)
|
||||
create_test(DEFAULT normalize overlap)
|
||||
create_test(DEFAULT normalize empty)
|
||||
create_test(DEFAULT normalize only_separators)
|
||||
create_test(DEFAULT normalize back_after_root)
|
||||
create_test(DEFAULT normalize forward_slashes)
|
||||
create_test(DEFAULT relative simple)
|
||||
create_test(DEFAULT relative relative)
|
||||
create_test(DEFAULT relative long_base)
|
||||
create_test(DEFAULT relative long_target)
|
||||
create_test(DEFAULT relative equal)
|
||||
create_test(DEFAULT relative same_base)
|
||||
create_test(DEFAULT relative base_skipped_end)
|
||||
create_test(DEFAULT relative target_skipped_end)
|
||||
create_test(DEFAULT relative base_div_skipped_end)
|
||||
create_test(DEFAULT relative target_div_skipped_end)
|
||||
create_test(DEFAULT relative skip_all)
|
||||
create_test(DEFAULT relative different_roots)
|
||||
create_test(DEFAULT relative relative_and_absolute)
|
||||
create_test(DEFAULT relative check)
|
||||
create_test(DEFAULT relative root_path_unix)
|
||||
create_test(DEFAULT relative root_path_windows)
|
||||
create_test(DEFAULT relative root_forward_slashes)
|
||||
create_test(DEFAULT root absolute)
|
||||
create_test(DEFAULT root unc)
|
||||
create_test(DEFAULT root device_unc)
|
||||
create_test(DEFAULT root device_dot)
|
||||
create_test(DEFAULT root device_question_mark)
|
||||
create_test(DEFAULT root relative)
|
||||
create_test(DEFAULT root windows_backslash)
|
||||
create_test(DEFAULT root windows_slash)
|
||||
create_test(DEFAULT root unix_backslash)
|
||||
create_test(DEFAULT root unix_drive)
|
||||
create_test(DEFAULT root absolute_drive)
|
||||
create_test(DEFAULT root relative_drive)
|
||||
create_test(DEFAULT root relative_windows)
|
||||
create_test(DEFAULT root change_simple)
|
||||
create_test(DEFAULT root change_empty)
|
||||
create_test(DEFAULT root change_separators)
|
||||
create_test(DEFAULT root change_overlapping)
|
||||
create_test(DEFAULT root change_without_root)
|
||||
create_test(DEFAULT segment first)
|
||||
create_test(DEFAULT segment last)
|
||||
create_test(DEFAULT segment next)
|
||||
create_test(DEFAULT segment next_too_far)
|
||||
create_test(DEFAULT segment previous_absolute)
|
||||
create_test(DEFAULT segment previous_relative)
|
||||
create_test(DEFAULT segment previous_absolute_one_char_first)
|
||||
create_test(DEFAULT segment previous_relative_one_char_first)
|
||||
create_test(DEFAULT segment previous_too_far)
|
||||
create_test(DEFAULT segment previous_too_far_root)
|
||||
create_test(DEFAULT segment type)
|
||||
create_test(DEFAULT segment back_with_root)
|
||||
create_test(DEFAULT segment change_simple)
|
||||
create_test(DEFAULT segment change_first)
|
||||
create_test(DEFAULT segment change_last)
|
||||
create_test(DEFAULT segment change_trim)
|
||||
create_test(DEFAULT segment change_empty)
|
||||
create_test(DEFAULT segment change_with_separator)
|
||||
create_test(DEFAULT segment change_overlap)
|
||||
create_test(DEFAULT windows change_style)
|
||||
create_test(DEFAULT windows get_root)
|
||||
create_test(DEFAULT windows get_unc_root)
|
||||
create_test(DEFAULT windows get_root_separator)
|
||||
create_test(DEFAULT windows get_root_relative)
|
||||
create_test(DEFAULT windows intersection_case)
|
||||
create_test(DEFAULT windows root_backslash)
|
||||
create_test(DEFAULT windows root_empty)
|
||||
write_test_file(DEFAULT "${TEST_DIRECTORY}/tests.h")
|
||||
|
||||
add_executable(cwalktest
|
||||
"${TEST_DIRECTORY}/main.c"
|
||||
"${TEST_DIRECTORY}/absolute_test.c"
|
||||
"${TEST_DIRECTORY}/basename_test.c"
|
||||
"${TEST_DIRECTORY}/dirname_test.c"
|
||||
"${TEST_DIRECTORY}/extension_test.c"
|
||||
"${TEST_DIRECTORY}/guess_test.c"
|
||||
"${TEST_DIRECTORY}/intersection_test.c"
|
||||
"${TEST_DIRECTORY}/is_absolute_test.c"
|
||||
"${TEST_DIRECTORY}/is_relative_test.c"
|
||||
"${TEST_DIRECTORY}/join_test.c"
|
||||
"${TEST_DIRECTORY}/normalize_test.c"
|
||||
"${TEST_DIRECTORY}/relative_test.c"
|
||||
"${TEST_DIRECTORY}/root_test.c"
|
||||
"${TEST_DIRECTORY}/segment_test.c"
|
||||
"${TEST_DIRECTORY}/windows_test.c")
|
||||
enable_warnings(cwalktest)
|
||||
|
||||
target_link_libraries(cwalktest PRIVATE cwalk)
|
||||
endif()
|
||||
|
||||
write_basic_package_version_file("CwalkConfigVersion.cmake"
|
||||
VERSION ${cwalk_VERSION}
|
||||
COMPATIBILITY SameMajorVersion)
|
||||
|
||||
configure_file(cwalk.pc.in ${PROJECT_BINARY_DIR}/cwalk.pc @ONLY)
|
||||
|
||||
install(TARGETS cwalk
|
||||
EXPORT CwalkTargets)
|
||||
|
||||
install(FILES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CwalkConfig.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cwalk)
|
||||
|
||||
install(FILES
|
||||
${PROJECT_BINARY_DIR}/cwalk.pc
|
||||
DESTINATION lib/pkgconfig/)
|
||||
|
||||
install(EXPORT CwalkTargets
|
||||
FILE CwalkTargets.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cwalk)
|
||||
+29
-29
@@ -1,30 +1,30 @@
|
||||
# Contributing
|
||||
All your contributions to **cwalk** are very welcome! **cwalk** is especially happy to
|
||||
receive contributions like:
|
||||
|
||||
* general **bugfixes**
|
||||
* simple **bug reports**
|
||||
* **proposing new features**
|
||||
* **questions** (there are no dumb questions)
|
||||
|
||||
## License
|
||||
**Any contributions you make will be under the MIT Software License.**
|
||||
|
||||
In short, when you submit code changes, your submissions are understood to be
|
||||
under the same MIT License that covers the project. Feel free to contact the
|
||||
maintainers if that's a concern.
|
||||
|
||||
## How to report a bug?
|
||||
You can just use the issue tracker to do so.
|
||||
|
||||
## How to propose a new feature?
|
||||
You can just use the issue tracker to do so.
|
||||
|
||||
## How to submit a bug fix?
|
||||
Just submit a pull-request! Try to make sure that the code style fits the
|
||||
surrounding code.
|
||||
|
||||
## How to submit a new feature?
|
||||
You probably want to create an issue first to discuss the change. All
|
||||
pull-requests will be considered though! Just try to make sure that the code
|
||||
# Contributing
|
||||
All your contributions to **cwalk** are very welcome! **cwalk** is especially happy to
|
||||
receive contributions like:
|
||||
|
||||
* general **bugfixes**
|
||||
* simple **bug reports**
|
||||
* **proposing new features**
|
||||
* **questions** (there are no dumb questions)
|
||||
|
||||
## License
|
||||
**Any contributions you make will be under the MIT Software License.**
|
||||
|
||||
In short, when you submit code changes, your submissions are understood to be
|
||||
under the same MIT License that covers the project. Feel free to contact the
|
||||
maintainers if that's a concern.
|
||||
|
||||
## How to report a bug?
|
||||
You can just use the issue tracker to do so.
|
||||
|
||||
## How to propose a new feature?
|
||||
You can just use the issue tracker to do so.
|
||||
|
||||
## How to submit a bug fix?
|
||||
Just submit a pull-request! Try to make sure that the code style fits the
|
||||
surrounding code.
|
||||
|
||||
## How to submit a new feature?
|
||||
You probably want to create an issue first to discuss the change. All
|
||||
pull-requests will be considered though! Just try to make sure that the code
|
||||
style fits the surrounding code.
|
||||
+20
-20
@@ -1,21 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Leonard Iklé
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Leonard Iklé
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,34 +1,34 @@
|
||||
<img style="width:100%;" src="/banner.png">
|
||||
|
||||
[](https://travis-ci.com/likle/cwalk)
|
||||
[](https://ci.appveyor.com/project/likle/cwalk)
|
||||
[](https://codecov.io/gh/likle/cwalk)
|
||||
|
||||
# libcwalk - path library for C/C++
|
||||
This is a lighweight C path manipulation library. It is currently compiled and
|
||||
tested under **Windows**, **MacOS** and **Linux**. It supports UNIX and Windows
|
||||
path styles on all platforms.
|
||||
|
||||
## Features
|
||||
Please have a look at the
|
||||
**[reference](https://likle.github.io/cwalk/reference/)** for detailed
|
||||
information. Some features this library includes:
|
||||
|
||||
* **cross-platform** on windows, linux and macOS
|
||||
* **simple interface** - just one header
|
||||
* **combine paths** together
|
||||
* **basename, dirname and extension** parsing
|
||||
* **normalize and cleanup** paths
|
||||
* **resolve and generate relative** paths
|
||||
* **iterate segments** of the path
|
||||
* **and more** things...
|
||||
|
||||
## Building
|
||||
**[Building](https://likle.github.io/cwalk/build.html)**,
|
||||
**[embedding](https://likle.github.io/cwalk/embed.html)** and
|
||||
**[testing](https://likle.github.io/cwalk/build.html)** instructions are
|
||||
available in the documentation (it's very easy).
|
||||
|
||||
## Docs
|
||||
All the documentation is available in the
|
||||
**[the github page](https://likle.github.io/cwalk/)** of this repository.
|
||||
<img style="width:100%;" src="/banner.png">
|
||||
|
||||
[](https://travis-ci.com/likle/cwalk)
|
||||
[](https://ci.appveyor.com/project/likle/cwalk)
|
||||
[](https://codecov.io/gh/likle/cwalk)
|
||||
|
||||
# libcwalk - path library for C/C++
|
||||
This is a lighweight C path manipulation library. It is currently compiled and
|
||||
tested under **Windows**, **MacOS** and **Linux**. It supports UNIX and Windows
|
||||
path styles on all platforms.
|
||||
|
||||
## Features
|
||||
Please have a look at the
|
||||
**[reference](https://likle.github.io/cwalk/reference/)** for detailed
|
||||
information. Some features this library includes:
|
||||
|
||||
* **cross-platform** on windows, linux and macOS
|
||||
* **simple interface** - just one header
|
||||
* **combine paths** together
|
||||
* **basename, dirname and extension** parsing
|
||||
* **normalize and cleanup** paths
|
||||
* **resolve and generate relative** paths
|
||||
* **iterate segments** of the path
|
||||
* **and more** things...
|
||||
|
||||
## Building
|
||||
**[Building](https://likle.github.io/cwalk/build.html)**,
|
||||
**[embedding](https://likle.github.io/cwalk/embed.html)** and
|
||||
**[testing](https://likle.github.io/cwalk/build.html)** instructions are
|
||||
available in the documentation (it's very easy).
|
||||
|
||||
## Docs
|
||||
All the documentation is available in the
|
||||
**[the github page](https://likle.github.io/cwalk/)** of this repository.
|
||||
+15
-15
@@ -1,15 +1,15 @@
|
||||
function(create_test_list list_name target)
|
||||
set("TEST_LIST_TARGET_${list_name}" ${target} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(write_test_file list_name file)
|
||||
set("TEST_LIST_FILE_${list_name}" ${file} PARENT_SCOPE)
|
||||
file(WRITE ${file} "#define UNIT_TESTS(XX) \\\n")
|
||||
file(APPEND ${file} ${TEST_LIST_CONTENT_${list_name}})
|
||||
file(APPEND ${file} "\n")
|
||||
endfunction()
|
||||
|
||||
function(create_test list_name unit_name test_name)
|
||||
set(TEST_LIST_CONTENT_${list_name} "${TEST_LIST_CONTENT_${list_name}} XX(${unit_name},${test_name}) \\\n" PARENT_SCOPE)
|
||||
add_test(NAME "${unit_name}_${test_name}" COMMAND ${TEST_LIST_TARGET_${list_name}} ${unit_name} ${test_name})
|
||||
endfunction()
|
||||
function(create_test_list list_name target)
|
||||
set("TEST_LIST_TARGET_${list_name}" ${target} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(write_test_file list_name file)
|
||||
set("TEST_LIST_FILE_${list_name}" ${file} PARENT_SCOPE)
|
||||
file(WRITE ${file} "#define UNIT_TESTS(XX) \\\n")
|
||||
file(APPEND ${file} ${TEST_LIST_CONTENT_${list_name}})
|
||||
file(APPEND ${file} "\n")
|
||||
endfunction()
|
||||
|
||||
function(create_test list_name unit_name test_name)
|
||||
set(TEST_LIST_CONTENT_${list_name} "${TEST_LIST_CONTENT_${list_name}} XX(${unit_name},${test_name}) \\\n" PARENT_SCOPE)
|
||||
add_test(NAME "${unit_name}_${test_name}" COMMAND ${TEST_LIST_TARGET_${list_name}} ${unit_name} ${test_name})
|
||||
endfunction()
|
||||
@@ -1 +1 @@
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/CwalkTargets.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/CwalkTargets.cmake")
|
||||
+25
-25
@@ -1,25 +1,25 @@
|
||||
# enable warnings
|
||||
function(enable_warnings target)
|
||||
if(MSVC)
|
||||
target_compile_definitions(${target} PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
target_compile_options(${target} PRIVATE /W4)
|
||||
if (NOT IGNORE_WARNINGS)
|
||||
target_compile_options(${target} PRIVATE /WX)
|
||||
endif()
|
||||
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
|
||||
target_compile_options(${target} PRIVATE -Wall)
|
||||
target_compile_options(${target} PRIVATE -Wextra)
|
||||
target_compile_options(${target} PRIVATE -Wpedantic)
|
||||
target_compile_options(${target} PRIVATE -Wno-gnu-zero-variadic-macro-arguments)
|
||||
if (NOT IGNORE_WARNINGS)
|
||||
target_compile_options(${target} PRIVATE -Werror)
|
||||
endif()
|
||||
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
||||
target_compile_options(${target} PRIVATE -Wall)
|
||||
target_compile_options(${target} PRIVATE -Wextra)
|
||||
target_compile_options(${target} PRIVATE -Wpedantic)
|
||||
if (NOT IGNORE_WARNINGS)
|
||||
target_compile_options(${target} PRIVATE -Werror)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
# enable warnings
|
||||
function(enable_warnings target)
|
||||
if(MSVC)
|
||||
target_compile_definitions(${target} PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
target_compile_options(${target} PRIVATE /W4)
|
||||
if (NOT IGNORE_WARNINGS)
|
||||
target_compile_options(${target} PRIVATE /WX)
|
||||
endif()
|
||||
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
|
||||
target_compile_options(${target} PRIVATE -Wall)
|
||||
target_compile_options(${target} PRIVATE -Wextra)
|
||||
target_compile_options(${target} PRIVATE -Wpedantic)
|
||||
target_compile_options(${target} PRIVATE -Wno-gnu-zero-variadic-macro-arguments)
|
||||
if (NOT IGNORE_WARNINGS)
|
||||
target_compile_options(${target} PRIVATE -Werror)
|
||||
endif()
|
||||
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
||||
target_compile_options(${target} PRIVATE -Wall)
|
||||
target_compile_options(${target} PRIVATE -Wextra)
|
||||
target_compile_options(${target} PRIVATE -Wpedantic)
|
||||
if (NOT IGNORE_WARNINGS)
|
||||
target_compile_options(${target} PRIVATE -Werror)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
defaults:
|
||||
-
|
||||
scope:
|
||||
path: "" # an empty string here means all files in the project
|
||||
values:
|
||||
defaults:
|
||||
-
|
||||
scope:
|
||||
path: "" # an empty string here means all files in the project
|
||||
values:
|
||||
layout: "default"
|
||||
+42
-42
@@ -1,42 +1,42 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{{ page.title }} - cwalk</title>
|
||||
<meta name="description" content="{{ page.description }}" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://fonts.googleapis.com/css?family=Ubuntu+Mono" rel="stylesheet">
|
||||
<link href="{{ site.baseurl }}/assets/css/default.css?v4" rel="stylesheet" type="text/css">
|
||||
<link href="{{ site.baseurl }}/assets/css/monakai.css" rel="stylesheet" type="text/css">
|
||||
<link rel="shortcut icon" href="{{ site.baseurl }}/assets/img/favicon.png">
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-127837944-1"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', 'UA-127837944-1');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="inner">
|
||||
<a href="{{ site.baseurl }}{% link index.md %}" class="logo">cwalk</a>
|
||||
<nav>
|
||||
<a href="{{ site.baseurl }}{% link build.md %}">build</a>
|
||||
<a href="{{ site.baseurl }}{% link embed.md %}">embed</a>
|
||||
<a href="{{ site.baseurl }}{% link reference/index.md %}">reference</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
<div class="main">
|
||||
<div class="content">
|
||||
<h1>{{ page.title }}</h1>
|
||||
{{ content }}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<footer>
|
||||
find this repository on <a href="https://github.com/likle/cwalk/tree/master">github</a>
|
||||
</footer>
|
||||
</html>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{{ page.title }} - cwalk</title>
|
||||
<meta name="description" content="{{ page.description }}" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://fonts.googleapis.com/css?family=Ubuntu+Mono" rel="stylesheet">
|
||||
<link href="{{ site.baseurl }}/assets/css/default.css?v4" rel="stylesheet" type="text/css">
|
||||
<link href="{{ site.baseurl }}/assets/css/monakai.css" rel="stylesheet" type="text/css">
|
||||
<link rel="shortcut icon" href="{{ site.baseurl }}/assets/img/favicon.png">
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-127837944-1"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', 'UA-127837944-1');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="inner">
|
||||
<a href="{{ site.baseurl }}{% link index.md %}" class="logo">cwalk</a>
|
||||
<nav>
|
||||
<a href="{{ site.baseurl }}{% link build.md %}">build</a>
|
||||
<a href="{{ site.baseurl }}{% link embed.md %}">embed</a>
|
||||
<a href="{{ site.baseurl }}{% link reference/index.md %}">reference</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
<div class="main">
|
||||
<div class="content">
|
||||
<h1>{{ page.title }}</h1>
|
||||
{{ content }}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<footer>
|
||||
find this repository on <a href="https://github.com/likle/cwalk/tree/master">github</a>
|
||||
</footer>
|
||||
</html>
|
||||
+126
-126
@@ -1,126 +1,126 @@
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
||||
margin: auto;
|
||||
padding: 20px;
|
||||
background: #FAFAFA;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
}
|
||||
|
||||
header {
|
||||
text-align: right;
|
||||
margin-bottom: 20px;
|
||||
padding: 20px 20px;
|
||||
font-family: 'Ubuntu Mono';
|
||||
background: #55FF99;
|
||||
color: #D5FFE6;
|
||||
border-bottom: 10px solid #37C871;
|
||||
}
|
||||
|
||||
header .inner {
|
||||
max-width: 800px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
header .logo {
|
||||
float: left;
|
||||
vertical-align: middle;
|
||||
display: inline-block;
|
||||
font-weight: bold;
|
||||
font-size: 32pt;
|
||||
padding: 0;
|
||||
margin-left: 10px;
|
||||
line-height: 50px;
|
||||
}
|
||||
|
||||
header nav {
|
||||
line-height: 50px;
|
||||
}
|
||||
|
||||
header a {
|
||||
padding: 10px;
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
font-size: 18pt;
|
||||
overflow: auto;
|
||||
color: #078e3d;;
|
||||
}
|
||||
|
||||
.main {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
footer {
|
||||
text-align: center;
|
||||
margin-top: 50px;
|
||||
padding: 40px 20px;
|
||||
font-family: 'Ubuntu Mono';
|
||||
background: #49483e;
|
||||
color: #e6db74;
|
||||
}
|
||||
|
||||
|
||||
a {
|
||||
color: #37C871;
|
||||
}
|
||||
|
||||
h1, h2 {
|
||||
font-family: 'Ubuntu Mono';
|
||||
padding-bottom: 5px;
|
||||
border-bottom: 1px solid rgba(255,255,255,.2);
|
||||
}
|
||||
|
||||
.content {
|
||||
color: #49483e;
|
||||
padding-top: 20px;
|
||||
max-width: 800px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.highlight {
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
overflow: auto;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.highlighter-rouge {
|
||||
background: rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
table td,
|
||||
table th {
|
||||
border: 1px solid #DDDDDD;
|
||||
background: #ffffff;
|
||||
padding: 5px 8px;
|
||||
}
|
||||
|
||||
table tr:nth-child(even) td {
|
||||
background: #f8f9fb;
|
||||
}
|
||||
|
||||
@media (max-width: 1000px) {
|
||||
header {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
header .logo {
|
||||
display: block;
|
||||
float: none;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 0 20px;
|
||||
}
|
||||
}
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
||||
margin: auto;
|
||||
padding: 20px;
|
||||
background: #FAFAFA;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
}
|
||||
|
||||
header {
|
||||
text-align: right;
|
||||
margin-bottom: 20px;
|
||||
padding: 20px 20px;
|
||||
font-family: 'Ubuntu Mono';
|
||||
background: #55FF99;
|
||||
color: #D5FFE6;
|
||||
border-bottom: 10px solid #37C871;
|
||||
}
|
||||
|
||||
header .inner {
|
||||
max-width: 800px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
header .logo {
|
||||
float: left;
|
||||
vertical-align: middle;
|
||||
display: inline-block;
|
||||
font-weight: bold;
|
||||
font-size: 32pt;
|
||||
padding: 0;
|
||||
margin-left: 10px;
|
||||
line-height: 50px;
|
||||
}
|
||||
|
||||
header nav {
|
||||
line-height: 50px;
|
||||
}
|
||||
|
||||
header a {
|
||||
padding: 10px;
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
font-size: 18pt;
|
||||
overflow: auto;
|
||||
color: #078e3d;;
|
||||
}
|
||||
|
||||
.main {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
footer {
|
||||
text-align: center;
|
||||
margin-top: 50px;
|
||||
padding: 40px 20px;
|
||||
font-family: 'Ubuntu Mono';
|
||||
background: #49483e;
|
||||
color: #e6db74;
|
||||
}
|
||||
|
||||
|
||||
a {
|
||||
color: #37C871;
|
||||
}
|
||||
|
||||
h1, h2 {
|
||||
font-family: 'Ubuntu Mono';
|
||||
padding-bottom: 5px;
|
||||
border-bottom: 1px solid rgba(255,255,255,.2);
|
||||
}
|
||||
|
||||
.content {
|
||||
color: #49483e;
|
||||
padding-top: 20px;
|
||||
max-width: 800px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.highlight {
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
overflow: auto;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.highlighter-rouge {
|
||||
background: rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
table td,
|
||||
table th {
|
||||
border: 1px solid #DDDDDD;
|
||||
background: #ffffff;
|
||||
padding: 5px 8px;
|
||||
}
|
||||
|
||||
table tr:nth-child(even) td {
|
||||
background: #f8f9fb;
|
||||
}
|
||||
|
||||
@media (max-width: 1000px) {
|
||||
header {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
header .logo {
|
||||
display: block;
|
||||
float: none;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 0 20px;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +1,69 @@
|
||||
---
|
||||
title: cwk_path_change_basename
|
||||
description: Changes the basename of a file path.
|
||||
---
|
||||
|
||||
_(since v1.2.0)_
|
||||
Changes the basename of a file path.
|
||||
|
||||
## Description
|
||||
```c
|
||||
size_t cwk_path_change_basename(const char *path, const char *new_basename,
|
||||
char *buffer, size_t buffer_size);
|
||||
```
|
||||
|
||||
This function changes the basename of a file path. This function will not
|
||||
write out more than the specified buffer can contain. However, the generated
|
||||
string is always null-terminated - even if not the whole path is written out.
|
||||
The function returns the total number of characters the complete buffer would
|
||||
have, even if it was not written out completely. The path may be the same
|
||||
memory address as the buffer.
|
||||
|
||||
**Note:** This function does not normalize the resulting path. You can use
|
||||
**[cwk_path_normalize]({{ site.baseurl }}{% link reference/cwk_path_normalize.md %})**
|
||||
to do so. Separators before and after the submitted basename will be trimmed,
|
||||
but not removed from the source path. The value may contain separators which
|
||||
will introduce new segments. If the submitted path does not have any segments,
|
||||
the basename will be appended as a new segment.
|
||||
|
||||
## Parameters
|
||||
* **path**: The original path which will be used for the modified path.
|
||||
* **new_basename**: The new basename which will replace the old one.
|
||||
* **buffer**: The buffer where the changed path will be written to.
|
||||
* **buffer_size**: The size of the result buffer where the changed path is written to.
|
||||
|
||||
## Return Value
|
||||
Returns the size which the complete new path would have if it was not truncated.
|
||||
|
||||
## Example
|
||||
```c
|
||||
#include <cwalk.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
cwk_path_change_basename("C:\\test.txt", "another.txt", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
printf("The new path: '%s'", buffer);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Ouput:
|
||||
```
|
||||
The new path: 'C:\another.txt'
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
| Version | Description |
|
||||
|------------|--------------------------------------------------------|
|
||||
---
|
||||
title: cwk_path_change_basename
|
||||
description: Changes the basename of a file path.
|
||||
---
|
||||
|
||||
_(since v1.2.0)_
|
||||
Changes the basename of a file path.
|
||||
|
||||
## Description
|
||||
```c
|
||||
size_t cwk_path_change_basename(const char *path, const char *new_basename,
|
||||
char *buffer, size_t buffer_size);
|
||||
```
|
||||
|
||||
This function changes the basename of a file path. This function will not
|
||||
write out more than the specified buffer can contain. However, the generated
|
||||
string is always null-terminated - even if not the whole path is written out.
|
||||
The function returns the total number of characters the complete buffer would
|
||||
have, even if it was not written out completely. The path may be the same
|
||||
memory address as the buffer.
|
||||
|
||||
**Note:** This function does not normalize the resulting path. You can use
|
||||
**[cwk_path_normalize]({{ site.baseurl }}{% link reference/cwk_path_normalize.md %})**
|
||||
to do so. Separators before and after the submitted basename will be trimmed,
|
||||
but not removed from the source path. The value may contain separators which
|
||||
will introduce new segments. If the submitted path does not have any segments,
|
||||
the basename will be appended as a new segment.
|
||||
|
||||
## Parameters
|
||||
* **path**: The original path which will be used for the modified path.
|
||||
* **new_basename**: The new basename which will replace the old one.
|
||||
* **buffer**: The buffer where the changed path will be written to.
|
||||
* **buffer_size**: The size of the result buffer where the changed path is written to.
|
||||
|
||||
## Return Value
|
||||
Returns the size which the complete new path would have if it was not truncated.
|
||||
|
||||
## Example
|
||||
```c
|
||||
#include <cwalk.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
cwk_path_change_basename("C:\\test.txt", "another.txt", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
printf("The new path: '%s'", buffer);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Ouput:
|
||||
```
|
||||
The new path: 'C:\another.txt'
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
| Version | Description |
|
||||
|------------|--------------------------------------------------------|
|
||||
| **v1.2.0** | The function is introduced. |
|
||||
@@ -1,71 +1,71 @@
|
||||
---
|
||||
title: cwk_path_change_extension
|
||||
description: Changes the extension of a file path.
|
||||
---
|
||||
|
||||
_(since v1.2.0)_
|
||||
Changes the extension of a file path.
|
||||
|
||||
## Description
|
||||
```c
|
||||
size_t cwk_path_change_extension(const char *path, const char *new_extension,
|
||||
char *buffer, size_t buffer_size);
|
||||
```
|
||||
|
||||
This function changes the extension of a file name. The function will append
|
||||
an extension if the basename does not have an extension, or use the extension
|
||||
as a basename if the path does not have a basename. This function will not
|
||||
write out more than the specified buffer can contain. However, the generated
|
||||
string is always null-terminated - even if not the whole path is written out.
|
||||
The function returns the total number of characters the complete buffer would
|
||||
have, even if it was not written out completely. The path may be the same
|
||||
memory address as the buffer.
|
||||
|
||||
**Note:** This function does not normalize the resulting path. You can use
|
||||
**[cwk_path_normalize]({{ site.baseurl }}{% link reference/cwk_path_normalize.md %})**
|
||||
to do so.
|
||||
|
||||
**Note:** If the ``new_extension`` parameter starts with a dot, the first dot will
|
||||
be ignored when the new extension is appended.
|
||||
|
||||
## Parameters
|
||||
* **path**: The path which will be used to make the change.
|
||||
* **new_extension**: The extension which will be placed within the new path.
|
||||
* **buffer**: The output buffer where the result will be written to.
|
||||
* **buffer_size**: The size of the output buffer where the result will be written to.
|
||||
|
||||
## Return Value
|
||||
Returns the total size which the output would have if it was not truncated.
|
||||
|
||||
## Example
|
||||
```c
|
||||
#include <cwalk.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
cwk_path_change_extension("C:\\test.txt", "md", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
printf("The new path: '%s'", buffer);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Ouput:
|
||||
```
|
||||
The new path: 'C:\test.md'
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
| Version | Description |
|
||||
|------------|--------------------------------------------------------|
|
||||
| **v1.2.0** | The function is introduced. |
|
||||
---
|
||||
title: cwk_path_change_extension
|
||||
description: Changes the extension of a file path.
|
||||
---
|
||||
|
||||
_(since v1.2.0)_
|
||||
Changes the extension of a file path.
|
||||
|
||||
## Description
|
||||
```c
|
||||
size_t cwk_path_change_extension(const char *path, const char *new_extension,
|
||||
char *buffer, size_t buffer_size);
|
||||
```
|
||||
|
||||
This function changes the extension of a file name. The function will append
|
||||
an extension if the basename does not have an extension, or use the extension
|
||||
as a basename if the path does not have a basename. This function will not
|
||||
write out more than the specified buffer can contain. However, the generated
|
||||
string is always null-terminated - even if not the whole path is written out.
|
||||
The function returns the total number of characters the complete buffer would
|
||||
have, even if it was not written out completely. The path may be the same
|
||||
memory address as the buffer.
|
||||
|
||||
**Note:** This function does not normalize the resulting path. You can use
|
||||
**[cwk_path_normalize]({{ site.baseurl }}{% link reference/cwk_path_normalize.md %})**
|
||||
to do so.
|
||||
|
||||
**Note:** If the ``new_extension`` parameter starts with a dot, the first dot will
|
||||
be ignored when the new extension is appended.
|
||||
|
||||
## Parameters
|
||||
* **path**: The path which will be used to make the change.
|
||||
* **new_extension**: The extension which will be placed within the new path.
|
||||
* **buffer**: The output buffer where the result will be written to.
|
||||
* **buffer_size**: The size of the output buffer where the result will be written to.
|
||||
|
||||
## Return Value
|
||||
Returns the total size which the output would have if it was not truncated.
|
||||
|
||||
## Example
|
||||
```c
|
||||
#include <cwalk.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
cwk_path_change_extension("C:\\test.txt", "md", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
printf("The new path: '%s'", buffer);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Ouput:
|
||||
```
|
||||
The new path: 'C:\test.md'
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
| Version | Description |
|
||||
|------------|--------------------------------------------------------|
|
||||
| **v1.2.0** | The function is introduced. |
|
||||
@@ -1,69 +1,69 @@
|
||||
---
|
||||
title: cwk_path_change_root
|
||||
description: Changes the root of a path.
|
||||
---
|
||||
|
||||
_(since v1.2.0)_
|
||||
Changes the root of a path.
|
||||
|
||||
## Description
|
||||
```c
|
||||
size_t cwk_path_change_root(const char *path, const char *new_root,
|
||||
char *buffer, size_t buffer_size);
|
||||
```
|
||||
|
||||
This function changes the root of a path. It does not normalize the result.
|
||||
The result will be written to a buffer, which might be truncated if the
|
||||
buffer is not large enough to hold the full path. However, the truncated
|
||||
result will always be null-terminated. The returned value is the amount of
|
||||
characters which the resulting path would take if it was not truncated
|
||||
(excluding the null-terminating character).
|
||||
|
||||
**Note:** This function does not normalize the resulting path. You can use
|
||||
**[cwk_path_normalize]({{ site.baseurl }}{% link reference/cwk_path_normalize.md %})**
|
||||
to do so. The new root may contain separators which will introduce new segments.
|
||||
If the submitted path does not have any root, the new root will be prepended to
|
||||
the path.
|
||||
|
||||
## Parameters
|
||||
* **path**: The original path which will get a new root.
|
||||
* **new_root**: The new root which will be placed in the path.
|
||||
* **buffer**: The output buffer where the result is written to.
|
||||
* **buffer_size**: The size of the output buffer where the result is written
|
||||
to.
|
||||
|
||||
## Return Value
|
||||
Returns the total amount of characters of the new path.
|
||||
|
||||
## Example
|
||||
```c
|
||||
#include <cwalk.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
cwk_path_change_root("C:\\test.txt", "D:\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
printf("The new path: '%s'", buffer);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Ouput:
|
||||
```
|
||||
The new path: 'D:\another.txt'
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
| Version | Description |
|
||||
|------------|--------------------------------------------------------|
|
||||
---
|
||||
title: cwk_path_change_root
|
||||
description: Changes the root of a path.
|
||||
---
|
||||
|
||||
_(since v1.2.0)_
|
||||
Changes the root of a path.
|
||||
|
||||
## Description
|
||||
```c
|
||||
size_t cwk_path_change_root(const char *path, const char *new_root,
|
||||
char *buffer, size_t buffer_size);
|
||||
```
|
||||
|
||||
This function changes the root of a path. It does not normalize the result.
|
||||
The result will be written to a buffer, which might be truncated if the
|
||||
buffer is not large enough to hold the full path. However, the truncated
|
||||
result will always be null-terminated. The returned value is the amount of
|
||||
characters which the resulting path would take if it was not truncated
|
||||
(excluding the null-terminating character).
|
||||
|
||||
**Note:** This function does not normalize the resulting path. You can use
|
||||
**[cwk_path_normalize]({{ site.baseurl }}{% link reference/cwk_path_normalize.md %})**
|
||||
to do so. The new root may contain separators which will introduce new segments.
|
||||
If the submitted path does not have any root, the new root will be prepended to
|
||||
the path.
|
||||
|
||||
## Parameters
|
||||
* **path**: The original path which will get a new root.
|
||||
* **new_root**: The new root which will be placed in the path.
|
||||
* **buffer**: The output buffer where the result is written to.
|
||||
* **buffer_size**: The size of the output buffer where the result is written
|
||||
to.
|
||||
|
||||
## Return Value
|
||||
Returns the total amount of characters of the new path.
|
||||
|
||||
## Example
|
||||
```c
|
||||
#include <cwalk.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
cwk_path_change_root("C:\\test.txt", "D:\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
printf("The new path: '%s'", buffer);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Ouput:
|
||||
```
|
||||
The new path: 'D:\another.txt'
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
| Version | Description |
|
||||
|------------|--------------------------------------------------------|
|
||||
| **v1.2.0** | The function is introduced. |
|
||||
@@ -1,72 +1,72 @@
|
||||
---
|
||||
title: cwk_path_change_segment
|
||||
description: Changes the content of a segment.
|
||||
---
|
||||
|
||||
_(since v1.2.0)_
|
||||
Changes the content of a segment.
|
||||
|
||||
## Description
|
||||
```c
|
||||
size_t cwk_path_change_segment(struct cwk_segment *segment, const char *value,
|
||||
char *buffer, size_t buffer_size);
|
||||
```
|
||||
|
||||
This function overrides the content of a segment to the submitted value and
|
||||
outputs the whole new path to the submitted buffer. The result might require
|
||||
less or more space than before if the new value length differs from the
|
||||
original length. The output is truncated if the new path is larger than the
|
||||
submitted buffer size, but it is always null-terminated. The source of the
|
||||
segment and the submitted buffer may be the same.
|
||||
|
||||
**Note:** This function does not normalize the resulting path. You can use
|
||||
**[cwk_path_normalize]({{ site.baseurl }}{% link reference/cwk_path_normalize.md %})**
|
||||
to do so. Separators before and after the value will be trimmed. The value may
|
||||
contain separators which will introduce new segments.
|
||||
|
||||
## Parameters
|
||||
* **segment**: The segment which will be modifier.
|
||||
* **value**: The new content of the segment.
|
||||
* **buffer**: The buffer where the modified path will be written to.
|
||||
* **buffer_size**: The size of the output buffer.
|
||||
|
||||
## Return Value
|
||||
Returns the total size which would have been written if the output was not
|
||||
truncated.
|
||||
|
||||
## Example
|
||||
```c
|
||||
#include <cwalk.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *path;
|
||||
char buffer[FILENAME_MAX];
|
||||
struct cwk_segment segment;
|
||||
|
||||
path = "/this/cool/path/";
|
||||
if (!cwk_path_get_first_segment(path, &segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cwk_path_change_segment(&segment, "other", buffer, sizeof(buffer));
|
||||
|
||||
printf("The new path: '%s'", buffer);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Ouput:
|
||||
```
|
||||
The new path: '/other/cool/path/'
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
| Version | Description |
|
||||
|------------|--------------------------------------------------------|
|
||||
| **v1.2.0** | The function is introduced. |
|
||||
---
|
||||
title: cwk_path_change_segment
|
||||
description: Changes the content of a segment.
|
||||
---
|
||||
|
||||
_(since v1.2.0)_
|
||||
Changes the content of a segment.
|
||||
|
||||
## Description
|
||||
```c
|
||||
size_t cwk_path_change_segment(struct cwk_segment *segment, const char *value,
|
||||
char *buffer, size_t buffer_size);
|
||||
```
|
||||
|
||||
This function overrides the content of a segment to the submitted value and
|
||||
outputs the whole new path to the submitted buffer. The result might require
|
||||
less or more space than before if the new value length differs from the
|
||||
original length. The output is truncated if the new path is larger than the
|
||||
submitted buffer size, but it is always null-terminated. The source of the
|
||||
segment and the submitted buffer may be the same.
|
||||
|
||||
**Note:** This function does not normalize the resulting path. You can use
|
||||
**[cwk_path_normalize]({{ site.baseurl }}{% link reference/cwk_path_normalize.md %})**
|
||||
to do so. Separators before and after the value will be trimmed. The value may
|
||||
contain separators which will introduce new segments.
|
||||
|
||||
## Parameters
|
||||
* **segment**: The segment which will be modifier.
|
||||
* **value**: The new content of the segment.
|
||||
* **buffer**: The buffer where the modified path will be written to.
|
||||
* **buffer_size**: The size of the output buffer.
|
||||
|
||||
## Return Value
|
||||
Returns the total size which would have been written if the output was not
|
||||
truncated.
|
||||
|
||||
## Example
|
||||
```c
|
||||
#include <cwalk.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *path;
|
||||
char buffer[FILENAME_MAX];
|
||||
struct cwk_segment segment;
|
||||
|
||||
path = "/this/cool/path/";
|
||||
if (!cwk_path_get_first_segment(path, &segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cwk_path_change_segment(&segment, "other", buffer, sizeof(buffer));
|
||||
|
||||
printf("The new path: '%s'", buffer);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Ouput:
|
||||
```
|
||||
The new path: '/other/cool/path/'
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
| Version | Description |
|
||||
|------------|--------------------------------------------------------|
|
||||
| **v1.2.0** | The function is introduced. |
|
||||
@@ -1,78 +1,78 @@
|
||||
---
|
||||
title: cwk_path_guess_style
|
||||
description: Guesses the path style.
|
||||
---
|
||||
|
||||
_(since v1.2.0)_
|
||||
Guesses the path style.
|
||||
|
||||
## Description
|
||||
```c
|
||||
enum cwk_path_style cwk_path_guess_style(const char *path);
|
||||
```
|
||||
|
||||
This function guesses the path style based on a submitted path-string. The guessing will look at the root and the type of slashes contained in the path and return the style which is more likely used in the path.
|
||||
The algorithm checks the following:
|
||||
1. If the root is longer than 1 character -> ``CWK_STYLE_WINDOWS``
|
||||
1. If the first separator is a backslash -> ``CWK_STYLE_WINDOWS``
|
||||
1. If the first separator is a slash -> ``CWK_STYLE_UNIX``
|
||||
1. If the last segment starts with a dot -> ``CWK_STYLE_UNIX``
|
||||
1. If the last segment contains a dot -> ``CWK_STYLE_WINDOWS``
|
||||
1. If nothing was found to determine the style -> ``CWK_STYLE_UNIX``
|
||||
|
||||
## Parameters
|
||||
* **path**: The path which will be inspected.
|
||||
|
||||
## Return Value
|
||||
Returns the style which is most likely used for the path.
|
||||
|
||||
## Outcomes
|
||||
|
||||
| Path | Result |
|
||||
|-----------------------------|-----------------------|
|
||||
| ``C:\\test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``C:/test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``C:test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``C:/.test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``C:/folder/.test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``\directory\other`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``\directory\.other`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``myfile.txt`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``/directory`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``/directory/other`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``/directory/other.txt`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``.my_hidden_file`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``.my_hidden_file.txt`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``/a/directory/myfile.txt`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``myfile`` | ``CWK_STYLE_UNIX`` |
|
||||
|
||||
## Example
|
||||
```c
|
||||
#include <cwalk.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (cwk_path_guess_style("C:\\myfile") == CWK_STYLE_UNIX) {
|
||||
printf("UNIX.");
|
||||
} else {
|
||||
printf("WINDOWS.");
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Ouput:
|
||||
```
|
||||
WINDOWS.
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
| Version | Description |
|
||||
|------------|--------------------------------------------------------|
|
||||
| **v1.2.1** | Fixed crash on call with empty string. |
|
||||
| **v1.2.0** | The function is introduced. |
|
||||
---
|
||||
title: cwk_path_guess_style
|
||||
description: Guesses the path style.
|
||||
---
|
||||
|
||||
_(since v1.2.0)_
|
||||
Guesses the path style.
|
||||
|
||||
## Description
|
||||
```c
|
||||
enum cwk_path_style cwk_path_guess_style(const char *path);
|
||||
```
|
||||
|
||||
This function guesses the path style based on a submitted path-string. The guessing will look at the root and the type of slashes contained in the path and return the style which is more likely used in the path.
|
||||
The algorithm checks the following:
|
||||
1. If the root is longer than 1 character -> ``CWK_STYLE_WINDOWS``
|
||||
1. If the first separator is a backslash -> ``CWK_STYLE_WINDOWS``
|
||||
1. If the first separator is a slash -> ``CWK_STYLE_UNIX``
|
||||
1. If the last segment starts with a dot -> ``CWK_STYLE_UNIX``
|
||||
1. If the last segment contains a dot -> ``CWK_STYLE_WINDOWS``
|
||||
1. If nothing was found to determine the style -> ``CWK_STYLE_UNIX``
|
||||
|
||||
## Parameters
|
||||
* **path**: The path which will be inspected.
|
||||
|
||||
## Return Value
|
||||
Returns the style which is most likely used for the path.
|
||||
|
||||
## Outcomes
|
||||
|
||||
| Path | Result |
|
||||
|-----------------------------|-----------------------|
|
||||
| ``C:\\test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``C:/test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``C:test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``C:/.test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``C:/folder/.test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``\directory\other`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``\directory\.other`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``myfile.txt`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``/directory`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``/directory/other`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``/directory/other.txt`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``.my_hidden_file`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``.my_hidden_file.txt`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``/a/directory/myfile.txt`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``myfile`` | ``CWK_STYLE_UNIX`` |
|
||||
|
||||
## Example
|
||||
```c
|
||||
#include <cwalk.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (cwk_path_guess_style("C:\\myfile") == CWK_STYLE_UNIX) {
|
||||
printf("UNIX.");
|
||||
} else {
|
||||
printf("WINDOWS.");
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Ouput:
|
||||
```
|
||||
WINDOWS.
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
| Version | Description |
|
||||
|------------|--------------------------------------------------------|
|
||||
| **v1.2.1** | Fixed crash on call with empty string. |
|
||||
| **v1.2.0** | The function is introduced. |
|
||||
+498
-498
@@ -1,498 +1,498 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef CWK_LIBRARY_H
|
||||
#define CWK_LIBRARY_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
#define CWK_EXPORT __declspec(dllexport)
|
||||
#define CWK_IMPORT __declspec(dllimport)
|
||||
#elif __GNUC__ >= 4
|
||||
#define CWK_EXPORT __attribute__((visibility("default")))
|
||||
#define CWK_IMPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
#define CWK_EXPORT
|
||||
#define CWK_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(CWK_SHARED)
|
||||
#if defined(CWK_EXPORTS)
|
||||
#define CWK_PUBLIC CWK_EXPORT
|
||||
#else
|
||||
#define CWK_PUBLIC CWK_IMPORT
|
||||
#endif
|
||||
#else
|
||||
#define CWK_PUBLIC
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A segment represents a single component of a path. For instance, on linux a
|
||||
* path might look like this "/var/log/", which consists of two segments "var"
|
||||
* and "log".
|
||||
*/
|
||||
struct cwk_segment
|
||||
{
|
||||
const char *path;
|
||||
const char *segments;
|
||||
const char *begin;
|
||||
const char *end;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
/**
|
||||
* The segment type can be used to identify whether a segment is a special
|
||||
* segment or not.
|
||||
*
|
||||
* CWK_NORMAL - normal folder or file segment
|
||||
* CWK_CURRENT - "./" current folder segment
|
||||
* CWK_BACK - "../" relative back navigation segment
|
||||
*/
|
||||
enum cwk_segment_type
|
||||
{
|
||||
CWK_NORMAL,
|
||||
CWK_CURRENT,
|
||||
CWK_BACK
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Determines the style which is used for the path parsing and
|
||||
* generation.
|
||||
*/
|
||||
enum cwk_path_style
|
||||
{
|
||||
CWK_STYLE_WINDOWS,
|
||||
CWK_STYLE_UNIX
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Generates an absolute path based on a base.
|
||||
*
|
||||
* This function generates an absolute path based on a base path and another
|
||||
* path. It is guaranteed to return an absolute path. If the second submitted
|
||||
* path is absolute, it will override the base path. The result will be
|
||||
* written to a buffer, which might be truncated if the buffer is not large
|
||||
* enough to hold the full path. However, the truncated result will always be
|
||||
* null-terminated. The returned value is the amount of characters which the
|
||||
* resulting path would take if it was not truncated (excluding the
|
||||
* null-terminating character).
|
||||
*
|
||||
* @param base The absolute base path on which the relative path will be
|
||||
* applied.
|
||||
* @param path The relative path which will be applied on the base path.
|
||||
* @param buffer The buffer where the result will be written to.
|
||||
* @param buffer_size The size of the result buffer.
|
||||
* @return Returns the total amount of characters of the new absolute path.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_get_absolute(const char *base, const char *path,
|
||||
char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Generates a relative path based on a base.
|
||||
*
|
||||
* This function generates a relative path based on a base path and another
|
||||
* path. It determines how to get to the submitted path, starting from the
|
||||
* base directory. The result will be written to a buffer, which might be
|
||||
* truncated if the buffer is not large enough to hold the full path. However,
|
||||
* the truncated result will always be null-terminated. The returned value is
|
||||
* the amount of characters which the resulting path would take if it was not
|
||||
* truncated (excluding the null-terminating character).
|
||||
*
|
||||
* @param base_directory The base path from which the relative path will
|
||||
* start.
|
||||
* @param path The target path where the relative path will point to.
|
||||
* @param buffer The buffer where the result will be written to.
|
||||
* @param buffer_size The size of the result buffer.
|
||||
* @return Returns the total amount of characters of the full path.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_get_relative(const char *base_directory,
|
||||
const char *path, char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Joins two paths together.
|
||||
*
|
||||
* This function generates a new path by combining the two submitted paths. It
|
||||
* will remove double separators, and unlike cwk_path_get_absolute it permits
|
||||
* the use of two relative paths to combine. The result will be written to a
|
||||
* buffer, which might be truncated if the buffer is not large enough to hold
|
||||
* the full path. However, the truncated result will always be
|
||||
* null-terminated. The returned value is the amount of characters which the
|
||||
* resulting path would take if it was not truncated (excluding the
|
||||
* null-terminating character).
|
||||
*
|
||||
* @param path_a The first path which comes first.
|
||||
* @param path_b The second path which comes after the first.
|
||||
* @param buffer The buffer where the result will be written to.
|
||||
* @param buffer_size The size of the result buffer.
|
||||
* @return Returns the total amount of characters of the full, combined path.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_join(const char *path_a, const char *path_b,
|
||||
char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Joins multiple paths together.
|
||||
*
|
||||
* This function generates a new path by joining multiple paths together. It
|
||||
* will remove double separators, and unlike cwk_path_get_absolute it permits
|
||||
* the use of multiple relative paths to combine. The last path of the
|
||||
* submitted string array must be set to NULL. The result will be written to a
|
||||
* buffer, which might be truncated if the buffer is not large enough to hold
|
||||
* the full path. However, the truncated result will always be
|
||||
* null-terminated. The returned value is the amount of characters which the
|
||||
* resulting path would take if it was not truncated (excluding the
|
||||
* null-terminating character).
|
||||
*
|
||||
* @param paths An array of paths which will be joined.
|
||||
* @param buffer The buffer where the result will be written to.
|
||||
* @param buffer_size The size of the result buffer.
|
||||
* @return Returns the total amount of characters of the full, combined path.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_join_multiple(const char **paths, char *buffer,
|
||||
size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Determines the root of a path.
|
||||
*
|
||||
* This function determines the root of a path by finding its length. The
|
||||
* root always starts at the submitted path. If the path has no root, the
|
||||
* length will be set to zero.
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @param length The output of the root length.
|
||||
*/
|
||||
CWK_PUBLIC void cwk_path_get_root(const char *path, size_t *length);
|
||||
|
||||
/**
|
||||
* @brief Changes the root of a path.
|
||||
*
|
||||
* This function changes the root of a path. It does not normalize the result.
|
||||
* The result will be written to a buffer, which might be truncated if the
|
||||
* buffer is not large enough to hold the full path. However, the truncated
|
||||
* result will always be null-terminated. The returned value is the amount of
|
||||
* characters which the resulting path would take if it was not truncated
|
||||
* (excluding the null-terminating character).
|
||||
*
|
||||
* @param path The original path which will get a new root.
|
||||
* @param new_root The new root which will be placed in the path.
|
||||
* @param buffer The output buffer where the result is written to.
|
||||
* @param buffer_size The size of the output buffer where the result is
|
||||
* written to.
|
||||
* @return Returns the total amount of characters of the new path.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_change_root(const char *path, const char *new_root,
|
||||
char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Determine whether the path is absolute or not.
|
||||
*
|
||||
* This function checks whether the path is an absolute path or not. A path is
|
||||
* considered to be absolute if the root ends with a separator.
|
||||
*
|
||||
* @param path The path which will be checked.
|
||||
* @return Returns true if the path is absolute or false otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_is_absolute(const char *path);
|
||||
|
||||
/**
|
||||
* @brief Determine whether the path is relative or not.
|
||||
*
|
||||
* This function checks whether the path is a relative path or not. A path is
|
||||
* considered to be relative if the root does not end with a separator.
|
||||
*
|
||||
* @param path The path which will be checked.
|
||||
* @return Returns true if the path is relative or false otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_is_relative(const char *path);
|
||||
|
||||
/**
|
||||
* @brief Gets the basename of a file path.
|
||||
*
|
||||
* This function gets the basename of a file path. A pointer to the beginning
|
||||
* of the basename will be returned through the basename parameter. This
|
||||
* pointer will be positioned on the first letter after the separator. The
|
||||
* length of the file path will be returned through the length parameter. The
|
||||
* length will be set to zero and the basename to NULL if there is no basename
|
||||
* available.
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @param basename The output of the basename pointer.
|
||||
* @param length The output of the length of the basename. This may be
|
||||
* null if not required.
|
||||
*/
|
||||
CWK_PUBLIC void cwk_path_get_basename(const char *path, const char **basename,
|
||||
size_t *length);
|
||||
|
||||
/**
|
||||
* @brief Changes the basename of a file path.
|
||||
*
|
||||
* This function changes the basename of a file path. This function will not
|
||||
* write out more than the specified buffer can contain. However, the
|
||||
* generated string is always null-terminated - even if not the whole path is
|
||||
* written out. The function returns the total number of characters the
|
||||
* complete buffer would have, even if it was not written out completely. The
|
||||
* path may be the same memory address as the buffer.
|
||||
*
|
||||
* @param path The original path which will be used for the modified path.
|
||||
* @param new_basename The new basename which will replace the old one.
|
||||
* @param buffer The buffer where the changed path will be written to.
|
||||
* @param buffer_size The size of the result buffer where the changed path is
|
||||
* written to.
|
||||
* @return Returns the size which the complete new path would have if it was
|
||||
* not truncated.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_change_basename(const char *path,
|
||||
const char *new_basename, char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Gets the dirname of a file path.
|
||||
*
|
||||
* This function determines the dirname of a file path and returns the length
|
||||
* up to which character is considered to be part of it. If no dirname is
|
||||
* found, the length will be set to zero. The beginning of the dirname is
|
||||
* always equal to the submitted path pointer.
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @param length The length of the dirname.
|
||||
*/
|
||||
CWK_PUBLIC void cwk_path_get_dirname(const char *path, size_t *length);
|
||||
|
||||
/**
|
||||
* @brief Gets the extension of a file path.
|
||||
*
|
||||
* This function extracts the extension portion of a file path. A pointer to
|
||||
* the beginning of the extension will be returned through the extension
|
||||
* parameter if an extension is found and true is returned. This pointer will
|
||||
* be positioned on the dot. The length of the extension name will be returned
|
||||
* through the length parameter. If no extension is found both parameters
|
||||
* won't be touched and false will be returned.
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @param extension The output of the extension pointer.
|
||||
* @param length The output of the length of the extension.
|
||||
* @return Returns true if an extension is found or false otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_get_extension(const char *path, const char **extension,
|
||||
size_t *length);
|
||||
|
||||
/**
|
||||
* @brief Determines whether the file path has an extension.
|
||||
*
|
||||
* This function determines whether the submitted file path has an extension.
|
||||
* This will evaluate to true if the last segment of the path contains a dot.
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @return Returns true if the path has an extension or false otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_has_extension(const char *path);
|
||||
|
||||
/**
|
||||
* @brief Changes the extension of a file path.
|
||||
*
|
||||
* This function changes the extension of a file name. The function will
|
||||
* append an extension if the basename does not have an extension, or use the
|
||||
* extension as a basename if the path does not have a basename. This function
|
||||
* will not write out more than the specified buffer can contain. However, the
|
||||
* generated string is always null-terminated - even if not the whole path is
|
||||
* written out. The function returns the total number of characters the
|
||||
* complete buffer would have, even if it was not written out completely. The
|
||||
* path may be the same memory address as the buffer.
|
||||
*
|
||||
* @param path The path which will be used to make the change.
|
||||
* @param new_extension The extension which will be placed within the new
|
||||
* path.
|
||||
* @param buffer The output buffer where the result will be written to.
|
||||
* @param buffer_size The size of the output buffer where the result will be
|
||||
* written to.
|
||||
* @return Returns the total size which the output would have if it was not
|
||||
* truncated.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_change_extension(const char *path,
|
||||
const char *new_extension, char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Creates a normalized version of the path.
|
||||
*
|
||||
* This function creates a normalized version of the path within the specified
|
||||
* buffer. This function will not write out more than the specified buffer can
|
||||
* contain. However, the generated string is always null-terminated - even if
|
||||
* not the whole path is written out. The function returns the total number of
|
||||
* characters the complete buffer would have, even if it was not written out
|
||||
* completely. The path may be the same memory address as the buffer.
|
||||
*
|
||||
* The following will be true for the normalized path:
|
||||
* 1) "../" will be resolved.
|
||||
* 2) "./" will be removed.
|
||||
* 3) double separators will be fixed with a single separator.
|
||||
* 4) separator suffixes will be removed.
|
||||
*
|
||||
* @param path The path which will be normalized.
|
||||
* @param buffer The buffer where the new path is written to.
|
||||
* @param buffer_size The size of the buffer.
|
||||
* @return The size which the complete normalized path has if it was not
|
||||
* truncated.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_normalize(const char *path, char *buffer,
|
||||
size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Finds common portions in two paths.
|
||||
*
|
||||
* This function finds common portions in two paths and returns the number
|
||||
* characters from the beginning of the base path which are equal to the other
|
||||
* path.
|
||||
*
|
||||
* @param path_base The base path which will be compared with the other path.
|
||||
* @param path_other The other path which will compared with the base path.
|
||||
* @return Returns the number of characters which are common in the base path.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_get_intersection(const char *path_base,
|
||||
const char *path_other);
|
||||
|
||||
/**
|
||||
* @brief Gets the first segment of a path.
|
||||
*
|
||||
* This function finds the first segment of a path. The position of the
|
||||
* segment is set to the first character after the separator, and the length
|
||||
* counts all characters until the next separator (excluding the separator).
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @param segment The segment which will be extracted.
|
||||
* @return Returns true if there is a segment or false if there is none.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_get_first_segment(const char *path,
|
||||
struct cwk_segment *segment);
|
||||
|
||||
/**
|
||||
* @brief Gets the last segment of the path.
|
||||
*
|
||||
* This function gets the last segment of a path. This function may return
|
||||
* false if the path doesn't contain any segments, in which case the submitted
|
||||
* segment parameter is not modified. The position of the segment is set to
|
||||
* the first character after the separator, and the length counts all
|
||||
* characters until the end of the path (excluding the separator).
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @param segment The segment which will be extracted.
|
||||
* @return Returns true if there is a segment or false if there is none.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_get_last_segment(const char *path,
|
||||
struct cwk_segment *segment);
|
||||
|
||||
/**
|
||||
* @brief Advances to the next segment.
|
||||
*
|
||||
* This function advances the current segment to the next segment. If there
|
||||
* are no more segments left, the submitted segment structure will stay
|
||||
* unchanged and false is returned.
|
||||
*
|
||||
* @param segment The current segment which will be advanced to the next one.
|
||||
* @return Returns true if another segment was found or false otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_get_next_segment(struct cwk_segment *segment);
|
||||
|
||||
/**
|
||||
* @brief Moves to the previous segment.
|
||||
*
|
||||
* This function moves the current segment to the previous segment. If the
|
||||
* current segment is the first one, the submitted segment structure will stay
|
||||
* unchanged and false is returned.
|
||||
*
|
||||
* @param segment The current segment which will be moved to the previous one.
|
||||
* @return Returns true if there is a segment before this one or false
|
||||
* otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_get_previous_segment(struct cwk_segment *segment);
|
||||
|
||||
/**
|
||||
* @brief Gets the type of the submitted path segment.
|
||||
*
|
||||
* This function inspects the contents of the segment and determines the type
|
||||
* of it. Currently, there are three types CWK_NORMAL, CWK_CURRENT and
|
||||
* CWK_BACK. A CWK_NORMAL segment is a normal folder or file entry. A
|
||||
* CWK_CURRENT is a "./" and a CWK_BACK a "../" segment.
|
||||
*
|
||||
* @param segment The segment which will be inspected.
|
||||
* @return Returns the type of the segment.
|
||||
*/
|
||||
CWK_PUBLIC enum cwk_segment_type cwk_path_get_segment_type(
|
||||
const struct cwk_segment *segment);
|
||||
|
||||
/**
|
||||
* @brief Changes the content of a segment.
|
||||
*
|
||||
* This function overrides the content of a segment to the submitted value and
|
||||
* outputs the whole new path to the submitted buffer. The result might
|
||||
* require less or more space than before if the new value length differs from
|
||||
* the original length. The output is truncated if the new path is larger than
|
||||
* the submitted buffer size, but it is always null-terminated. The source of
|
||||
* the segment and the submitted buffer may be the same.
|
||||
*
|
||||
* @param segment The segment which will be modifier.
|
||||
* @param value The new content of the segment.
|
||||
* @param buffer The buffer where the modified path will be written to.
|
||||
* @param buffer_size The size of the output buffer.
|
||||
* @return Returns the total size which would have been written if the output
|
||||
* was not truncated.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_change_segment(struct cwk_segment *segment,
|
||||
const char *value, char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Checks whether the submitted pointer points to a separator.
|
||||
*
|
||||
* This function simply checks whether the submitted pointer points to a
|
||||
* separator, which has to be null-terminated (but not necessarily after the
|
||||
* separator). The function will return true if it is a separator, or false
|
||||
* otherwise.
|
||||
*
|
||||
* @param symbol A pointer to a string.
|
||||
* @return Returns true if it is a separator, or false otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_is_separator(const char *str);
|
||||
|
||||
/**
|
||||
* @brief Guesses the path style.
|
||||
*
|
||||
* This function guesses the path style based on a submitted path-string. The
|
||||
* guessing will look at the root and the type of slashes contained in the
|
||||
* path and return the style which is more likely used in the path.
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @return Returns the style which is most likely used for the path.
|
||||
*/
|
||||
CWK_PUBLIC enum cwk_path_style cwk_path_guess_style(const char *path);
|
||||
|
||||
/**
|
||||
* @brief Configures which path style is used.
|
||||
*
|
||||
* This function configures which path style is used. The following styles are
|
||||
* currently supported.
|
||||
*
|
||||
* CWK_STYLE_WINDOWS: Use backslashes as a separator and volume for the root.
|
||||
* CWK_STYLE_UNIX: Use slashes as a separator and a slash for the root.
|
||||
*
|
||||
* @param style The style which will be used from now on.
|
||||
*/
|
||||
CWK_PUBLIC void cwk_path_set_style(enum cwk_path_style style);
|
||||
|
||||
/**
|
||||
* @brief Gets the path style configuration.
|
||||
*
|
||||
* This function gets the style configuration which is currently used for the
|
||||
* paths. This configuration determines how paths are parsed and generated.
|
||||
*
|
||||
* @return Returns the current path style configuration.
|
||||
*/
|
||||
CWK_PUBLIC enum cwk_path_style cwk_path_get_style(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#ifndef CWK_LIBRARY_H
|
||||
#define CWK_LIBRARY_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
#define CWK_EXPORT __declspec(dllexport)
|
||||
#define CWK_IMPORT __declspec(dllimport)
|
||||
#elif __GNUC__ >= 4
|
||||
#define CWK_EXPORT __attribute__((visibility("default")))
|
||||
#define CWK_IMPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
#define CWK_EXPORT
|
||||
#define CWK_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(CWK_SHARED)
|
||||
#if defined(CWK_EXPORTS)
|
||||
#define CWK_PUBLIC CWK_EXPORT
|
||||
#else
|
||||
#define CWK_PUBLIC CWK_IMPORT
|
||||
#endif
|
||||
#else
|
||||
#define CWK_PUBLIC
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A segment represents a single component of a path. For instance, on linux a
|
||||
* path might look like this "/var/log/", which consists of two segments "var"
|
||||
* and "log".
|
||||
*/
|
||||
struct cwk_segment
|
||||
{
|
||||
const char *path;
|
||||
const char *segments;
|
||||
const char *begin;
|
||||
const char *end;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
/**
|
||||
* The segment type can be used to identify whether a segment is a special
|
||||
* segment or not.
|
||||
*
|
||||
* CWK_NORMAL - normal folder or file segment
|
||||
* CWK_CURRENT - "./" current folder segment
|
||||
* CWK_BACK - "../" relative back navigation segment
|
||||
*/
|
||||
enum cwk_segment_type
|
||||
{
|
||||
CWK_NORMAL,
|
||||
CWK_CURRENT,
|
||||
CWK_BACK
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Determines the style which is used for the path parsing and
|
||||
* generation.
|
||||
*/
|
||||
enum cwk_path_style
|
||||
{
|
||||
CWK_STYLE_WINDOWS,
|
||||
CWK_STYLE_UNIX
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Generates an absolute path based on a base.
|
||||
*
|
||||
* This function generates an absolute path based on a base path and another
|
||||
* path. It is guaranteed to return an absolute path. If the second submitted
|
||||
* path is absolute, it will override the base path. The result will be
|
||||
* written to a buffer, which might be truncated if the buffer is not large
|
||||
* enough to hold the full path. However, the truncated result will always be
|
||||
* null-terminated. The returned value is the amount of characters which the
|
||||
* resulting path would take if it was not truncated (excluding the
|
||||
* null-terminating character).
|
||||
*
|
||||
* @param base The absolute base path on which the relative path will be
|
||||
* applied.
|
||||
* @param path The relative path which will be applied on the base path.
|
||||
* @param buffer The buffer where the result will be written to.
|
||||
* @param buffer_size The size of the result buffer.
|
||||
* @return Returns the total amount of characters of the new absolute path.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_get_absolute(const char *base, const char *path,
|
||||
char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Generates a relative path based on a base.
|
||||
*
|
||||
* This function generates a relative path based on a base path and another
|
||||
* path. It determines how to get to the submitted path, starting from the
|
||||
* base directory. The result will be written to a buffer, which might be
|
||||
* truncated if the buffer is not large enough to hold the full path. However,
|
||||
* the truncated result will always be null-terminated. The returned value is
|
||||
* the amount of characters which the resulting path would take if it was not
|
||||
* truncated (excluding the null-terminating character).
|
||||
*
|
||||
* @param base_directory The base path from which the relative path will
|
||||
* start.
|
||||
* @param path The target path where the relative path will point to.
|
||||
* @param buffer The buffer where the result will be written to.
|
||||
* @param buffer_size The size of the result buffer.
|
||||
* @return Returns the total amount of characters of the full path.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_get_relative(const char *base_directory,
|
||||
const char *path, char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Joins two paths together.
|
||||
*
|
||||
* This function generates a new path by combining the two submitted paths. It
|
||||
* will remove double separators, and unlike cwk_path_get_absolute it permits
|
||||
* the use of two relative paths to combine. The result will be written to a
|
||||
* buffer, which might be truncated if the buffer is not large enough to hold
|
||||
* the full path. However, the truncated result will always be
|
||||
* null-terminated. The returned value is the amount of characters which the
|
||||
* resulting path would take if it was not truncated (excluding the
|
||||
* null-terminating character).
|
||||
*
|
||||
* @param path_a The first path which comes first.
|
||||
* @param path_b The second path which comes after the first.
|
||||
* @param buffer The buffer where the result will be written to.
|
||||
* @param buffer_size The size of the result buffer.
|
||||
* @return Returns the total amount of characters of the full, combined path.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_join(const char *path_a, const char *path_b,
|
||||
char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Joins multiple paths together.
|
||||
*
|
||||
* This function generates a new path by joining multiple paths together. It
|
||||
* will remove double separators, and unlike cwk_path_get_absolute it permits
|
||||
* the use of multiple relative paths to combine. The last path of the
|
||||
* submitted string array must be set to NULL. The result will be written to a
|
||||
* buffer, which might be truncated if the buffer is not large enough to hold
|
||||
* the full path. However, the truncated result will always be
|
||||
* null-terminated. The returned value is the amount of characters which the
|
||||
* resulting path would take if it was not truncated (excluding the
|
||||
* null-terminating character).
|
||||
*
|
||||
* @param paths An array of paths which will be joined.
|
||||
* @param buffer The buffer where the result will be written to.
|
||||
* @param buffer_size The size of the result buffer.
|
||||
* @return Returns the total amount of characters of the full, combined path.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_join_multiple(const char **paths, char *buffer,
|
||||
size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Determines the root of a path.
|
||||
*
|
||||
* This function determines the root of a path by finding its length. The
|
||||
* root always starts at the submitted path. If the path has no root, the
|
||||
* length will be set to zero.
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @param length The output of the root length.
|
||||
*/
|
||||
CWK_PUBLIC void cwk_path_get_root(const char *path, size_t *length);
|
||||
|
||||
/**
|
||||
* @brief Changes the root of a path.
|
||||
*
|
||||
* This function changes the root of a path. It does not normalize the result.
|
||||
* The result will be written to a buffer, which might be truncated if the
|
||||
* buffer is not large enough to hold the full path. However, the truncated
|
||||
* result will always be null-terminated. The returned value is the amount of
|
||||
* characters which the resulting path would take if it was not truncated
|
||||
* (excluding the null-terminating character).
|
||||
*
|
||||
* @param path The original path which will get a new root.
|
||||
* @param new_root The new root which will be placed in the path.
|
||||
* @param buffer The output buffer where the result is written to.
|
||||
* @param buffer_size The size of the output buffer where the result is
|
||||
* written to.
|
||||
* @return Returns the total amount of characters of the new path.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_change_root(const char *path, const char *new_root,
|
||||
char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Determine whether the path is absolute or not.
|
||||
*
|
||||
* This function checks whether the path is an absolute path or not. A path is
|
||||
* considered to be absolute if the root ends with a separator.
|
||||
*
|
||||
* @param path The path which will be checked.
|
||||
* @return Returns true if the path is absolute or false otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_is_absolute(const char *path);
|
||||
|
||||
/**
|
||||
* @brief Determine whether the path is relative or not.
|
||||
*
|
||||
* This function checks whether the path is a relative path or not. A path is
|
||||
* considered to be relative if the root does not end with a separator.
|
||||
*
|
||||
* @param path The path which will be checked.
|
||||
* @return Returns true if the path is relative or false otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_is_relative(const char *path);
|
||||
|
||||
/**
|
||||
* @brief Gets the basename of a file path.
|
||||
*
|
||||
* This function gets the basename of a file path. A pointer to the beginning
|
||||
* of the basename will be returned through the basename parameter. This
|
||||
* pointer will be positioned on the first letter after the separator. The
|
||||
* length of the file path will be returned through the length parameter. The
|
||||
* length will be set to zero and the basename to NULL if there is no basename
|
||||
* available.
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @param basename The output of the basename pointer.
|
||||
* @param length The output of the length of the basename. This may be
|
||||
* null if not required.
|
||||
*/
|
||||
CWK_PUBLIC void cwk_path_get_basename(const char *path, const char **basename,
|
||||
size_t *length);
|
||||
|
||||
/**
|
||||
* @brief Changes the basename of a file path.
|
||||
*
|
||||
* This function changes the basename of a file path. This function will not
|
||||
* write out more than the specified buffer can contain. However, the
|
||||
* generated string is always null-terminated - even if not the whole path is
|
||||
* written out. The function returns the total number of characters the
|
||||
* complete buffer would have, even if it was not written out completely. The
|
||||
* path may be the same memory address as the buffer.
|
||||
*
|
||||
* @param path The original path which will be used for the modified path.
|
||||
* @param new_basename The new basename which will replace the old one.
|
||||
* @param buffer The buffer where the changed path will be written to.
|
||||
* @param buffer_size The size of the result buffer where the changed path is
|
||||
* written to.
|
||||
* @return Returns the size which the complete new path would have if it was
|
||||
* not truncated.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_change_basename(const char *path,
|
||||
const char *new_basename, char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Gets the dirname of a file path.
|
||||
*
|
||||
* This function determines the dirname of a file path and returns the length
|
||||
* up to which character is considered to be part of it. If no dirname is
|
||||
* found, the length will be set to zero. The beginning of the dirname is
|
||||
* always equal to the submitted path pointer.
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @param length The length of the dirname.
|
||||
*/
|
||||
CWK_PUBLIC void cwk_path_get_dirname(const char *path, size_t *length);
|
||||
|
||||
/**
|
||||
* @brief Gets the extension of a file path.
|
||||
*
|
||||
* This function extracts the extension portion of a file path. A pointer to
|
||||
* the beginning of the extension will be returned through the extension
|
||||
* parameter if an extension is found and true is returned. This pointer will
|
||||
* be positioned on the dot. The length of the extension name will be returned
|
||||
* through the length parameter. If no extension is found both parameters
|
||||
* won't be touched and false will be returned.
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @param extension The output of the extension pointer.
|
||||
* @param length The output of the length of the extension.
|
||||
* @return Returns true if an extension is found or false otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_get_extension(const char *path, const char **extension,
|
||||
size_t *length);
|
||||
|
||||
/**
|
||||
* @brief Determines whether the file path has an extension.
|
||||
*
|
||||
* This function determines whether the submitted file path has an extension.
|
||||
* This will evaluate to true if the last segment of the path contains a dot.
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @return Returns true if the path has an extension or false otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_has_extension(const char *path);
|
||||
|
||||
/**
|
||||
* @brief Changes the extension of a file path.
|
||||
*
|
||||
* This function changes the extension of a file name. The function will
|
||||
* append an extension if the basename does not have an extension, or use the
|
||||
* extension as a basename if the path does not have a basename. This function
|
||||
* will not write out more than the specified buffer can contain. However, the
|
||||
* generated string is always null-terminated - even if not the whole path is
|
||||
* written out. The function returns the total number of characters the
|
||||
* complete buffer would have, even if it was not written out completely. The
|
||||
* path may be the same memory address as the buffer.
|
||||
*
|
||||
* @param path The path which will be used to make the change.
|
||||
* @param new_extension The extension which will be placed within the new
|
||||
* path.
|
||||
* @param buffer The output buffer where the result will be written to.
|
||||
* @param buffer_size The size of the output buffer where the result will be
|
||||
* written to.
|
||||
* @return Returns the total size which the output would have if it was not
|
||||
* truncated.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_change_extension(const char *path,
|
||||
const char *new_extension, char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Creates a normalized version of the path.
|
||||
*
|
||||
* This function creates a normalized version of the path within the specified
|
||||
* buffer. This function will not write out more than the specified buffer can
|
||||
* contain. However, the generated string is always null-terminated - even if
|
||||
* not the whole path is written out. The function returns the total number of
|
||||
* characters the complete buffer would have, even if it was not written out
|
||||
* completely. The path may be the same memory address as the buffer.
|
||||
*
|
||||
* The following will be true for the normalized path:
|
||||
* 1) "../" will be resolved.
|
||||
* 2) "./" will be removed.
|
||||
* 3) double separators will be fixed with a single separator.
|
||||
* 4) separator suffixes will be removed.
|
||||
*
|
||||
* @param path The path which will be normalized.
|
||||
* @param buffer The buffer where the new path is written to.
|
||||
* @param buffer_size The size of the buffer.
|
||||
* @return The size which the complete normalized path has if it was not
|
||||
* truncated.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_normalize(const char *path, char *buffer,
|
||||
size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Finds common portions in two paths.
|
||||
*
|
||||
* This function finds common portions in two paths and returns the number
|
||||
* characters from the beginning of the base path which are equal to the other
|
||||
* path.
|
||||
*
|
||||
* @param path_base The base path which will be compared with the other path.
|
||||
* @param path_other The other path which will compared with the base path.
|
||||
* @return Returns the number of characters which are common in the base path.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_get_intersection(const char *path_base,
|
||||
const char *path_other);
|
||||
|
||||
/**
|
||||
* @brief Gets the first segment of a path.
|
||||
*
|
||||
* This function finds the first segment of a path. The position of the
|
||||
* segment is set to the first character after the separator, and the length
|
||||
* counts all characters until the next separator (excluding the separator).
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @param segment The segment which will be extracted.
|
||||
* @return Returns true if there is a segment or false if there is none.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_get_first_segment(const char *path,
|
||||
struct cwk_segment *segment);
|
||||
|
||||
/**
|
||||
* @brief Gets the last segment of the path.
|
||||
*
|
||||
* This function gets the last segment of a path. This function may return
|
||||
* false if the path doesn't contain any segments, in which case the submitted
|
||||
* segment parameter is not modified. The position of the segment is set to
|
||||
* the first character after the separator, and the length counts all
|
||||
* characters until the end of the path (excluding the separator).
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @param segment The segment which will be extracted.
|
||||
* @return Returns true if there is a segment or false if there is none.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_get_last_segment(const char *path,
|
||||
struct cwk_segment *segment);
|
||||
|
||||
/**
|
||||
* @brief Advances to the next segment.
|
||||
*
|
||||
* This function advances the current segment to the next segment. If there
|
||||
* are no more segments left, the submitted segment structure will stay
|
||||
* unchanged and false is returned.
|
||||
*
|
||||
* @param segment The current segment which will be advanced to the next one.
|
||||
* @return Returns true if another segment was found or false otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_get_next_segment(struct cwk_segment *segment);
|
||||
|
||||
/**
|
||||
* @brief Moves to the previous segment.
|
||||
*
|
||||
* This function moves the current segment to the previous segment. If the
|
||||
* current segment is the first one, the submitted segment structure will stay
|
||||
* unchanged and false is returned.
|
||||
*
|
||||
* @param segment The current segment which will be moved to the previous one.
|
||||
* @return Returns true if there is a segment before this one or false
|
||||
* otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_get_previous_segment(struct cwk_segment *segment);
|
||||
|
||||
/**
|
||||
* @brief Gets the type of the submitted path segment.
|
||||
*
|
||||
* This function inspects the contents of the segment and determines the type
|
||||
* of it. Currently, there are three types CWK_NORMAL, CWK_CURRENT and
|
||||
* CWK_BACK. A CWK_NORMAL segment is a normal folder or file entry. A
|
||||
* CWK_CURRENT is a "./" and a CWK_BACK a "../" segment.
|
||||
*
|
||||
* @param segment The segment which will be inspected.
|
||||
* @return Returns the type of the segment.
|
||||
*/
|
||||
CWK_PUBLIC enum cwk_segment_type cwk_path_get_segment_type(
|
||||
const struct cwk_segment *segment);
|
||||
|
||||
/**
|
||||
* @brief Changes the content of a segment.
|
||||
*
|
||||
* This function overrides the content of a segment to the submitted value and
|
||||
* outputs the whole new path to the submitted buffer. The result might
|
||||
* require less or more space than before if the new value length differs from
|
||||
* the original length. The output is truncated if the new path is larger than
|
||||
* the submitted buffer size, but it is always null-terminated. The source of
|
||||
* the segment and the submitted buffer may be the same.
|
||||
*
|
||||
* @param segment The segment which will be modifier.
|
||||
* @param value The new content of the segment.
|
||||
* @param buffer The buffer where the modified path will be written to.
|
||||
* @param buffer_size The size of the output buffer.
|
||||
* @return Returns the total size which would have been written if the output
|
||||
* was not truncated.
|
||||
*/
|
||||
CWK_PUBLIC size_t cwk_path_change_segment(struct cwk_segment *segment,
|
||||
const char *value, char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Checks whether the submitted pointer points to a separator.
|
||||
*
|
||||
* This function simply checks whether the submitted pointer points to a
|
||||
* separator, which has to be null-terminated (but not necessarily after the
|
||||
* separator). The function will return true if it is a separator, or false
|
||||
* otherwise.
|
||||
*
|
||||
* @param symbol A pointer to a string.
|
||||
* @return Returns true if it is a separator, or false otherwise.
|
||||
*/
|
||||
CWK_PUBLIC bool cwk_path_is_separator(const char *str);
|
||||
|
||||
/**
|
||||
* @brief Guesses the path style.
|
||||
*
|
||||
* This function guesses the path style based on a submitted path-string. The
|
||||
* guessing will look at the root and the type of slashes contained in the
|
||||
* path and return the style which is more likely used in the path.
|
||||
*
|
||||
* @param path The path which will be inspected.
|
||||
* @return Returns the style which is most likely used for the path.
|
||||
*/
|
||||
CWK_PUBLIC enum cwk_path_style cwk_path_guess_style(const char *path);
|
||||
|
||||
/**
|
||||
* @brief Configures which path style is used.
|
||||
*
|
||||
* This function configures which path style is used. The following styles are
|
||||
* currently supported.
|
||||
*
|
||||
* CWK_STYLE_WINDOWS: Use backslashes as a separator and volume for the root.
|
||||
* CWK_STYLE_UNIX: Use slashes as a separator and a slash for the root.
|
||||
*
|
||||
* @param style The style which will be used from now on.
|
||||
*/
|
||||
CWK_PUBLIC void cwk_path_set_style(enum cwk_path_style style);
|
||||
|
||||
/**
|
||||
* @brief Gets the path style configuration.
|
||||
*
|
||||
* This function gets the style configuration which is currently used for the
|
||||
* paths. This configuration determines how paths are parsed and generated.
|
||||
*
|
||||
* @return Returns the current path style configuration.
|
||||
*/
|
||||
CWK_PUBLIC enum cwk_path_style cwk_path_get_style(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+1479
-1479
File diff suppressed because it is too large.
Load diff
+206
-206
@@ -1,206 +1,206 @@
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
int absolute_check()
|
||||
{
|
||||
const char *relative_paths[] = {"..", "test", "test/test", "../another_test",
|
||||
"./simple", ".././simple"};
|
||||
const char *absolute_paths[] = {"/", "/test", "/../test/", "/../another_test",
|
||||
"/./simple", "/.././simple"};
|
||||
size_t i;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(relative_paths); ++i) {
|
||||
if (cwk_path_is_absolute(relative_paths[i])) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(absolute_paths); ++i) {
|
||||
if (!cwk_path_is_absolute(absolute_paths[i])) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_too_far()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_get_absolute("/hello/there", "../../../../../", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_normalization()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_get_absolute("/hello//../there", "test//thing", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 17) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/there/test/thing") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_mixed()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_get_absolute("hello/there", "/test", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 5) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_unix_relative_base()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_get_absolute("hello/there", "test", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 17) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/hello/there/test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_windows_relative_base()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_get_absolute("hello\\there", "test", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 17) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "\\hello\\there\\test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_absolute_path()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_get_absolute("/hello/there", "/test", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 5) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_simple()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_get_absolute("/hello/there", "..", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 6) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/hello") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int absolute_buffer_reuse()
|
||||
{
|
||||
char path[FILENAME_MAX];
|
||||
|
||||
memset(path, 1, FILENAME_MAX);
|
||||
path[0] = '\0';
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
cwk_path_get_absolute(path, "/", path, FILENAME_MAX);
|
||||
if (strcmp(path, "/") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cwk_path_get_absolute(path, "see", path, FILENAME_MAX);
|
||||
if (strcmp(path, "/see") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cwk_path_get_absolute(path, "dog", path, FILENAME_MAX);
|
||||
if (strcmp(path, "/see/dog") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cwk_path_get_absolute(path, "..", path, FILENAME_MAX);
|
||||
if (strcmp(path, "/see") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cwk_path_get_absolute(path, "cat", path, FILENAME_MAX);
|
||||
if (strcmp(path, "/see/cat") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
int absolute_check()
|
||||
{
|
||||
const char *relative_paths[] = {"..", "test", "test/test", "../another_test",
|
||||
"./simple", ".././simple"};
|
||||
const char *absolute_paths[] = {"/", "/test", "/../test/", "/../another_test",
|
||||
"/./simple", "/.././simple"};
|
||||
size_t i;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(relative_paths); ++i) {
|
||||
if (cwk_path_is_absolute(relative_paths[i])) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(absolute_paths); ++i) {
|
||||
if (!cwk_path_is_absolute(absolute_paths[i])) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_too_far()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_get_absolute("/hello/there", "../../../../../", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_normalization()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_get_absolute("/hello//../there", "test//thing", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 17) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/there/test/thing") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_mixed()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_get_absolute("hello/there", "/test", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 5) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_unix_relative_base()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_get_absolute("hello/there", "test", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 17) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/hello/there/test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_windows_relative_base()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_get_absolute("hello\\there", "test", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 17) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "\\hello\\there\\test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_absolute_path()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_get_absolute("/hello/there", "/test", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 5) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int absolute_simple()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_get_absolute("/hello/there", "..", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 6) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/hello") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int absolute_buffer_reuse()
|
||||
{
|
||||
char path[FILENAME_MAX];
|
||||
|
||||
memset(path, 1, FILENAME_MAX);
|
||||
path[0] = '\0';
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
cwk_path_get_absolute(path, "/", path, FILENAME_MAX);
|
||||
if (strcmp(path, "/") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cwk_path_get_absolute(path, "see", path, FILENAME_MAX);
|
||||
if (strcmp(path, "/see") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cwk_path_get_absolute(path, "dog", path, FILENAME_MAX);
|
||||
if (strcmp(path, "/see/dog") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cwk_path_get_absolute(path, "..", path, FILENAME_MAX);
|
||||
if (strcmp(path, "/see") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cwk_path_get_absolute(path, "cat", path, FILENAME_MAX);
|
||||
if (strcmp(path, "/see/cat") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+313
-313
@@ -1,313 +1,313 @@
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int basename_change_trim_only_root()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_basename("/", "///another.txt///", buffer,
|
||||
sizeof(buffer));
|
||||
if (n != 12) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/another.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_change_trim()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_basename("/test.txt", "///another.txt///", buffer,
|
||||
sizeof(buffer));
|
||||
if (n != 12) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/another.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_change_relative()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_basename("../test.txt", "another.txt", buffer,
|
||||
sizeof(buffer));
|
||||
if (n != 14) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "../another.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_change_empty_basename()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_basename("C:\\test.txt", "", buffer, sizeof(buffer));
|
||||
if (n != 3) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "C:\\") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_change_only_root()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_basename("C:\\", "another.txt", buffer, sizeof(buffer));
|
||||
if (n != 14) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "C:\\another.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_change_empty_path()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_basename("", "another.txt", buffer, sizeof(buffer));
|
||||
if (n != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "another.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_change_simple()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_basename("C:\\test.txt", "another.txt", buffer,
|
||||
sizeof(buffer));
|
||||
if (n != 14) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "C:\\another.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_windows()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
path = "C:\\path\\test.txt";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(basename, "test.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_root()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (basename != NULL) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_special_directories()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "..";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 2) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(basename, "..", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
path = ".";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(basename, ".", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_no_separators()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "file_name";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 9) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(basename, "file_name", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_trailing_separators()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt////";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(basename, "path.txt", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_trailing_separator()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt/";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(basename, "path.txt", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_empty()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (basename != NULL) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_simple()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(basename, "path.txt", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int basename_change_trim_only_root()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_basename("/", "///another.txt///", buffer,
|
||||
sizeof(buffer));
|
||||
if (n != 12) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/another.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_change_trim()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_basename("/test.txt", "///another.txt///", buffer,
|
||||
sizeof(buffer));
|
||||
if (n != 12) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/another.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_change_relative()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_basename("../test.txt", "another.txt", buffer,
|
||||
sizeof(buffer));
|
||||
if (n != 14) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "../another.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_change_empty_basename()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_basename("C:\\test.txt", "", buffer, sizeof(buffer));
|
||||
if (n != 3) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "C:\\") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_change_only_root()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_basename("C:\\", "another.txt", buffer, sizeof(buffer));
|
||||
if (n != 14) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "C:\\another.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_change_empty_path()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_basename("", "another.txt", buffer, sizeof(buffer));
|
||||
if (n != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "another.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_change_simple()
|
||||
{
|
||||
size_t n;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_basename("C:\\test.txt", "another.txt", buffer,
|
||||
sizeof(buffer));
|
||||
if (n != 14) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "C:\\another.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_windows()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
path = "C:\\path\\test.txt";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(basename, "test.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_root()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (basename != NULL) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_special_directories()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "..";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 2) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(basename, "..", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
path = ".";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(basename, ".", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_no_separators()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "file_name";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 9) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(basename, "file_name", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_trailing_separators()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt////";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(basename, "path.txt", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_trailing_separator()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt/";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(basename, "path.txt", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_empty()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (basename != NULL) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int basename_simple()
|
||||
{
|
||||
const char *path, *basename;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt";
|
||||
cwk_path_get_basename(path, &basename, &length);
|
||||
|
||||
if (length != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(basename, "path.txt", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+154
-154
@@ -1,154 +1,154 @@
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int dirname_relative()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "../one/two.txt";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 7) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_three_segments()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/one/two/three.txt";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 9) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_root()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_special_directories()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "..";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
path = ".";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_no_separators()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "file_name";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_trailing_separators()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt////";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_trailing_separator()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt/";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_empty()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_simple()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int dirname_relative()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "../one/two.txt";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 7) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_three_segments()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/one/two/three.txt";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 9) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_root()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_special_directories()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "..";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
path = ".";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_no_separators()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "file_name";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_trailing_separators()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt////";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_trailing_separator()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt/";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_empty()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int dirname_simple()
|
||||
{
|
||||
const char *path;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt";
|
||||
cwk_path_get_dirname(path, &length);
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+308
-308
@@ -1,308 +1,308 @@
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int extension_change_with_trailing_slash()
|
||||
{
|
||||
char buffer[FILENAME_MAX] = "/folder/file.txt/";
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension(buffer, ".md", buffer, sizeof(buffer));
|
||||
if (n != 16) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/folder/file.md/", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_hidden_file()
|
||||
{
|
||||
char buffer[FILENAME_MAX] = "/folder/.hidden_file.txt";
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension(buffer, ".md", buffer, sizeof(buffer));
|
||||
if (n != 23) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/folder/.hidden_file.md", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_overlap_long()
|
||||
{
|
||||
char buffer[FILENAME_MAX] = "/test.txt/";
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension(buffer, ".text", buffer, sizeof(buffer));
|
||||
if (n != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/test.text/", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_overlap()
|
||||
{
|
||||
char buffer[FILENAME_MAX] = "/test.txt/";
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension(buffer, ".md", buffer, sizeof(buffer));
|
||||
if (n != 9) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/test.md/", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_with_dot()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension("/test.txt", ".md", buffer, sizeof(buffer));
|
||||
if (n != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/test.md", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_remove()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension("/test.txt", "", buffer, sizeof(buffer));
|
||||
if (n != 5) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/test", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_no_extension()
|
||||
{
|
||||
char buffer[FILENAME_MAX] = "C:\\file";
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_extension(buffer, ".md", buffer, sizeof(buffer));
|
||||
if (n != 10) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("C:\\file.md", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_no_basename()
|
||||
{
|
||||
char buffer[FILENAME_MAX] = "C:\\";
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_extension(buffer, ".md", buffer, sizeof(buffer));
|
||||
if (n != 6) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("C:\\.md", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_simple()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension("/test.txt", "md", buffer, sizeof(buffer));
|
||||
if (n != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/test.md", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_check_without()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (cwk_path_has_extension("/my/path")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_check_empty()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (cwk_path_has_extension("")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_check_simple()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (!cwk_path_has_extension("/my/path.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_get_multiple()
|
||||
{
|
||||
const char *path, *extension;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.abc.txt.tests";
|
||||
if (!cwk_path_get_extension(path, &extension, &length)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (length != 6) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(extension, ".tests", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_get_last()
|
||||
{
|
||||
const char *path, *extension;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.";
|
||||
if (!cwk_path_get_extension(path, &extension, &length)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(extension, ".", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_get_first()
|
||||
{
|
||||
const char *path, *extension;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/.path";
|
||||
if (!cwk_path_get_extension(path, &extension, &length)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (length != 5) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(extension, ".path", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_get_without()
|
||||
{
|
||||
const char *path, *extension;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path";
|
||||
if (cwk_path_get_extension(path, &extension, &length)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_get_simple()
|
||||
{
|
||||
const char *path, *extension;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt";
|
||||
if (!cwk_path_get_extension(path, &extension, &length)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(extension, ".txt", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int extension_change_with_trailing_slash()
|
||||
{
|
||||
char buffer[FILENAME_MAX] = "/folder/file.txt/";
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension(buffer, ".md", buffer, sizeof(buffer));
|
||||
if (n != 16) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/folder/file.md/", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_hidden_file()
|
||||
{
|
||||
char buffer[FILENAME_MAX] = "/folder/.hidden_file.txt";
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension(buffer, ".md", buffer, sizeof(buffer));
|
||||
if (n != 23) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/folder/.hidden_file.md", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_overlap_long()
|
||||
{
|
||||
char buffer[FILENAME_MAX] = "/test.txt/";
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension(buffer, ".text", buffer, sizeof(buffer));
|
||||
if (n != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/test.text/", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_overlap()
|
||||
{
|
||||
char buffer[FILENAME_MAX] = "/test.txt/";
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension(buffer, ".md", buffer, sizeof(buffer));
|
||||
if (n != 9) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/test.md/", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_with_dot()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension("/test.txt", ".md", buffer, sizeof(buffer));
|
||||
if (n != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/test.md", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_remove()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension("/test.txt", "", buffer, sizeof(buffer));
|
||||
if (n != 5) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/test", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_no_extension()
|
||||
{
|
||||
char buffer[FILENAME_MAX] = "C:\\file";
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_extension(buffer, ".md", buffer, sizeof(buffer));
|
||||
if (n != 10) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("C:\\file.md", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_no_basename()
|
||||
{
|
||||
char buffer[FILENAME_MAX] = "C:\\";
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
n = cwk_path_change_extension(buffer, ".md", buffer, sizeof(buffer));
|
||||
if (n != 6) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("C:\\.md", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_change_simple()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
n = cwk_path_change_extension("/test.txt", "md", buffer, sizeof(buffer));
|
||||
if (n != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp("/test.md", buffer) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_check_without()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (cwk_path_has_extension("/my/path")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_check_empty()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (cwk_path_has_extension("")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_check_simple()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (!cwk_path_has_extension("/my/path.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_get_multiple()
|
||||
{
|
||||
const char *path, *extension;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.abc.txt.tests";
|
||||
if (!cwk_path_get_extension(path, &extension, &length)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (length != 6) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(extension, ".tests", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_get_last()
|
||||
{
|
||||
const char *path, *extension;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.";
|
||||
if (!cwk_path_get_extension(path, &extension, &length)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(extension, ".", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_get_first()
|
||||
{
|
||||
const char *path, *extension;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/.path";
|
||||
if (!cwk_path_get_extension(path, &extension, &length)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (length != 5) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(extension, ".path", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_get_without()
|
||||
{
|
||||
const char *path, *extension;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path";
|
||||
if (cwk_path_get_extension(path, &extension, &length)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int extension_get_simple()
|
||||
{
|
||||
const char *path, *extension;
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
path = "/my/path.txt";
|
||||
if (!cwk_path_get_extension(path, &extension, &length)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(extension, ".txt", length) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+105
-105
@@ -1,105 +1,105 @@
|
||||
#include <cwalk.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int guess_empty_string()
|
||||
{
|
||||
if (cwk_path_guess_style("") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_unguessable()
|
||||
{
|
||||
if (cwk_path_guess_style("myfile") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_extension()
|
||||
{
|
||||
if (cwk_path_guess_style("myfile.txt") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style("/a/directory/myfile.txt") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_hidden_file()
|
||||
{
|
||||
if (cwk_path_guess_style(".my_hidden_file") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style(".my_hidden_file.txt") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_unix_separator()
|
||||
{
|
||||
if (cwk_path_guess_style("/directory/other") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style("/directory/other.txt") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_windows_separator()
|
||||
{
|
||||
if (cwk_path_guess_style("\\directory\\other") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (cwk_path_guess_style("\\directory\\.other") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_unix_root()
|
||||
{
|
||||
if (cwk_path_guess_style("/directory") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_windows_root()
|
||||
{
|
||||
if (cwk_path_guess_style("C:\\test") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style("C:/test") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style("C:test") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style("C:/.test") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style("C:/folder/.test") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include <cwalk.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int guess_empty_string()
|
||||
{
|
||||
if (cwk_path_guess_style("") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_unguessable()
|
||||
{
|
||||
if (cwk_path_guess_style("myfile") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_extension()
|
||||
{
|
||||
if (cwk_path_guess_style("myfile.txt") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style("/a/directory/myfile.txt") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_hidden_file()
|
||||
{
|
||||
if (cwk_path_guess_style(".my_hidden_file") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style(".my_hidden_file.txt") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_unix_separator()
|
||||
{
|
||||
if (cwk_path_guess_style("/directory/other") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style("/directory/other.txt") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_windows_separator()
|
||||
{
|
||||
if (cwk_path_guess_style("\\directory\\other") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (cwk_path_guess_style("\\directory\\.other") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_unix_root()
|
||||
{
|
||||
if (cwk_path_guess_style("/directory") != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int guess_windows_root()
|
||||
{
|
||||
if (cwk_path_guess_style("C:\\test") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style("C:/test") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style("C:test") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style("C:/.test") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_guess_style("C:/folder/.test") != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+165
-165
@@ -1,165 +1,165 @@
|
||||
#include <cwalk.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int is_absolute_relative_windows()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_absolute("..\\hello\\world.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_relative_drive()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_absolute("C:test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_device_question_mark()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_absolute("\\\\?\\mydevice\\test")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_device_dot()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_is_absolute("\\\\.\\mydevice\\test");
|
||||
|
||||
if (!cwk_path_is_absolute("\\\\.\\mydevice\\test")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_device_unc()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_absolute("\\\\.\\UNC\\LOCALHOST\\c$\\temp\\test-file.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_unc()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_absolute("\\\\server\\folder\\data")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_absolute_drive()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_absolute("C:\\test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_unix_drive()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (cwk_path_is_absolute("C:\\test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_unix_backslash()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (cwk_path_is_absolute("\\folder\\")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_windows_slash()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_absolute("/test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_windows_backslash()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_absolute("\\test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_relative()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (cwk_path_is_absolute("test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_absolute()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (!cwk_path_is_absolute("/test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_root()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (!cwk_path_is_absolute("/")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_dir()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (!cwk_path_is_absolute("/dir")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include <cwalk.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int is_absolute_relative_windows()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_absolute("..\\hello\\world.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_relative_drive()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_absolute("C:test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_device_question_mark()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_absolute("\\\\?\\mydevice\\test")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_device_dot()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_is_absolute("\\\\.\\mydevice\\test");
|
||||
|
||||
if (!cwk_path_is_absolute("\\\\.\\mydevice\\test")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_device_unc()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_absolute("\\\\.\\UNC\\LOCALHOST\\c$\\temp\\test-file.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_unc()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_absolute("\\\\server\\folder\\data")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_absolute_drive()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_absolute("C:\\test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_unix_drive()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (cwk_path_is_absolute("C:\\test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_unix_backslash()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (cwk_path_is_absolute("\\folder\\")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_windows_slash()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_absolute("/test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_windows_backslash()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_absolute("\\test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_relative()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (cwk_path_is_absolute("test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_absolute()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (!cwk_path_is_absolute("/test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_root()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (!cwk_path_is_absolute("/")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_absolute_dir()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (!cwk_path_is_absolute("/dir")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+145
-145
@@ -1,145 +1,145 @@
|
||||
#include <cwalk.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int is_relative_relative_windows()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_relative("..\\hello\\world.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_relative_drive()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_relative("C:test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_device_question_mark()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_relative("\\\\?\\mydevice\\test")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_device_dot()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_is_absolute("\\\\.\\mydevice\\test");
|
||||
|
||||
if (cwk_path_is_relative("\\\\.\\mydevice\\test")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_device_unc()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_relative("\\\\.\\UNC\\LOCALHOST\\c$\\temp\\test-file.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_unc()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_relative("\\\\server\\folder\\data")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_absolute_drive()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_relative("C:\\test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_unix_drive()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (!cwk_path_is_relative("C:\\test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_unix_backslash()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (!cwk_path_is_relative("\\folder\\")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_windows_slash()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_relative("/test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_windows_backslash()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_relative("\\test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_relative()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (!cwk_path_is_relative("test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_absolute()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (cwk_path_is_relative("/test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include <cwalk.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int is_relative_relative_windows()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_relative("..\\hello\\world.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_relative_drive()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (!cwk_path_is_relative("C:test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_device_question_mark()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_relative("\\\\?\\mydevice\\test")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_device_dot()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_is_absolute("\\\\.\\mydevice\\test");
|
||||
|
||||
if (cwk_path_is_relative("\\\\.\\mydevice\\test")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_device_unc()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_relative("\\\\.\\UNC\\LOCALHOST\\c$\\temp\\test-file.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_unc()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_relative("\\\\server\\folder\\data")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_absolute_drive()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_relative("C:\\test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_unix_drive()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (!cwk_path_is_relative("C:\\test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_unix_backslash()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (!cwk_path_is_relative("\\folder\\")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_windows_slash()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_relative("/test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_windows_backslash()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_is_relative("\\test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_relative()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (!cwk_path_is_relative("test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int is_relative_absolute()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (cwk_path_is_relative("/test.txt")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+186
-186
@@ -1,186 +1,186 @@
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int join_multiple()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
const char *paths[3];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
paths[0] = "hello/there";
|
||||
paths[1] = "../world";
|
||||
paths[2] = NULL;
|
||||
|
||||
length = cwk_path_join_multiple(paths, buffer, sizeof(buffer));
|
||||
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "hello/world") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_relative_back_after_root()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_join("this\\", "C:\\..\\..\\is\\a\\test\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 9) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "is\\a\\test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_back_after_root()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_join("C:\\this\\path", "C:\\..\\is\\a\\test\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 22) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "C:\\this\\path\\is\\a\\test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_with_two_roots()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_join("C:\\this\\path", "C:\\is\\a\\test\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 25) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "C:\\this\\path\\C:\\is\\a\\test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_two_unc()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_join("\\\\server\\unc\\path", "\\\\server2\\unc\\path",
|
||||
buffer, sizeof(buffer));
|
||||
|
||||
if (length != 34) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "\\\\server\\unc\\path\\server2\\unc\\path") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_two_absolute()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_join("/first", "/second", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 13) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/first/second") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_empty()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_join("hello", "..", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_navigate_back()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_join("hello/there", "..", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 5) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "hello") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_simple()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_join("hello", "there", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "hello/there") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int join_multiple()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
const char *paths[3];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
paths[0] = "hello/there";
|
||||
paths[1] = "../world";
|
||||
paths[2] = NULL;
|
||||
|
||||
length = cwk_path_join_multiple(paths, buffer, sizeof(buffer));
|
||||
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "hello/world") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_relative_back_after_root()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_join("this\\", "C:\\..\\..\\is\\a\\test\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 9) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "is\\a\\test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_back_after_root()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_join("C:\\this\\path", "C:\\..\\is\\a\\test\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 22) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "C:\\this\\path\\is\\a\\test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_with_two_roots()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_join("C:\\this\\path", "C:\\is\\a\\test\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 25) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "C:\\this\\path\\C:\\is\\a\\test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_two_unc()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_join("\\\\server\\unc\\path", "\\\\server2\\unc\\path",
|
||||
buffer, sizeof(buffer));
|
||||
|
||||
if (length != 34) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "\\\\server\\unc\\path\\server2\\unc\\path") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_two_absolute()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_join("/first", "/second", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 13) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "/first/second") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_empty()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_join("hello", "..", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_navigate_back()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_join("hello/there", "..", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 5) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "hello") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_simple()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
length = cwk_path_join("hello", "there", buffer, sizeof(buffer));
|
||||
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "hello/there") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+113
-113
@@ -1,113 +1,113 @@
|
||||
#include "tests.h"
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* This is just a small macro which calculates the size of an array.
|
||||
*/
|
||||
#define CWK_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
struct cwk_test
|
||||
{
|
||||
const char *unit_name;
|
||||
const char *test_name;
|
||||
const char *full_name;
|
||||
int (*fn)(void);
|
||||
};
|
||||
|
||||
#define XX(u, t) extern int u##_##t(void);
|
||||
UNIT_TESTS(XX)
|
||||
#undef XX
|
||||
|
||||
static struct cwk_test tests[] = {
|
||||
#define XX(u, t) \
|
||||
{.unit_name = #u, .test_name = #t, .full_name = #u "/" #t, .fn = u##_##t},
|
||||
UNIT_TESTS(XX)
|
||||
#undef XX
|
||||
};
|
||||
|
||||
static int call_test(struct cwk_test *test)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
printf(" Running '%s' ", test->full_name);
|
||||
for (i = strlen(test->full_name); i < 45; ++i) {
|
||||
fputs(".", stdout);
|
||||
}
|
||||
|
||||
if (test->fn() == EXIT_FAILURE) {
|
||||
fputs(" FAILURE\n", stdout);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fputs(" SUCCESS\n", stdout);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
size_t i, count, failed, succeeded;
|
||||
const char *requested_unit_name, *requested_test_name;
|
||||
struct cwk_test *test;
|
||||
double rate;
|
||||
|
||||
count = 0;
|
||||
failed = 0;
|
||||
if (argc < 2) {
|
||||
fputs("No unit specified. Running all tests.\n\n", stdout);
|
||||
for (i = 0; i < CWK_ARRAY_SIZE(tests); ++i) {
|
||||
test = &tests[i];
|
||||
++count;
|
||||
if (call_test(test) == EXIT_FAILURE) {
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
} else if (argc < 3) {
|
||||
requested_unit_name = argv[1];
|
||||
printf("Running all unit tests of '%s'.\n\n", requested_unit_name);
|
||||
for (i = 0; i < CWK_ARRAY_SIZE(tests); ++i) {
|
||||
test = &tests[i];
|
||||
if (strcmp(test->unit_name, requested_unit_name) == 0) {
|
||||
++count;
|
||||
if (call_test(test) == EXIT_FAILURE) {
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
requested_unit_name = argv[1];
|
||||
requested_test_name = argv[2];
|
||||
printf("Running a single test '%s/%s'.\n\n", requested_unit_name,
|
||||
requested_test_name);
|
||||
for (i = 0; i < CWK_ARRAY_SIZE(tests); ++i) {
|
||||
test = &tests[i];
|
||||
if (strcmp(test->unit_name, requested_unit_name) == 0 &&
|
||||
strcmp(test->test_name, requested_test_name) == 0) {
|
||||
++count;
|
||||
if (call_test(test) == EXIT_FAILURE) {
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 1) {
|
||||
fputs("\nThe test has been executed.\n", stdout);
|
||||
} else if (count > 0) {
|
||||
succeeded = count - failed;
|
||||
rate = (double)succeeded / (double)count * 100;
|
||||
printf("\n%zu/%zu (%.2f%%) of those tests succeeded.\n", succeeded, count,
|
||||
rate);
|
||||
} else {
|
||||
printf("\nNo tests found.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (failed > 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include "tests.h"
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* This is just a small macro which calculates the size of an array.
|
||||
*/
|
||||
#define CWK_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
struct cwk_test
|
||||
{
|
||||
const char *unit_name;
|
||||
const char *test_name;
|
||||
const char *full_name;
|
||||
int (*fn)(void);
|
||||
};
|
||||
|
||||
#define XX(u, t) extern int u##_##t(void);
|
||||
UNIT_TESTS(XX)
|
||||
#undef XX
|
||||
|
||||
static struct cwk_test tests[] = {
|
||||
#define XX(u, t) \
|
||||
{.unit_name = #u, .test_name = #t, .full_name = #u "/" #t, .fn = u##_##t},
|
||||
UNIT_TESTS(XX)
|
||||
#undef XX
|
||||
};
|
||||
|
||||
static int call_test(struct cwk_test *test)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
printf(" Running '%s' ", test->full_name);
|
||||
for (i = strlen(test->full_name); i < 45; ++i) {
|
||||
fputs(".", stdout);
|
||||
}
|
||||
|
||||
if (test->fn() == EXIT_FAILURE) {
|
||||
fputs(" FAILURE\n", stdout);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fputs(" SUCCESS\n", stdout);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
size_t i, count, failed, succeeded;
|
||||
const char *requested_unit_name, *requested_test_name;
|
||||
struct cwk_test *test;
|
||||
double rate;
|
||||
|
||||
count = 0;
|
||||
failed = 0;
|
||||
if (argc < 2) {
|
||||
fputs("No unit specified. Running all tests.\n\n", stdout);
|
||||
for (i = 0; i < CWK_ARRAY_SIZE(tests); ++i) {
|
||||
test = &tests[i];
|
||||
++count;
|
||||
if (call_test(test) == EXIT_FAILURE) {
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
} else if (argc < 3) {
|
||||
requested_unit_name = argv[1];
|
||||
printf("Running all unit tests of '%s'.\n\n", requested_unit_name);
|
||||
for (i = 0; i < CWK_ARRAY_SIZE(tests); ++i) {
|
||||
test = &tests[i];
|
||||
if (strcmp(test->unit_name, requested_unit_name) == 0) {
|
||||
++count;
|
||||
if (call_test(test) == EXIT_FAILURE) {
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
requested_unit_name = argv[1];
|
||||
requested_test_name = argv[2];
|
||||
printf("Running a single test '%s/%s'.\n\n", requested_unit_name,
|
||||
requested_test_name);
|
||||
for (i = 0; i < CWK_ARRAY_SIZE(tests); ++i) {
|
||||
test = &tests[i];
|
||||
if (strcmp(test->unit_name, requested_unit_name) == 0 &&
|
||||
strcmp(test->test_name, requested_test_name) == 0) {
|
||||
++count;
|
||||
if (call_test(test) == EXIT_FAILURE) {
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 1) {
|
||||
fputs("\nThe test has been executed.\n", stdout);
|
||||
} else if (count > 0) {
|
||||
succeeded = count - failed;
|
||||
rate = (double)succeeded / (double)count * 100;
|
||||
printf("\n%zu/%zu (%.2f%%) of those tests succeeded.\n", succeeded, count,
|
||||
rate);
|
||||
} else {
|
||||
printf("\nNo tests found.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (failed > 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+261
-261
@@ -1,261 +1,261 @@
|
||||
#include <cwalk.h>
|
||||
#include <limits.h>
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int normalize_forward_slashes()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
input = "C:/this/is/a/test/path";
|
||||
strcpy(result, input);
|
||||
expected = "C:\\this\\is\\a\\test\\path";
|
||||
count = cwk_path_normalize(result, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_back_after_root()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
input = "C:\\..\\this\\is\\a\\test\\path";
|
||||
strcpy(result, input);
|
||||
expected = "C:\\this\\is\\a\\test\\path";
|
||||
count = cwk_path_normalize(result, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_only_separators()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "////";
|
||||
strcpy(result, input);
|
||||
expected = "/";
|
||||
count = cwk_path_normalize(result, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_empty()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "test/..";
|
||||
strcpy(result, input);
|
||||
expected = ".";
|
||||
count = cwk_path_normalize(result, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_overlap()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var/./logs/.//test/..//..//////";
|
||||
strcpy(result, input);
|
||||
expected = "/var";
|
||||
count = cwk_path_normalize(result, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_mixed()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var/./logs/.//test/..//..//////";
|
||||
expected = "/var";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_remove_current()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var/././././";
|
||||
expected = "/var";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_double_separator()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var////logs//test/";
|
||||
expected = "/var/logs/test";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_terminated()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
size_t i, expected_size, n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var/logs/test/../../";
|
||||
expected = "/var";
|
||||
expected_size = strlen(expected);
|
||||
|
||||
memset(result, 1, sizeof(result));
|
||||
|
||||
for (i = 0; i < 7; ++i) {
|
||||
count = cwk_path_normalize(input, result, i);
|
||||
|
||||
if (i != 0 && expected_size < i) {
|
||||
n = expected_size;
|
||||
} else {
|
||||
n = i - 1;
|
||||
}
|
||||
|
||||
if (count != strlen(expected) ||
|
||||
(i > 0 && (strncmp(result, expected, n) != 0 || result[n] != '\0'))) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_relative_too_far()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "rel/../../";
|
||||
expected = "..";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_absolute_too_far()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var/logs/test/../../../../../../";
|
||||
expected = "/";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_navigate_back()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var/logs/test/../../";
|
||||
expected = "/var";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_do_nothing()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var";
|
||||
expected = "/var";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include <cwalk.h>
|
||||
#include <limits.h>
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int normalize_forward_slashes()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
input = "C:/this/is/a/test/path";
|
||||
strcpy(result, input);
|
||||
expected = "C:\\this\\is\\a\\test\\path";
|
||||
count = cwk_path_normalize(result, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_back_after_root()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
input = "C:\\..\\this\\is\\a\\test\\path";
|
||||
strcpy(result, input);
|
||||
expected = "C:\\this\\is\\a\\test\\path";
|
||||
count = cwk_path_normalize(result, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_only_separators()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "////";
|
||||
strcpy(result, input);
|
||||
expected = "/";
|
||||
count = cwk_path_normalize(result, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_empty()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "test/..";
|
||||
strcpy(result, input);
|
||||
expected = ".";
|
||||
count = cwk_path_normalize(result, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_overlap()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var/./logs/.//test/..//..//////";
|
||||
strcpy(result, input);
|
||||
expected = "/var";
|
||||
count = cwk_path_normalize(result, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_mixed()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var/./logs/.//test/..//..//////";
|
||||
expected = "/var";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_remove_current()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var/././././";
|
||||
expected = "/var";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_double_separator()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var////logs//test/";
|
||||
expected = "/var/logs/test";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_terminated()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
size_t i, expected_size, n;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var/logs/test/../../";
|
||||
expected = "/var";
|
||||
expected_size = strlen(expected);
|
||||
|
||||
memset(result, 1, sizeof(result));
|
||||
|
||||
for (i = 0; i < 7; ++i) {
|
||||
count = cwk_path_normalize(input, result, i);
|
||||
|
||||
if (i != 0 && expected_size < i) {
|
||||
n = expected_size;
|
||||
} else {
|
||||
n = i - 1;
|
||||
}
|
||||
|
||||
if (count != strlen(expected) ||
|
||||
(i > 0 && (strncmp(result, expected, n) != 0 || result[n] != '\0'))) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_relative_too_far()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "rel/../../";
|
||||
expected = "..";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_absolute_too_far()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var/logs/test/../../../../../../";
|
||||
expected = "/";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_navigate_back()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var/logs/test/../../";
|
||||
expected = "/var";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_do_nothing()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
input = "/var";
|
||||
expected = "/var";
|
||||
count = cwk_path_normalize(input, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+356
-356
@@ -1,356 +1,356 @@
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
int relative_root_forward_slashes()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
length = cwk_path_get_relative("C:\\foo\\bar\\baz\\", "C:/foo/bar/file.txt",
|
||||
result, sizeof(result));
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "..\\file.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_root_path_windows()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
length = cwk_path_get_relative("C:\\this\\is\\path_one", "C:\\", result,
|
||||
sizeof(result));
|
||||
if (length != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "..\\..\\..") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_root_path_unix()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/this/is/path_one", "/", result,
|
||||
sizeof(result));
|
||||
if (length != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../../..") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_check()
|
||||
{
|
||||
const char *relative_paths[] = {"..", "test", "test/test", "../another_test",
|
||||
"./simple", ".././simple"};
|
||||
const char *absolute_paths[] = {"/", "/test", "/../test/", "/../another_test",
|
||||
"/./simple", "/.././simple"};
|
||||
size_t i;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(relative_paths); ++i) {
|
||||
if (!cwk_path_is_relative(relative_paths[i])) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(absolute_paths); ++i) {
|
||||
if (cwk_path_is_relative(absolute_paths[i])) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_relative_and_absolute()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
*result = 1;
|
||||
|
||||
length = cwk_path_get_relative("./foo", "/bar", result, sizeof(result));
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (*result != '\0') {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_different_roots()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
*result = 1;
|
||||
|
||||
length = cwk_path_get_relative("C:/path/same", "D:/path/same", result,
|
||||
sizeof(result));
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (*result != '\0') {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_skip_all()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/../../", "/../../", result, sizeof(result));
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_target_div_skipped_end()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/same", "/path/not_same/ho/..", result,
|
||||
sizeof(result));
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../not_same") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_base_div_skipped_end()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/not_same/ho/..", "/path/same", result,
|
||||
sizeof(result));
|
||||
if (length != 7) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../same") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_target_skipped_end()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/same", "/path/same/ho/..", result,
|
||||
sizeof(result));
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_base_skipped_end()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/same/ho/..", "/path/same", result,
|
||||
sizeof(result));
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_equal()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/same", "/path/same", result,
|
||||
sizeof(result));
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_same_base()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/dir/dir", "/dir/dir3/file", result,
|
||||
sizeof(result));
|
||||
if (length != 12) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../dir3/file") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_long_target()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/long/one", "/path/long/one/two", result,
|
||||
sizeof(result));
|
||||
if (length != 3) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "two") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_long_base()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/long/one/two", "/path/long/one", result,
|
||||
sizeof(result));
|
||||
if (length != 2) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "..") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_relative()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("./this/is/path_one", "./this/is/path_two",
|
||||
result, sizeof(result));
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../path_two") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_simple()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/this/is/path_one", "/this/is/path_two",
|
||||
result, sizeof(result));
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../path_two") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
int relative_root_forward_slashes()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
length = cwk_path_get_relative("C:\\foo\\bar\\baz\\", "C:/foo/bar/file.txt",
|
||||
result, sizeof(result));
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "..\\file.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_root_path_windows()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
length = cwk_path_get_relative("C:\\this\\is\\path_one", "C:\\", result,
|
||||
sizeof(result));
|
||||
if (length != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "..\\..\\..") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_root_path_unix()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/this/is/path_one", "/", result,
|
||||
sizeof(result));
|
||||
if (length != 8) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../../..") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_check()
|
||||
{
|
||||
const char *relative_paths[] = {"..", "test", "test/test", "../another_test",
|
||||
"./simple", ".././simple"};
|
||||
const char *absolute_paths[] = {"/", "/test", "/../test/", "/../another_test",
|
||||
"/./simple", "/.././simple"};
|
||||
size_t i;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(relative_paths); ++i) {
|
||||
if (!cwk_path_is_relative(relative_paths[i])) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(absolute_paths); ++i) {
|
||||
if (cwk_path_is_relative(absolute_paths[i])) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_relative_and_absolute()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
*result = 1;
|
||||
|
||||
length = cwk_path_get_relative("./foo", "/bar", result, sizeof(result));
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (*result != '\0') {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_different_roots()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
*result = 1;
|
||||
|
||||
length = cwk_path_get_relative("C:/path/same", "D:/path/same", result,
|
||||
sizeof(result));
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (*result != '\0') {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_skip_all()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/../../", "/../../", result, sizeof(result));
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_target_div_skipped_end()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/same", "/path/not_same/ho/..", result,
|
||||
sizeof(result));
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../not_same") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_base_div_skipped_end()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/not_same/ho/..", "/path/same", result,
|
||||
sizeof(result));
|
||||
if (length != 7) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../same") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_target_skipped_end()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/same", "/path/same/ho/..", result,
|
||||
sizeof(result));
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_base_skipped_end()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/same/ho/..", "/path/same", result,
|
||||
sizeof(result));
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_equal()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/same", "/path/same", result,
|
||||
sizeof(result));
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_same_base()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/dir/dir", "/dir/dir3/file", result,
|
||||
sizeof(result));
|
||||
if (length != 12) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../dir3/file") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_long_target()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/long/one", "/path/long/one/two", result,
|
||||
sizeof(result));
|
||||
if (length != 3) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "two") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_long_base()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/long/one/two", "/path/long/one", result,
|
||||
sizeof(result));
|
||||
if (length != 2) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "..") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_relative()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("./this/is/path_one", "./this/is/path_two",
|
||||
result, sizeof(result));
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../path_two") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_simple()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/this/is/path_one", "/this/is/path_two",
|
||||
result, sizeof(result));
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../path_two") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+287
-287
@@ -1,287 +1,287 @@
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int root_change_without_root()
|
||||
{
|
||||
size_t length;
|
||||
char buffer[FILENAME_MAX] = "hello\\world.txt";
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_change_root(buffer, "D:\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 18) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "D:\\hello\\world.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_change_overlapping()
|
||||
{
|
||||
size_t length;
|
||||
char buffer[FILENAME_MAX] = "C:\\hello\\world.txt";
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_change_root(buffer, "D:\\path\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 23) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "D:\\path\\hello\\world.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_change_separators()
|
||||
{
|
||||
size_t length;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_change_root("C:\\hello\\world.txt", "D:\\path\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 23) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "D:\\path\\hello\\world.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_change_empty()
|
||||
{
|
||||
size_t length;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_change_root("C:\\hello\\world.txt", "", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 15) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "hello\\world.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_change_simple()
|
||||
{
|
||||
size_t length;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_change_root("C:\\hello\\world.txt", "D:\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 18) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "D:\\hello\\world.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_relative_windows()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("..\\hello\\world.txt", &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_relative_drive()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("C:test.txt", &length);
|
||||
|
||||
if (length != 2) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_device_question_mark()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("\\\\?\\mydevice\\test", &length);
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_device_dot()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("\\\\.\\mydevice\\test", &length);
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_device_unc()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("\\\\.\\UNC\\LOCALHOST\\c$\\temp\\test-file.txt", &length);
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_unc()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("\\\\server\\folder\\data", &length);
|
||||
|
||||
if (length != 16) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_absolute_drive()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("C:\\test.txt", &length);
|
||||
|
||||
if (length != 3) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_unix_drive()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
cwk_path_get_root("C:\\test.txt", &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_unix_backslash()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
cwk_path_get_root("\\folder\\", &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_windows_slash()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("/test.txt", &length);
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_windows_backslash()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("\\test.txt", &length);
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_relative()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
cwk_path_get_root("test.txt", &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_absolute()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
cwk_path_get_root("/test.txt", &length);
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int root_change_without_root()
|
||||
{
|
||||
size_t length;
|
||||
char buffer[FILENAME_MAX] = "hello\\world.txt";
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_change_root(buffer, "D:\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 18) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "D:\\hello\\world.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_change_overlapping()
|
||||
{
|
||||
size_t length;
|
||||
char buffer[FILENAME_MAX] = "C:\\hello\\world.txt";
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_change_root(buffer, "D:\\path\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 23) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "D:\\path\\hello\\world.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_change_separators()
|
||||
{
|
||||
size_t length;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_change_root("C:\\hello\\world.txt", "D:\\path\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 23) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "D:\\path\\hello\\world.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_change_empty()
|
||||
{
|
||||
size_t length;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_change_root("C:\\hello\\world.txt", "", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 15) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "hello\\world.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_change_simple()
|
||||
{
|
||||
size_t length;
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_change_root("C:\\hello\\world.txt", "D:\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 18) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "D:\\hello\\world.txt") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_relative_windows()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("..\\hello\\world.txt", &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_relative_drive()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("C:test.txt", &length);
|
||||
|
||||
if (length != 2) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_device_question_mark()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("\\\\?\\mydevice\\test", &length);
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_device_dot()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("\\\\.\\mydevice\\test", &length);
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_device_unc()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("\\\\.\\UNC\\LOCALHOST\\c$\\temp\\test-file.txt", &length);
|
||||
|
||||
if (length != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_unc()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("\\\\server\\folder\\data", &length);
|
||||
|
||||
if (length != 16) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_absolute_drive()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("C:\\test.txt", &length);
|
||||
|
||||
if (length != 3) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_unix_drive()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
cwk_path_get_root("C:\\test.txt", &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_unix_backslash()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
cwk_path_get_root("\\folder\\", &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_windows_slash()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("/test.txt", &length);
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_windows_backslash()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("\\test.txt", &length);
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_relative()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
cwk_path_get_root("test.txt", &length);
|
||||
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int root_absolute()
|
||||
{
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
cwk_path_get_root("/test.txt", &length);
|
||||
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+690
-690
File diff suppressed because it is too large.
Load diff
+116
-116
@@ -1,116 +1,116 @@
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int windows_root_empty()
|
||||
{
|
||||
size_t size;
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
cwk_path_get_root("", &size);
|
||||
if (size != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_root_backslash()
|
||||
{
|
||||
size_t size;
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
cwk_path_get_root("\\no_network_path\\hello", &size);
|
||||
if (size != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_intersection_case()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_get_intersection("C:\\MYFOLDER\\MYILE.TXT",
|
||||
"c:\\myfolder\\myile.txt") != 21) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_get_root_relative()
|
||||
{
|
||||
size_t size;
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("C:file.txt", &size);
|
||||
|
||||
if (size != 2) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_get_root_separator()
|
||||
{
|
||||
size_t size;
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("C:/this/is/a/test", &size);
|
||||
|
||||
if (size != 3) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_get_unc_root()
|
||||
{
|
||||
size_t size;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("\\\\server\\share\\test.txt", &size);
|
||||
|
||||
if (size != 15) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_get_root()
|
||||
{
|
||||
size_t size;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("C:\\test.txt", &size);
|
||||
|
||||
if (size != 3) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_change_style()
|
||||
{
|
||||
enum cwk_path_style style;
|
||||
|
||||
style = cwk_path_get_style();
|
||||
if (style == CWK_STYLE_WINDOWS) {
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (cwk_path_get_style() != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
} else {
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
if (cwk_path_get_style() != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int windows_root_empty()
|
||||
{
|
||||
size_t size;
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
cwk_path_get_root("", &size);
|
||||
if (size != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_root_backslash()
|
||||
{
|
||||
size_t size;
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
cwk_path_get_root("\\no_network_path\\hello", &size);
|
||||
if (size != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_intersection_case()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
if (cwk_path_get_intersection("C:\\MYFOLDER\\MYILE.TXT",
|
||||
"c:\\myfolder\\myile.txt") != 21) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_get_root_relative()
|
||||
{
|
||||
size_t size;
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("C:file.txt", &size);
|
||||
|
||||
if (size != 2) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_get_root_separator()
|
||||
{
|
||||
size_t size;
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("C:/this/is/a/test", &size);
|
||||
|
||||
if (size != 3) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_get_unc_root()
|
||||
{
|
||||
size_t size;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("\\\\server\\share\\test.txt", &size);
|
||||
|
||||
if (size != 15) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_get_root()
|
||||
{
|
||||
size_t size;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
cwk_path_get_root("C:\\test.txt", &size);
|
||||
|
||||
if (size != 3) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_change_style()
|
||||
{
|
||||
enum cwk_path_style style;
|
||||
|
||||
style = cwk_path_get_style();
|
||||
if (style == CWK_STYLE_WINDOWS) {
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
if (cwk_path_get_style() != CWK_STYLE_UNIX) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
} else {
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
if (cwk_path_get_style() != CWK_STYLE_WINDOWS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in new issue
Block a user