diff options
author | Werner Koch <[email protected]> | 2010-11-02 20:17:57 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2010-11-02 20:17:57 +0000 |
commit | 753375ffcf25b63e6f8e0c05aa36bb2fe0094329 (patch) | |
tree | 1af5bb58b8f0bd5c6b06d12d9bddffd260068b3e /src/data-fd.c | |
parent | First take on changes to allow building with MSC for W32CE. (diff) | |
download | gpgme-753375ffcf25b63e6f8e0c05aa36bb2fe0094329.tar.gz gpgme-753375ffcf25b63e6f8e0c05aa36bb2fe0094329.zip |
Might now build for CE using MSC.
Diffstat (limited to 'src/data-fd.c')
-rw-r--r-- | src/data-fd.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/data-fd.c b/src/data-fd.c index 1ada70f7..779202e2 100644 --- a/src/data-fd.c +++ b/src/data-fd.c @@ -30,6 +30,62 @@ #include "debug.h" #include "data.h" + + +#if defined(HAVE_W32CE_SYSTEM) && !defined(__MINGW32CE__) +/* We need to provide replacements for read, write and lseek. They + are taken from the cegcc runtime files, written by Pedro Alves + <[email protected]> in Feb 2007 and placed in the public + domain. (cf. cegcc/src/mingw/mingwex/wince/) */ + +#include <windows.h> + +static int +read (int fildes, void *buf, unsigned int bufsize) +{ + DWORD NumberOfBytesRead; + if (bufsize > 0x7fffffff) + bufsize = 0x7fffffff; + if (!ReadFile ((HANDLE) fildes, buf, bufsize, &NumberOfBytesRead, NULL)) + return -1; + return (int) NumberOfBytesRead; +} + +static int +write (int fildes, const void *buf, unsigned int bufsize) +{ + DWORD NumberOfBytesWritten; + if (bufsize > 0x7fffffff) + bufsize = 0x7fffffff; + if (!WriteFile ((HANDLE) fildes, buf, bufsize, &NumberOfBytesWritten, NULL)) + return -1; + return (int) NumberOfBytesWritten; +} + +static long +lseek (int fildes, long offset, int whence) +{ + DWORD mode; + switch (whence) + { + case SEEK_SET: + mode = FILE_BEGIN; + break; + case SEEK_CUR: + mode = FILE_CURRENT; + break; + case SEEK_END: + mode = FILE_END; + break; + default: + /* Specify an invalid mode so SetFilePointer catches it. */ + mode = (DWORD)-1; + } + return (long) SetFilePointer ((HANDLE) fildes, offset, NULL, mode); +} +#endif /*HAVE_W32CE_SYSTEM && !__MINGW32CE__*/ + + static ssize_t fd_read (gpgme_data_t dh, void *buffer, size_t size) |