diff options
Diffstat (limited to 'src/platform')
| -rw-r--r-- | src/platform/platform.h | 7 | ||||
| -rw-r--r-- | src/platform/unix.c | 13 | ||||
| -rw-r--r-- | src/platform/windows.c | 17 |
3 files changed, 29 insertions, 8 deletions
diff --git a/src/platform/platform.h b/src/platform/platform.h index 55ed242..04b20b0 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -24,11 +24,7 @@ #define cc4group_mkdir(path, mode) mkdir((path)) #define SET_BINARY(fd) setmode(fd, O_BINARY) #else - #ifndef _XOPEN_SOURCE - #define _XOPEN_SOURCE 700 - #endif #include <sys/mman.h> - #include <stdlib.h> #define cc4group_mkdir(path, mode) mkdir((path), (mode)) #define O_BINARY 0 @@ -37,4 +33,5 @@ void *cc4group_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); int cc4group_munmap(void *addr, size_t length); -char* cc4group_absolutePath(const char* path);
\ No newline at end of file +char* cc4group_absolutePath(const char* path); +char* cc4group_basename(const char* path);
\ No newline at end of file diff --git a/src/platform/unix.c b/src/platform/unix.c index 01161fc..4e534a6 100644 --- a/src/platform/unix.c +++ b/src/platform/unix.c @@ -1,3 +1,11 @@ +#ifndef _XOPEN_SOURCE + #define _XOPEN_SOURCE 700 +#endif +#ifndef _GNU_SOURCE + #define _GNU_SOURCE +#endif +#include <stdlib.h> +#include <string.h> #include "platform.h" void *cc4group_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) @@ -14,3 +22,8 @@ char* cc4group_absolutePath(const char* path) { return realpath(path, NULL); } + +char* cc4group_basename(const char* path) +{ + return strdup(basename(path)); +}
\ No newline at end of file diff --git a/src/platform/windows.c b/src/platform/windows.c index 96678ab..50cb722 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -15,6 +15,7 @@ #include <io.h> #include <windows.h> +#include <string.h> #include <sys/types.h> #include "platform.h" @@ -90,6 +91,9 @@ void *cc4group_mmap(void *start, size_t length, int prot, int flags, int fd, off return ret; } +#undef DWORD_HI +#undef DWORD_LO + int cc4group_munmap(void *addr, size_t length) { (void)length; @@ -102,6 +106,13 @@ char* cc4group_absolutePath(const char* path) return _fullpath(NULL, path, 0); } - -#undef DWORD_HI -#undef DWORD_LO +char* cc4group_basename(const char* path) +{ + char fname[_MAX_FNAME]; + char ext[_MAX_EXT]; + _splitpath(path, NULL, NULL, fname, ext); + char* result = malloc(sizeof(char) * (strlen(fname) + strlen(ext) + 1); + strcpy(result, fname); + strcat(result, ext); + return result; +} |
