Skip to content

Commit 1d499b6

Browse files
committed
Adding rcutils_norm_path function
1 parent 660e090 commit 1d499b6

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

include/rcutils/filesystem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ rcutils_join_path(
126126
const char * right_hand_path,
127127
rcutils_allocator_t allocator);
128128

129+
RCUTILS_PUBLIC
130+
char *
131+
rcutils_norm_path(
132+
const char * path,
133+
rcutils_allocator_t allocator);
134+
129135
#ifdef __cplusplus
130136
}
131137
#endif

src/filesystem.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern "C"
2929
#endif // _WIN32
3030

3131
#include "rcutils/format_string.h"
32+
#include "rcutils/repl_str.h"
3233

3334
bool
3435
rcutils_get_cwd(char * buffer, size_t max_length)
@@ -161,6 +162,24 @@ rcutils_join_path(
161162
return rcutils_format_string(allocator, "%s%s%s", left_hand_path, delimiter, right_hand_path);
162163
}
163164

165+
char *
166+
rcutils_norm_path(
167+
const char * path,
168+
rcutils_allocator_t allocator)
169+
{
170+
if (NULL == path) {
171+
return NULL;
172+
}
173+
174+
#ifdef _WIN32
175+
const char * delimiter = "\\";
176+
#else
177+
const char * delimiter = "/";
178+
#endif // _WIN32
179+
180+
return rcutils_repl_str(path, "/", delimiter, &allocator);
181+
}
182+
164183
#ifdef __cplusplus
165184
}
166185
#endif

0 commit comments

Comments
 (0)