summarylogtreecommitdiffstats
path: root/pathtools.h
blob: b01fab00673e652113ebfb502cf8dd9e8062d209 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
      .Some useful path tools.
        .ASCII only for now.
   .Written by Ray Donnelly in 2014.
   .Licensed under CC0 (and anything.
  .else you need to license it under).
      .No warranties whatsoever.
  .email: <mingw.android@gmail.com>.
 */

#ifndef PATHTOOLS_H
#define PATHTOOLS_H

#include <unistd.h>
#if defined(__APPLE__)
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#include <stdio.h>

char * malloc_copy_string(char const * original);

/* In-place replaces any '\' with '/' and any '//' with '/' */
void sanitise_path(char * path);

/* Uses a host OS specific function to determine the path of the executable,
   if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */
int get_executable_path(char const * argv0, char * result, ssize_t max_size);

#if defined(_WIN32)
int get_dll_path(char * result, unsigned long max_size);
#endif

/* Where possible, in-place removes occourances of '.' and 'path/..' */
void simplify_path(char * path);

/* Allocates (via malloc) and returns the path to get from from to to. */
char * get_relative_path(char const * from, char const * to);

size_t split_path_list(char const * path_list, char split_char, char *** arr);

/* Advances path along by the amount that removes n prefix folders. */
char const *
strip_n_prefix_folders(char const * path, size_t n);

/* NULL terminates path to remove n suffix folders. */
void
strip_n_suffix_folders(char * path, size_t n);

char const * get_relocated_path (char const * from, char const * to, char const * actual_from);
char * get_relocated_path_list(char const * from, char const * to_path_list);

char * single_path_relocation(const char *from, const char *to);
char * pathlist_relocation(const char *from_path, const char *to_path_list);

#endif /* PATHTOOLS_H */