103 | 103 |
{
|
104 | 104 |
struct stat file_stats;
|
105 | 105 |
int mode = 0;
|
|
106 |
#ifdef UNICODE
|
|
107 |
char url_buffer[1024];
|
|
108 |
memset(url_buffer, 0, sizeof(url_buffer));
|
|
109 |
#ifdef _WIN32
|
|
110 |
if(WideCharToMultiByte(CP_ACP, 0, URL, -1, url_buffer, sizeof(url_buffer), 0, 0) == 0) {
|
|
111 |
#else
|
|
112 |
if (wcstombs_s(&return_length, url_buffer, sizeof(url_buffer), URL, sizeof(url_buffer) - 1) != 0) {
|
|
113 |
#endif
|
|
114 |
NodeReportError(p, NULL, ERR_ID, ERR_INVALID_PARAM, URL);
|
|
115 |
return ERR_INVALID_PARAM;
|
|
116 |
}
|
|
117 |
#else
|
|
118 |
const char* url_buffer = URL;
|
|
119 |
#endif
|
106 | 120 |
|
107 | 121 |
if (Flags & SFLAG_WRONLY && !(Flags & SFLAG_RDONLY))
|
108 | 122 |
mode = O_WRONLY;
|
|
114 | 128 |
if (Flags & SFLAG_CREATE)
|
115 | 129 |
mode |= O_CREAT|O_TRUNC;
|
116 | 130 |
|
117 | |
//bctbx_file_open2 doesn't work with Unicode files
|
118 | |
#ifdef UNICODE
|
119 | |
char fileStr[1024];
|
120 | |
memset(fileStr, 0, 1024);
|
121 | |
#ifdef _WIN32
|
122 | |
WideCharToMultiByte(CP_ACP, 0, URL, -1, fileStr, sizeof(fileStr), 0, 0);
|
123 | |
#else
|
124 | |
wcstombs(fileStr, URL, 1024);
|
125 | |
#endif
|
126 | |
p->fp = bctbx_file_open2(bctbx_vfs_get_default(), fileStr, mode);
|
127 | |
#else
|
128 | |
p->fp = bctbx_file_open2(bctbx_vfs_get_default(), URL, mode);
|
129 | |
#endif
|
130 | |
|
|
131 |
p->fp = bctbx_file_open2(bctbx_vfs_get_default(), url_buffer, mode);
|
131 | 132 |
if (p->fp == NULL)
|
132 | 133 |
{
|
133 | 134 |
if ((Flags & (SFLAG_REOPEN|SFLAG_SILENT))==0)
|
134 | |
NodeReportError(p,NULL,ERR_ID,ERR_FILE_NOT_FOUND,URL);
|
|
135 |
NodeReportError(p,NULL,ERR_ID,ERR_FILE_NOT_FOUND, url_buffer);
|
135 | 136 |
return ERR_FILE_NOT_FOUND;
|
136 | 137 |
}
|
137 | 138 |
|
138 | 139 |
tcscpy_s(p->URL,TSIZEOF(p->URL),URL);
|
139 | |
|
140 | |
if (stat(URL, &file_stats) == 0)
|
|
140 |
if (stat(url_buffer, &file_stats) == 0)
|
141 | 141 |
p->Length = file_stats.st_size;
|
142 | |
|
143 | 142 |
}
|
144 | 143 |
return ERR_NONE;
|
145 | 144 |
}
|