61 Commits
Author SHA1 Message Date
akallabeth e98d23f688 fix invalid doxygen param 2024-11-07 14:47:13 +01:00
Antonio Vázquez Blanco 852763951c meson: Fix symbol exporting 2024-05-06 11:35:58 +02:00
Leonard Iklé f418404bf3 better documentation of the return value in the normalize function #45 2024-02-07 20:06:05 +01:00
Leonard Iklé 982e86076e added pkgconfig for meson 2024-02-03 10:34:29 +01:00
Leonard Iklé f45a23a13a prepare for v1.2.9 2024-02-03 10:07:16 +01:00
Foxie Flakey 35ee006d19 Fix "${includedir}" does not refer to any variable
The cflags in pkgconfig file is invalid as "${includedir}" expands to nothing so it becomes a bare "-I"
2024-02-03 09:34:19 +01:00
Leonard Iklé 88c9c59586 prepare for release of v1.2.8 2024-02-02 12:50:10 +01:00
Leonard Iklé 8c1129e43f updated copyright in LICENSE 2024-02-02 12:42:58 +01:00
Leonard Iklé 0b018eb5b9 updated README and deleted old build files 2024-02-02 12:38:28 +01:00
Leonard Iklé ef41c4e294 added void to parameterless test functions 2024-02-02 12:38:28 +01:00
Leonard Iklé e5e02d6f3f changed README to use github workflows 2024-02-02 12:38:28 +01:00
Leonard Iklé e427287f9e added github workflows 2024-02-02 12:11:19 +01:00
Leonard Iklé cfe8282fce converted line endings to unix 2023-05-08 09:35:38 +02:00
Davide Beatrici 2434a7a719 CMake: Rely on GNUInstallDirs for installation directories
https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
2023-05-07 11:05:12 +02:00
Leonard Iklé 20226de310 fixed travis badge 2023-04-08 10:15:16 +02:00
Leonard Iklé b52d0fc520 added pkg config file 2023-01-26 16:01:32 +01:00
Jules Laffitte 6d2ba296a4 integrates cwalktest with meson build system
* adds `ENABLE_TESTS` option to meson project
* adds conditional compilation of `cwalktest` executable
* registers `cwalktest` test with meson project
2023-01-17 13:22:22 +01:00
Jules Laffitte 44a201c772 fixes meson build warnings
* moves version string to file.
* bumps meson version to >=0.57.0.
* adds version to meson project call.
2023-01-17 13:20:52 +01:00
Leonard Iklé d92d846d05 removed lgtm badge 2023-01-01 10:58:15 +01:00
Andre Smit 9849af4bd0 fix reference in cwk_path_join doc 2022-12-06 22:46:01 +01:00
Leonard Iklé 08e7520d33 fixing #29 windows path root separator normalization 2022-05-29 16:34:13 +02:00
jwerle 0d22f4fb1f chore(clib.json): make clib friendly 2022-04-07 09:03:46 +02:00
Vesper 3aa1e36aa4 Made length parameter optional for cwk_path_get_basename() 2022-02-09 18:10:06 +01:00
Leonard Iklé 6a7c37d41b added ENABLE_TESTS flag to documentation 2021-09-27 10:59:55 +02:00
Leonard Iklé 3583a61007 added missing semicolon in docs 2021-09-27 10:34:51 +02:00
Leonard Iklé 28ab154bae added two simple tests 2021-09-27 10:34:02 +02:00
Leonard Iklé 6de23d70c1 #23 fixing string comparing for unequal lengths 2021-09-02 10:45:24 +02:00
falsycat 39b5a5d80c added new build option, IGNORE_WARNINGS 2021-06-07 20:04:57 +02:00
Leonard Iklé d418a2e007 trigger the build 2021-01-18 22:32:48 +01:00
Leonard Iklé ddb4388423 removed variable initialization 2021-01-18 22:00:16 +01:00
Leonard Iklé d9f7d9424f removed unnecessary assignment statement 2021-01-18 21:55:14 +01:00
Leonard Iklé 7fcc790081 fixed link in docs 2021-01-01 10:26:58 +01:00
Leonard Iklé 2ffcab76b7 updated version in cmake file 2020-11-26 14:00:36 +01:00
Leonard Iklé fba6b24c51 updated changelog for cwk_path_get_relative 2020-11-26 13:28:19 +01:00
Leonard Iklé 795a5d9d18 #17 fixed cwk_path_get_relative with relative base 2020-11-26 11:41:00 +01:00
Leonard Iklé 82eaf2ad3e #17 improved behaviour for relative path generation with unequal roots 2020-11-26 11:26:39 +01:00
Leonard Iklé c5addcfc44 #17 fixed relative path generation with root path 2020-11-26 11:13:34 +01:00
Leonard Iklé 2ca7464c89 removed cwalktest file from root 2020-10-16 14:11:27 +02:00
Leonard Iklé 30da9d275b fixed test generation 2020-10-11 22:36:12 +02:00
likle a9c62cc6ae removed unused cmake variables 2020-10-11 22:05:02 +02:00
Leonard Iklé e3fd66801e added cmake config and target exports 2020-10-11 22:03:42 +02:00
Leonard Iklé fb0f22423d added conditional tests, shared library exports and cmake install instructions 2020-10-11 16:21:52 +02:00
Leonard Iklé 41c48b931b retrigger checks 2020-10-05 16:45:47 +02:00
Leonard Iklé abba46fc46 updated documentation log 2020-10-05 16:20:51 +02:00
Leonard Iklé 1dac5f18c1 fixed cwk_path_get_absolute with a relative base path for windows 2020-10-02 18:15:01 +02:00
Ilya Pavlov ff447b560e fix_typo 2020-09-04 12:01:29 +02:00
Leonard Iklé 276bda40db small correction in cwk_path_get_previous_segment 2020-09-03 19:57:09 +02:00
Ilya Pavlov 58f8522c91 fixed getting first segment 2020-09-03 19:37:22 +02:00
Leonard Iklé 22be3dcbc9 fixed change log of cwk_path_get_absolute 2020-08-10 23:05:49 +02:00
Leonard Iklé d2e520ca36 added memset to improve test quality 2020-08-09 23:56:21 +02:00
Leonard Iklé f01023f7b1 removed unused PATH_SIZE macro 2020-08-09 23:24:24 +02:00
Leonard Iklé 7c3d2f96f6 using EXIT_SUCCESS instead of zero and fixed a comment 2020-08-09 23:20:52 +02:00
Leonard Iklé f395287a41 #11 fixed absolute path generation when reusing buffers 2020-08-09 23:14:37 +02:00
Leonard Iklé 75f00be40b fixed docs background color 2020-08-01 15:31:45 +02:00
Leonard Iklé 2c11193603 updated css version in url 2020-08-01 15:30:11 +02:00
Leonard Iklé b57eca8d28 fixed height of body and html in docs 2020-08-01 15:28:22 +02:00
Leonard Iklé 611b14385a fixed typo, docs on large displays and changed travis to bionic dist 2020-08-01 15:21:16 +02:00
Leonard Iklé d3bd7d2a0f added new lines at end of test files 2020-07-12 23:25:10 +02:00
Leonard Iklé b5fb38360f fixed build on windows 2020-07-12 23:16:09 +02:00
Leonard Iklé edbb9b8b0e enabled warnings for test target 2020-07-12 23:05:21 +02:00
Michael Fitzmayer 8e44a30682 Fix 'implicit conversion changes signedness: long long to size_t' warnings which are shown when -Wsign-conversion is enabled 2020-07-12 22:39:01 +02:00
54 changed files with 6592 additions and 5945 deletions

No files matched your search

-29
View File
@@ -1,29 +0,0 @@
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 .. -G %GENERATOR%
build:
project: c:\projects\cwalk\build.win\cwalk.sln
verbosity: minimal
test_script:
- cmd: c:\projects\cwalk\build.win\Release\cwalktest.exe
+17 -29
View File
@@ -1,29 +1,17 @@
---
BasedOnStyle: LLVM
AlignAfterOpenBracket: DontAlign
BinPackArguments: 'true'
BinPackParameters: 'true'
BreakBeforeBraces: Mozilla
IndentWidth: '2'
ContinuationIndentWidth: '2'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AllowShortBlocksOnASingleLine: 'false'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: 'false'
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
PenaltyBreakAssignment: 10000
PenaltyBreakBeforeFirstCallParameter: 100000
BreakBeforeBraces: Custom
BraceWrapping:
AfterControlStatement: false
AfterEnum: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
AfterFunction: true
IndentBraces: false
BeforeElse: false
SplitEmptyFunction: true
SplitEmptyRecord: true
---
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
View File
@@ -1,2 +1,2 @@
ignore:
ignore:
- "test"
+22
View File
@@ -0,0 +1,22 @@
name: Build on FreeBSD
on:
push:
branches: [ "**" ]
pull_request:
branches: [ "**" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: build
id: test
uses: vmactions/freebsd-vm@v1
with:
usesh: true
prepare: |
pkg install -y cmake
run: |
cmake -B build -S ${{github.workspace}} -DENABLE_TESTS=1
cmake --build build
ctest --test-dir build
+42
View File
@@ -0,0 +1,42 @@
name: Build on Linux
on:
push:
branches: [ "**" ]
pull_request:
branches: [ "**" ]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, ubuntu-20.04]
build_type: [Release]
c_compiler: [gcc, clang]
sanitizers: [address, OFF]
steps:
- uses: actions/checkout@v3
- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Configure CMake
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DENABLE_TESTS=1
-DENABLE_COVERAGE=1
-DENABLE_SANITIZER=${{ matrix.sanitizers }}
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }}
- name: Coverage
if: ${{ matrix.c_compiler == 'gcc' && matrix.sanitizers == 'OFF' }}
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: bash <(curl -s https://codecov.io/bash)
+35
View File
@@ -0,0 +1,35 @@
name: Build on macOS
on:
push:
branches: [ "**" ]
pull_request:
branches: [ "**" ]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-12, macos-11]
build_type: [Release]
c_compiler: [gcc, clang]
steps:
- uses: actions/checkout@v3
- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Configure CMake
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DENABLE_TESTS=1
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }}
+36
View File
@@ -0,0 +1,36 @@
name: Build on Windows
on:
push:
branches: [ "**" ]
pull_request:
branches: [ "**" ]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-2019, windows-2022]
build_type: [Release]
c_compiler: [cl]
steps:
- uses: actions/checkout@v3
- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Configure CMake
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_C_FLAGS=/wd5105
-DENABLE_TESTS=1
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }}
+2 -1
View File
@@ -8,4 +8,5 @@ build.win
builddir
.vs
.vscode
docs/_site
docs/_site
docs/.jekyll-cache
-31
View File
@@ -1,31 +0,0 @@
language: c
os:
- linux
- osx
dist: trusty
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-7
- cmake
compiler:
- gcc
- clang
before_script:
- mkdir build
- cd build
- cmake -DENABLE_COVERAGE=1 ..
script:
- make
- make test
after_success:
- bash <(curl -s https://codecov.io/bash)
+285 -236
View File
@@ -1,236 +1,285 @@
cmake_minimum_required(VERSION 3.9.2)
# set project name
project(cwalk
DESCRIPTION "A simple path library"
LANGUAGES C)
# include utilities
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(EnableWarnings)
include(CTest)
include(CreateTestList)
# configure requirements
set(CMAKE_C_STANDARD 11)
# setup target and directory names
set(LIBRARY_TARGET "cwalk")
set(TEST_TARGET "cwalktest")
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(${LIBRARY_TARGET}
"${INCLUDE_DIRECTORY}/cwalk.h"
"${SOURCE_DIRECTORY}/cwalk.c")
target_include_directories(${LIBRARY_TARGET} PUBLIC "${INCLUDE_DIRECTORY}")
# add tests
enable_testing()
create_test(DEFAULT absolute simple)
create_test(DEFAULT absolute absolute_path)
create_test(DEFAULT absolute 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 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_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 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 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 check)
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_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)
create_test_list(DEFAULT "${TEST_DIRECTORY}/tests.h")
add_executable(${TEST_TARGET}
"${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")
target_link_libraries(${TEST_TARGET} PUBLIC ${LIBRARY_TARGET})
target_include_directories(${TEST_TARGET} PUBLIC "${INCLUDE_DIRECTORY}")
# enable warnings
enable_warnings(${LIBRARY_TARGET})
cmake_minimum_required(VERSION 3.9.2)
# set project name
project(cwalk
VERSION 1.2.9
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
View File
@@ -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.
+21 -21
View File
@@ -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
SOFTWARE.
MIT License
Copyright (c) 2024 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.
+36 -35
View File
@@ -1,35 +1,36 @@
<img style="width:100%;" src="/banner.png">
[![Travis Build](https://img.shields.io/travis/likle/cwalk/master.svg?maxAge=2592000&label=Linux%20%26%20MacOS)](https://travis-ci.org/likle/cwalk)
[![Appveyor Build](https://img.shields.io/appveyor/ci/likle/cwalk/master.svg?label=Windows)](https://ci.appveyor.com/project/likle/cwalk)
[![codecov](https://img.shields.io/codecov/c/github/likle/cwalk/master.svg?label=Coverage)](https://codecov.io/gh/likle/cwalk)
[![Language Grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/likle/cwalk.svg?label=Code%20Quality)](https://lgtm.com/projects/g/likle/cwalk/context:cpp)
# 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">
[![Build Pipeline](https://github.com/likle/cwalk/actions/workflows/build-linux.yml/badge.svg)](https://github.com/likle/cwalk/actions/workflows/build-linux.yml)
[![Build Pipeline](https://github.com/likle/cwalk/actions/workflows/build-freebsd.yml/badge.svg)](https://github.com/likle/cwalk/actions/workflows/build-freebsd.yml)
[![Build Pipeline](https://github.com/likle/cwalk/actions/workflows/build-macos.yml/badge.svg)](https://github.com/likle/cwalk/actions/workflows/build-macos.yml)
[![Build Pipeline](https://github.com/likle/cwalk/actions/workflows/build-win.yml/badge.svg)](https://github.com/likle/cwalk/actions/workflows/build-win.yml)
[![codecov](https://img.shields.io/codecov/c/github/likle/cwalk/master.svg?label=Coverage)](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 **Linux**, **FreeBSD**, **Windows** and **MacOS**. 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 Linux, FreeBSD, Windows 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.
+10
View File
@@ -0,0 +1,10 @@
{
"name": "cwalk",
"repo": "likle/cwalk",
"version": "v1.2.9",
"decription": "libcwalk - path library for C/C++",
"src": [
"src/cwalk.c",
"include/cwalk.h"
]
}
+15 -11
View File
@@ -1,11 +1,15 @@
function(create_test_list 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_TARGET} ${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
View File
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/CwalkTargets.cmake")
Regular → Executable
+25 -18
View File
@@ -1,18 +1,25 @@
# enable warnings
function(enable_warnings target)
if(MSVC)
target_compile_options(${target} PRIVATE /W4)
target_compile_options(${target} PRIVATE /WX)
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(${target} PRIVATE -Werror)
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)
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(${target} PRIVATE -Wall)
target_compile_options(${target} PRIVATE -Werror)
target_compile_options(${target} PRIVATE -Wextra)
target_compile_options(${target} PRIVATE -Wpedantic)
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()
+11
View File
@@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: @PROJECT_NAME@
Description: @CMAKE_PROJECT_DESCRIPTION@
URL: @CMAKE_PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Cflags: -I"${includedir}"
Libs: -L"${libdir}" -lcwalk
+5 -5
View File
@@ -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
View File
@@ -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?v2" 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 -116
View File
@@ -1,116 +1,126 @@
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: #00A1AF radial-gradient(#FFFFFF, #FAFAFA);
background-repeat: no-repeat;
padding: 0;
}
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;;
}
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;
}
}
+5 -1
View File
@@ -34,8 +34,12 @@ cmake ..
make
```
# Running Tests
After building **cwalk** you can run tests to ensure everything is fine. In order to do that, make sure that you are in the build folder and then execute the test program:
In order to run tests, cwalk needs to be built with tests enabled. There is a ``ENABLE_TESTS`` flag for that. It can be passed to the cmake command like this:
```
cmake .. -DENABLE_TESTS=1
```
After building **cwalk** you can run tests to ensure everything is fine. In order to do that, make sure that you are in the build folder and then execute the test program:
```bash
./cwalktest
```
+68 -68
View File
@@ -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. |
+71 -71
View File
@@ -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. |
+68 -68
View File
@@ -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. |
+72 -72
View File
@@ -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. |
+4 -2
View File
@@ -15,7 +15,7 @@ size_t cwk_path_get_absolute(const char *base, const char *path, char *buffer,
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).
## Parameters
* **base**: The base path on which the relative path will be applied.
* **base**: The absolute base path on which the relative path will be applied.
* **path**: The relative path which will be applied on the base path.
* **buffer**: The buffer where the result will be written to.
* **buffer_size**: The size of the result buffer.
@@ -61,4 +61,6 @@ The absolute path is: /hello/there/world
| Version | Description |
|------------|--------------------------------------------------------|
| **v1.0.0** | The function is introduced. |
| **v1.2.4** | Fix for relative base path fallback on windows. |
| **v1.2.3** | Fix for path generation when reusing buffers. |
| **v1.0.0** | The function is introduced. |
@@ -31,12 +31,12 @@ int main(int argc, char *argv[])
struct cwk_segment segment;
if(!cwk_path_get_last_segment("/my/funny/test/path.txt", &segment)) {
printf("Path doesn't have any segments.");
printf("Path doesn't have any segments.\n");
return EXIT_FAILURE;
}
do {
printf("Current segment is '%.*s'.\n", segment.size, segment.begin);
printf("Current segment is '%.*s'.\n", (int)segment.size, segment.begin);
} while(cwk_path_get_previous_segment(&segment));
return EXIT_SUCCESS;
@@ -45,7 +45,7 @@ int main(int argc, char *argv[])
Ouput:
```
Current segment is 'path'.
Current segment is 'path.txt'.
Current segment is 'test'.
Current segment is 'funny'.
Current segment is 'my'.
@@ -55,4 +55,5 @@ Current segment is 'my'.
| Version | Description |
|------------|--------------------------------------------------------|
| **v1.0.0** | The function is introduced. |
| **v1.2.4** | Bugfix for single char segments. |
| **v1.0.0** | The function is introduced. |
+6 -3
View File
@@ -64,6 +64,9 @@ The relative path is: ../world
## Changelog
| Version | Description |
|------------|--------------------------------------------------------|
| **v1.0.0** | The function is introduced. |
| Version | Description |
|------------|---------------------------------------------------|
| **v1.2.7** | Fixed windows paths with forward slashes in root. |
| **v1.2.5** | Fixed calls with path without segments. |
| **v1.2.5** | Fixed calls with unequal roots in paths. |
| **v1.0.0** | The function is introduced. |
+78 -78
View File
@@ -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. |
+4 -2
View File
@@ -11,7 +11,9 @@ Determines whether the file path has an extension.
bool cwk_path_has_extension(const char *path);
```
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. In order to read more information about the extension see [[cwk_path_get_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. In order
to read more information about the extension see **[cwk_path_get_extension]({{ site.baseurl }}{% link reference/cwk_path_get_extension.md %})**.
## Parameters
* **path**: The path which will be inspected.
@@ -57,4 +59,4 @@ yes.
| Version | Description |
|------------|--------------------------------------------------------|
| **v1.0.0** | The function is introduced. |
| **v1.0.0** | The function is introduced. |
+2 -2
View File
@@ -50,7 +50,7 @@ int main(int argc, char *argv[])
size_t length;
path = "/this/is/a/test";
length = cwk_path_get_intersection(path, "/this/is/a/string")
length = cwk_path_get_intersection(path, "/this/is/a/string");
printf("The common portion is: '%.*s'", length, path);
return EXIT_SUCCESS;
@@ -66,4 +66,4 @@ The common portion is: '/this/is/a'
| Version | Description |
|------------|--------------------------------------------------------|
| **v1.0.0** | The function is introduced. |
| **v1.0.0** | The function is introduced. |
+7 -7
View File
@@ -3,7 +3,7 @@ title: cwk_path_join
description: Joins two paths together.
---
_(since v1.0.0)_
_(since v1.0.0)_
Joins two paths together.
## Description
@@ -33,18 +33,18 @@ Returns the total amount of characters of the full, combined path.
| UNIX | ``hello/there`` | ``..`` | ``hello`` |
| UNIX | ``hello`` | ``there`` | ``hello/there`` |
| WINDOWS | ``this\`` | ``C:\..\..\is\a\test\`` | ``is\a\test`` |
| WINDOWS | ``C:\this\path`` | ``C:\is\a\test\`` | ``C:\this\path\C:\is\a\test`` |
| WINDOWS | ``C:\this\path`` | ``C:\is\a\test\`` | ``C:\this\path\C:\is\a\test`` |
| WINDOWS | ``C:\this\path`` | ``C:\..\is\a\test\`` | ``C:\this\path\is\a\test`` |
| WINDOWS | ``\\s1\unc\path`` | ``\\s2\unc\pa`` | ``\\s1\unc\pa\s2\unc\path`` |
### Style
The style is automatically chosen during compile time, which is
The style is automatically chosen during compile time, which is
UNIX for macOS and linux and WINDOWS for windows. You can change the style
using [cwk_path_join]({{ site.baseurl }}{% link reference/cwk_path_join.md %}).
using [cwk_path_set_style]({{ site.baseurl }}{% link reference/cwk_path_set_style.md %}).
### Result
The **path_b** parameter will always be treated as a relative path, so even if
a driver letter is submitted on a windows style path, it will be treated as a
The **path_b** parameter will always be treated as a relative path, so even if
a driver letter is submitted on a windows style path, it will be treated as a
folder.
## Example
@@ -57,7 +57,7 @@ folder.
int main(int argc, char *argv[])
{
char buffer[FILENAME_MAX];
cwk_path_join("hello/there", "../world", buffer, sizeof(buffer));
printf("The combined path is: %s", buffer);
+5 -4
View File
@@ -11,7 +11,7 @@ Creates a normalized version of the path.
size_t cwk_path_normalize(const char *path, char *buffer, size_t buffer_size);
```
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.
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 returned value is the amount of characters which the resulting path would take if it was not truncated (excluding the null-terminating character). The path may be the same memory address as the buffer.
The following will be true for the normalized path:
* "../" will be resolved.
@@ -68,6 +68,7 @@ Output:
## Changelog
| Version | Description |
|------------|--------------------------------------------------------|
| **v1.0.0** | The function is introduced. |
| Version | Description |
|------------|---------------------------------------------------|
| **v1.2.7** | Fixed windows paths with forward slashes in root. |
| **v1.0.0** | The function is introduced. |
+499 -466
View File
@@ -1,466 +1,499 @@
#pragma once
#ifndef CWK_LIBRARY_H
#define CWK_LIBRARY_H
#include <stdbool.h>
#include <stddef.h>
#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 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.
*/
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.
*/
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.
*/
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.
*/
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 it's 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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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 returned value is the amount of
* characters which the resulting path would take if it was not truncated
* (excluding the null-terminating character). 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 str 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
+16 -2
View File
@@ -1,15 +1,29 @@
project('cwalk', 'c',
license: 'MIT',
meson_version: '>= 0.45.1'
version: '1.2.9',
meson_version: '>= 0.57.0'
)
cwalk_inc = include_directories('include')
cwalk_c_args = []
if get_option('default_library') == 'shared'
cwalk_c_args += '-DCWK_SHARED'
endif
cwalk = library('cwalk', 'src/cwalk.c',
install: true,
include_directories: cwalk_inc
include_directories: cwalk_inc,
c_args: cwalk_c_args
)
install_headers('include/cwalk.h')
cwalk_dep = declare_dependency(include_directories: 'include', link_with: cwalk)
if get_option('ENABLE_TESTS')
subdir('test')
endif
pkg = import('pkgconfig')
pkg.generate(cwalk)
+1
View File
@@ -0,0 +1 @@
option('ENABLE_TESTS', type: 'boolean', value: false, description: 'Enables building test executables')
Regular → Executable
+1479 -1424
View File
File diff suppressed because it is too large. Load diff
Regular → Executable
+206 -150
View File
@@ -1,150 +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_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_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;
}
#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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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;
}
Regular → Executable
+313 -313
View File
@@ -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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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;
}
Regular → Executable
+154 -154
View File
@@ -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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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;
}
Regular → Executable
+308 -308
View File
@@ -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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (cwk_path_has_extension("/my/path")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int extension_check_empty(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (cwk_path_has_extension("")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int extension_check_simple(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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
View File
@@ -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(void)
{
if (cwk_path_guess_style("") != CWK_STYLE_UNIX) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int guess_unguessable(void)
{
if (cwk_path_guess_style("myfile") != CWK_STYLE_UNIX) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int guess_extension(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
if (cwk_path_guess_style("/directory") != CWK_STYLE_UNIX) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int guess_windows_root(void)
{
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;
}
Regular → Executable
+13 -13
View File
@@ -1,7 +1,7 @@
#include <cwalk.h>
#include <stdlib.h>
int intersection_skipped_end()
int intersection_skipped_end(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
@@ -12,7 +12,7 @@ int intersection_skipped_end()
return EXIT_SUCCESS;
}
int intersection_relative_other()
int intersection_relative_other(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
@@ -23,7 +23,7 @@ int intersection_relative_other()
return EXIT_SUCCESS;
}
int intersection_relative_base()
int intersection_relative_base(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
@@ -35,7 +35,7 @@ int intersection_relative_base()
return EXIT_SUCCESS;
}
int intersection_one_root_only()
int intersection_one_root_only(void)
{
cwk_path_set_style(CWK_STYLE_WINDOWS);
@@ -46,7 +46,7 @@ int intersection_one_root_only()
return EXIT_SUCCESS;
}
int intersection_same_roots()
int intersection_same_roots(void)
{
cwk_path_set_style(CWK_STYLE_WINDOWS);
@@ -57,7 +57,7 @@ int intersection_same_roots()
return EXIT_SUCCESS;
}
int intersection_relative_absolute_mix()
int intersection_relative_absolute_mix(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
@@ -68,7 +68,7 @@ int intersection_relative_absolute_mix()
return EXIT_SUCCESS;
}
int intersection_unequal_roots()
int intersection_unequal_roots(void)
{
cwk_path_set_style(CWK_STYLE_WINDOWS);
@@ -79,7 +79,7 @@ int intersection_unequal_roots()
return EXIT_SUCCESS;
}
int intersection_empty()
int intersection_empty(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
@@ -90,7 +90,7 @@ int intersection_empty()
return EXIT_SUCCESS;
}
int intersection_double_separator()
int intersection_double_separator(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (cwk_path_get_intersection("/this///is/a//test", "/this//is/a///file") !=
@@ -101,7 +101,7 @@ int intersection_double_separator()
return EXIT_SUCCESS;
}
int intersection_trailing_separator()
int intersection_trailing_separator(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (cwk_path_get_intersection("/this/is/a/test", "/this/is/a/") != 10) {
@@ -111,7 +111,7 @@ int intersection_trailing_separator()
return EXIT_SUCCESS;
}
int intersection_truncated()
int intersection_truncated(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (cwk_path_get_intersection("/this/is/a/test", "/this/is/a") != 10) {
@@ -121,7 +121,7 @@ int intersection_truncated()
return EXIT_SUCCESS;
}
int intersection_simple()
int intersection_simple(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (cwk_path_get_intersection("/this/is/a/test", "/this/is/a/string") != 10) {
@@ -129,4 +129,4 @@ int intersection_simple()
}
return EXIT_SUCCESS;
}
}
Regular → Executable
+165 -145
View File
@@ -1,145 +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;
}
#include <cwalk.h>
#include <stdlib.h>
int is_absolute_relative_windows(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (cwk_path_is_absolute("\\folder\\")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int is_absolute_windows_slash(void)
{
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(void)
{
cwk_path_set_style(CWK_STYLE_WINDOWS);
if (!cwk_path_is_absolute("\\test.txt")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int is_absolute_relative(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (cwk_path_is_absolute("test.txt")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int is_absolute_absolute(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (!cwk_path_is_absolute("/test.txt")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int is_absolute_root(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (!cwk_path_is_absolute("/")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int is_absolute_dir(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (!cwk_path_is_absolute("/dir")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Regular → Executable
+145 -145
View File
@@ -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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (!cwk_path_is_relative("\\folder\\")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int is_relative_windows_slash(void)
{
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(void)
{
cwk_path_set_style(CWK_STYLE_WINDOWS);
if (cwk_path_is_relative("\\test.txt")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int is_relative_relative(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (!cwk_path_is_relative("test.txt")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int is_relative_absolute(void)
{
cwk_path_set_style(CWK_STYLE_UNIX);
if (cwk_path_is_relative("/test.txt")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
+186 -186
View File
@@ -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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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
View File
@@ -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 < 40; ++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;
}
+23
View File
@@ -0,0 +1,23 @@
cwalktest_sources = files(
'main.c',
'absolute_test.c',
'basename_test.c',
'dirname_test.c',
'extension_test.c',
'guess_test.c',
'intersection_test.c',
'is_absolute_test.c',
'is_relative_test.c',
'join_test.c',
'normalize_test.c',
'relative_test.c',
'root_test.c',
'segment_test.c',
'windows_test.c',
)
cwalktest = executable('cwalktest',
sources: cwalktest_sources,
dependencies: cwalk_dep,
)
test('cwalktest', cwalktest)
+261 -242
View File
@@ -1,242 +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_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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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;
}
Regular → Executable
+356 -245
View File
@@ -1,245 +1,356 @@
#include <cwalk.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
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_different_roots()
{
char result[FILENAME_MAX];
size_t length;
cwk_path_set_style(CWK_STYLE_WINDOWS);
length = cwk_path_get_relative("C:/path/same", "D:/path/same", result,
sizeof(result));
if (length != 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_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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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;
}
Regular → Executable
+287 -286
View File
@@ -1,286 +1,287 @@
#include <cwalk.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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 -546
View File
File diff suppressed because it is too large. Load diff
Regular → Executable
+116 -116
View File
@@ -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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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(void)
{
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;
}