summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarkus Mittendrein <git@maxmitti.tk>2019-03-16 15:15:56 +0100
committerMarkus Mittendrein <git@maxmitti.tk>2019-03-16 15:17:11 +0100
commit673a447f292c07ad5399211f823ec45771bea07b (patch)
treef6a72ab9e8621fe9a93018f761fa5c0712c36fd3 /src
parentdf9f87f985e0b1e5c13bf4b196d16316f49cd8ac (diff)
downloadcc4group-673a447f292c07ad5399211f823ec45771bea07b.tar.gz
cc4group-673a447f292c07ad5399211f823ec45771bea07b.zip
Fix c4ls_buffer and reading from stdin file "-" on windows
Diffstat (limited to 'src')
-rw-r--r--src/cc4group.c1
-rw-r--r--src/cc4group.h4
-rw-r--r--src/platform/platform.h3
3 files changed, 6 insertions, 2 deletions
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);