Coverage Report

Created: 2025-02-07 06:04

/src/clib/deps/path-normalize/path-normalize.c
Line
Count
Source (jump to first uncovered line)
1
2
//
3
// path-normalize.c
4
//
5
// Copyright (c) 2013 Stephen Mathieson
6
// MIT licensed
7
//
8
9
#include <string.h>
10
#include "strdup/strdup.h"
11
#include "path-normalize.h"
12
13
/*
14
 * Normalize the given `path`
15
 */
16
17
char *
18
0
path_normalize(const char *path) {
19
0
  if (!path) return NULL;
20
21
0
  char *copy = strdup(path);
22
0
  if (NULL == copy) return NULL;
23
0
  char *ptr = copy;
24
25
0
  for (int i = 0; copy[i]; i++) {
26
0
    *ptr++ = path[i];
27
0
    if ('/' == path[i]) {
28
0
      i++;
29
0
      while ('/' == path[i]) i++;
30
0
      i--;
31
0
    }
32
0
  }
33
34
0
  *ptr = '\0';
35
36
0
  return copy;
37
0
}