-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.c
61 lines (51 loc) · 941 Bytes
/
util.c
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
58
59
60
#include "impy.h"
#include "private.h"
#include <string.h>
#include <ctype.h>
int istricmp(const char* a, const char* b)
{
while(1) {
if(*a < *b) {
return -1;
}
if(*a > *b) {
return 1;
}
if(*a == '\0') {
break;
}
++a;
++b;
}
return 0;
}
bool is_path_sep(char c) {
if (c=='/') {
return true;
}
#ifdef __WIN32
if (c=='\\' || c==':') {
return true;
}
#endif
return false;
}
// examples:
// "wibble.gif" => ".gif"
// "foo/bar.wibble/blah" => ""
// "foo/bar.wibble/blah.png" => ".png"
// ".config" => ".config"
// "foo.tar.gz" => ".gz"
const char* ext_part( const char* path)
{
int n;
for (n=(int)strlen(path)-1; n>=0; --n) {
if (is_path_sep(path[n])) {
break;
}
if(path[n]=='.') {
return &path[n];
}
}
return "";
}