1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
/* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */
#if defined(__CYGWIN__) || defined(__MSYS__)
#include <windows.h>
#include <pobl/bl_debug.h>
#include <pobl/bl_path.h> /* bl_conv_to_win32_path */
/* --- global functions --- */
HANDLE
cygfopen(const char *path, const char *mode) {
char winpath[MAX_PATH];
HANDLE file;
if (bl_conv_to_win32_path(path, winpath, sizeof(winpath)) < 0) {
return NULL;
}
if (*mode == 'a') {
file =
CreateFileA(winpath, FILE_APPEND_DATA, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
} else /* if( *mode == 'w') */
{
file = CreateFileA(winpath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
}
if (file == INVALID_HANDLE_VALUE) {
return NULL;
} else {
return file;
}
}
int cygfclose(HANDLE file) {
CloseHandle(file);
return 0;
}
size_t cygfwrite(const void *ptr, size_t size, size_t nmemb, HANDLE file) {
DWORD written;
if (WriteFile(file, ptr, size * nmemb, &written, NULL)) {
return written;
} else {
return 0;
}
}
#ifdef __DEBUG
void main(void) {
HANDLE file = cygfopen("test.log", "w");
cygfwrite("aaa\n", 1, 4, file);
cygfclose(file);
file = cygfopen("test.log", "a");
cygfwrite("bbb\n", 1, 4, file);
cygfclose(file);
}
#endif
#endif
|