summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/pathfuncs.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/firmware/common/pathfuncs.c b/firmware/common/pathfuncs.c
index 1c48a54972..2b4e6a8eb0 100644
--- a/firmware/common/pathfuncs.c
+++ b/firmware/common/pathfuncs.c
@@ -340,6 +340,57 @@ void path_correct_separators(char *dstpath, const char *path)
340 strcpy(dstp, p); 340 strcpy(dstp, p);
341} 341}
342 342
343/* Remove dot segments from the path
344 *
345 * 'path' and 'dstpath' may either be the same buffer or non-overlapping
346 */
347void path_remove_dot_segments (char *dstpath, const char *path)
348{
349 char *dstp = dstpath;
350 char *odstp = dstpath;
351 const char *p = path;
352
353 while (*p)
354 {
355 if (p[0] == '.' && p[1] == PATH_SEPCH)
356 p += 2;
357 else if (p[0] == '.' && p[1] == '.' && p[2] == PATH_SEPCH)
358 p += 3;
359 else if (p[0] == PATH_SEPCH && p[1] == '.' && p[2] == PATH_SEPCH)
360 p += 2;
361 else if (p[0] == PATH_SEPCH && p[1] == '.' && !p[2])
362 {
363 *dstp++ = PATH_SEPCH;
364 break;
365 }
366 else if (p[0] == PATH_SEPCH && p[1] == '.' &&
367 p[2] == '.' && p[3] == PATH_SEPCH)
368 {
369 dstp = odstp;
370 p += 3;
371 }
372 else if (p[0] == PATH_SEPCH && p[1] == '.' && p[2] == '.' && !p[3])
373 {
374 dstp = odstp;
375 *dstp++ = PATH_SEPCH;
376 break;
377 }
378 else if (p[0] == '.' && !p[1])
379 break;
380 else if (p[0] == '.' && p[1] == '.' && !p[2])
381 break;
382 else
383 {
384 odstp = dstp;
385 if (p[0] == PATH_SEPCH)
386 *dstp++ = *p++;
387 while (p[0] && p[0] != PATH_SEPCH)
388 *dstp++ = *p++;
389 }
390 }
391 *dstp = 0;
392}
393
343/* Appends one path to another, adding separators between components if needed. 394/* Appends one path to another, adding separators between components if needed.
344 * Return value and behavior is otherwise as strlcpy so that truncation may be 395 * Return value and behavior is otherwise as strlcpy so that truncation may be
345 * detected. 396 * detected.