-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBASENAME.H
47 lines (36 loc) · 975 Bytes
/
BASENAME.H
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
int basename (char *path, char *base, int max)
{
int i, stop;
stop = strcspn (path, ".");
if (stop > max) stop = max;
for (i = 0; i < stop; i ++) base [i] = path [i];
base [i] = 0;
return strcmp (path, base);
}
int extension (char *path, char *ext, int max)
{
int i;
char *start;
if ((start = strchr (path, '.')) == (char *) NULL) ext [0] = 0;
else
{
strncpy (ext, start, max);
ext [max] = 0;
}
return strlen (ext);
}
int bare_name (char *path, int maxp, char *fname, int maxf)
{
int i, k, start, stop;
/* find the end */
stop = strcspn (path, ".");
if (stop > maxp) stop = maxp;
/* find the beginning */
for (i = stop; i >= 0 && path [i] != '/'; i --);
start = i + 1;
/* copy file name without path and extension */
for (k = 0, i = start; k < maxf && i < stop; k ++, i ++)
fname [k] = path [i];
fname [k] = 0;
return strlen (fname);
}