blob: 2a7275eb22fab83e22edf545277b4ecb0f19d305 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*
* Portable file and directory name functions.
* $Id$
* Copyright (c) 1997 by Tycho Softworks.
* For conditions of distribution and reuse see product license.
*/
#include <other/files.h>
#include <std/string.h>
#include <std/math.h>
char *dirname(char *path)
{
char *p = basename(path);
if(p == path)
return ".";
*(--p) = 0;
return path;
}
char *basename(const char *path)
{
char *p = strrchr(path, '/');
#if defined(_MSDOS) || defined(_OS2) || defined(_WIN32)
char *p1 = strrchr(path, '\\');
p = max(p, p1);
#endif
if(p)
return ++p;
else
return (char *)path;
}
char *extfname(const char *path)
{
char *e = strrchr(pathfname(path), '.');
if(e)
return e;
else
return "";
}
bool ispath(const char *p)
{
if(strchr(p, '/'))
return TRUE;
#if defined(_MSDOS) || defined(_OS2) || defined(_WIN32)
if(strchr(p, '\\'))
return TRUE;
#endif
return FALSE;
}
bool isroot(const char *p)
{
#if defined(_MSDOS) || defined(_OS2) || defined(_WIN32)
if(!strncmp(p, "\\\\", 2))
return TRUE;
if(p[1] == ':')
return TRUE;
#else
if(*p == '/')
return TRUE;
#endif
return FALSE;
}
|