comparison common/listutil.c @ 1157:fd7d04bb37cb

(issue36) Add encoding aware port_fopen function and use it
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 18 Sep 2014 15:43:22 +0200
parents edbf5e5e88f4
children 2a1206932f53
comparison
equal deleted inserted replaced
1156:e986d3d4705f 1157:fd7d04bb37cb
20 #include <share.h> 20 #include <share.h>
21 #endif 21 #endif
22 22
23 #include "strhelp.h" 23 #include "strhelp.h"
24 #include "logging.h" 24 #include "logging.h"
25 #include "portpath.h"
25 26
26 #ifdef RELEASE_BUILD 27 #ifdef RELEASE_BUILD
27 #include "pubkey-release.h" 28 #include "pubkey-release.h"
28 #else 29 #else
29 #include "pubkey-test.h" 30 #include "pubkey-test.h"
52 53
53 if (!file_name || !data || !size || !max_size) 54 if (!file_name || !data || !size || !max_size)
54 { 55 {
55 return READ_FILE_INVALID_CALL; 56 return READ_FILE_INVALID_CALL;
56 } 57 }
57 #ifdef WIN32 58
58 { 59 f = port_fopen_rb(file_name, true);
59 wchar_t *wFilename = utf8_to_wchar(file_name, strlen(file_name));
60 if (!wFilename)
61 {
62 return READ_FILE_UNREADABLE;
63 }
64 /* We open and write protect the file here so that
65 as long as the file is open we can be sure that
66 it was not modified and can use it in subsequent
67 calls based on the filename. */
68 f = _wfsopen(wFilename, L"rb", _SH_DENYWR);
69 xfree(wFilename);
70 }
71 #else
72 f = fopen(file_name, "rb");
73 #endif
74 if (f == NULL) 60 if (f == NULL)
75 return READ_FILE_UNREADABLE; 61 return READ_FILE_UNREADABLE;
76 62
77 fseek(f, 0, SEEK_END); 63 fseek(f, 0, SEEK_END);
78 file_size = ftell(f); 64 file_size = ftell(f);

http://wald.intevation.org/projects/trustbridge/