diff options
| -rw-r--r-- | CMakeLists.txt | 7 | ||||
| -rw-r--r-- | examples/c4ls_buffer.c | 3 | ||||
| -rw-r--r-- | src/cc4group.c | 1 | ||||
| -rw-r--r-- | src/cc4group.h | 4 | ||||
| -rw-r--r-- | src/platform/platform.h | 3 |
5 files changed, 14 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1762b16..944b9eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,15 +59,18 @@ example(unc4group) example(c4copy) example(c4info) example(c4ls) -example(c4ls_buffer) example(c4touch) example(c4rm) example(c4mkdir) -add_executable(c4cat examples/c4cat.c src/platform/${CC4GROUP_PLATFORM}.c) +add_executable(c4cat examples/c4cat.c) target_link_libraries(c4cat PRIVATE cc4group) target_compile_definitions(c4cat PRIVATE CC4GROUP_PLATFORM_${CC4GROUP_PLATFORM_DEF}) +add_executable(c4ls_buffer examples/c4ls_buffer.c) +target_link_libraries(c4ls_buffer PRIVATE cc4group) +target_compile_definitions(c4ls_buffer PRIVATE CC4GROUP_PLATFORM_${CC4GROUP_PLATFORM_DEF}) + if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") add_executable(c4cat_dyn examples/c4cat_dyn.c) target_link_libraries(c4cat_dyn PRIVATE -ldl) diff --git a/examples/c4ls_buffer.c b/examples/c4ls_buffer.c index 6bb2cca..4ec6843 100644 --- a/examples/c4ls_buffer.c +++ b/examples/c4ls_buffer.c @@ -7,6 +7,7 @@ #include <errno.h> #include "cc4group.h" +#include "platform/platform.h" const char* formatTime(int32_t time) { @@ -58,6 +59,8 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } + SET_BINARY(STDIN_FILENO); + size_t size = 1024; uint8_t* buffer = malloc(size); if(buffer == NULL) diff --git a/src/cc4group.c b/src/cc4group.c index e0ba55e..e126984 100644 --- a/src/cc4group.c +++ b/src/cc4group.c @@ -1057,6 +1057,7 @@ static bool cc4group_openExisting(CC4Group* const this, const char* const path) if(strcmp(path, "-") == 0) { + SET_BINARY(STDIN_FILENO); return cc4group_openFd(this, STDIN_FILENO); } diff --git a/src/cc4group.h b/src/cc4group.h index 5031e95..cc04a4f 100644 --- a/src/cc4group.h +++ b/src/cc4group.h @@ -53,11 +53,11 @@ typedef struct { bool (*openMemory)(CC4Group* const this, const void* const groupData, size_t const size, int const memoryManagement); // opens a group through a file descriptor - // the file descriptor must have been opened with read access + // the file descriptor must have been opened with read access; also be aware that the file must be opened with binary mode on windows bool (*openFd)(CC4Group* const this, int fd); // opens a group through a FILE* - // the file must have been opened with read access + // the file must have been opened with read access; also be aware that the file must be opened with binary mode on windows bool (*openFilePointer)(CC4Group* const this, FILE* fd); // opens a group and calls the callback to get the group data diff --git a/src/platform/platform.h b/src/platform/platform.h index aaa6138..8e52d51 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -4,6 +4,7 @@ #include <sys/types.h> #ifdef CC4GROUP_PLATFORM_WINDOWS + #include <fcntl.h> #define PROT_READ 0x1 #define PROT_WRITE 0x2 /* This flag is only available in WinXP+ */ @@ -21,11 +22,13 @@ #define MAP_FAILED ((void *) -1) #define cc4group_mkdir(path, mode) mkdir((path)) + #define SET_BINARY(fd) setmode(fd, O_BINARY) #else #include <sys/mman.h> #define cc4group_mkdir(path, mode) mkdir((path), (mode)) #define O_BINARY 0 + #define SET_BINARY(fd) #endif void *cc4group_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset, void** extra); |
