adding screenshot to savestate files
[drnoksnes] / platform / path.c
1 #include <string.h>
2
3 #include "port.h"
4
5 void PathMake(char *path, const char *drive, const char *dir,
6         const char *fname, const char *ext)
7 {
8         if (dir && *dir) {
9                 strcpy (path, dir);
10                 strcat (path, "/");
11         } else {
12                 *path = 0;
13         }
14         strcat (path, fname);
15         if (ext && *ext) {
16                 strcat (path, ".");
17                 strcat (path, ext);
18         }
19 }
20
21 void PathSplit(const char *path, char *drive, char *dir, char *fname, char *ext)
22 {
23         *drive = 0;
24
25         char *slash = strrchr (path, '/');
26         if (!slash)
27                 slash = strrchr (path, '\\');
28
29         char *dot = strrchr (path, '.');
30
31         if (dot && slash && dot < slash)
32                 dot = NULL;
33
34         if (!slash)
35         {
36                 strcpy (dir, "");
37                 strcpy (fname, path);
38                 if (dot)
39                 {
40                         *(fname + (dot - path)) = 0;
41                         strcpy (ext, dot + 1);
42                 }
43                 else
44                         strcpy (ext, "");
45         }
46         else
47         {
48                 strcpy (dir, path);
49                 *(dir + (slash - path)) = 0;
50                 strcpy (fname, slash + 1);
51                 if (dot)
52                 {
53                         *(fname + (dot - slash) - 1) = 0;
54                         strcpy (ext, dot + 1);
55                 }
56                 else
57                         strcpy (ext, "");
58         }
59 }
60
61 const char * PathBasename(const char * path)
62 {
63         const char * p = strrchr (path, '/');
64
65         if (p)
66                 return p + 1;
67
68         return path;
69 }
70