cwk_path_change_root

(since v1.2.0)
Changes the root of a path.

Description

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 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

Return Value

Returns the total amount of characters of the new path.

Example

#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.