summaryrefslogtreecommitdiff
path: root/uisimulator/common/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/common/io.c')
-rw-r--r--uisimulator/common/io.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index ca64affa8c..ca597e0805 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -50,6 +50,12 @@
50#include "debug.h" 50#include "debug.h"
51#include "config.h" 51#include "config.h"
52 52
53/* Windows (and potentially other OSes) distinguish binary and text files.
54 * Define a dummy for the others. */
55#ifndef O_BINARY
56#define O_BINARY 0
57#endif
58
53#ifdef HAVE_DIRCACHE 59#ifdef HAVE_DIRCACHE
54void dircache_remove(const char *name); 60void dircache_remove(const char *name);
55void dircache_rename(const char *oldpath, const char *newpath); 61void dircache_rename(const char *oldpath, const char *newpath);
@@ -81,11 +87,8 @@ typedef struct mydir MYDIR;
81#if 1 /* maybe this needs disabling for MSVC... */ 87#if 1 /* maybe this needs disabling for MSVC... */
82static unsigned int rockbox2sim(int opt) 88static unsigned int rockbox2sim(int opt)
83{ 89{
84#ifdef WIN32
85 int newopt = O_BINARY; 90 int newopt = O_BINARY;
86#else 91
87 int newopt = 0;
88#endif
89 if(opt & 1) 92 if(opt & 1)
90 newopt |= O_WRONLY; 93 newopt |= O_WRONLY;
91 if(opt & 2) 94 if(opt & 2)
@@ -189,24 +192,22 @@ int sim_open(const char *name, int o)
189 192
190} 193}
191 194
192int sim_creat(const char *name, mode_t mode) 195int sim_creat(const char *name)
193{ 196{
194 int opts = rockbox2sim(mode);
195
196#ifndef __PCTOOL__ 197#ifndef __PCTOOL__
197 char buffer[256]; /* sufficiently big */ 198 char buffer[256]; /* sufficiently big */
198 if(name[0] == '/') 199 if(name[0] == '/')
199 { 200 {
200 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); 201 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
201 202
202 debugf("We create the real file '%s'\n", buffer); 203 debugf("We create the real file '%s'\n", buffer);
203 return open(buffer, opts | O_CREAT | O_TRUNC, 0666); 204 return open(buffer, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666);
204 } 205 }
205 fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", 206 fprintf(stderr, "WARNING, bad file name lacks slash: %s\n",
206 name); 207 name);
207 return -1; 208 return -1;
208#else 209#else
209 return open(name, opts | O_CREAT | O_TRUNC, 0666); 210 return open(name, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666);
210#endif 211#endif
211} 212}
212 213
@@ -390,15 +391,11 @@ void *sim_codec_load_ram(char* codecptr, int size,
390 { 391 {
391 sprintf(path, TEMP_CODEC_FILE, codec_count); 392 sprintf(path, TEMP_CODEC_FILE, codec_count);
392 393
393 #ifdef WIN32
394 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU); 394 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU);
395 #else
396 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
397 #endif
398 if (fd >= 0) 395 if (fd >= 0)
399 break; /* Created a file ok */ 396 break; /* Created a file ok */
400 } 397 }
401 if (fd < 0) 398 if (fd < 0)
402 { 399 {
403 DEBUGF("failed to open for write: %s\n", path); 400 DEBUGF("failed to open for write: %s\n", path);
404 return NULL; 401 return NULL;