1
0
Fork 0
forked from len0rd/rockbox

Removed 'mode' parameter from creat(). It wasn't pure posix anyway, it was ignored on target and mixed into 'oflags' in the simulator. * Simplified io.c a bit by defining a dummy O_BINARY for OSes which don't have that.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12179 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2007-02-01 23:08:15 +00:00
parent 98dc093317
commit 67eb154146
26 changed files with 53 additions and 57 deletions

View file

@ -90,12 +90,12 @@
#define CODEC_ENC_MAGIC 0x52454E43 /* RENC */ #define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
/* increase this every time the api struct changes */ /* increase this every time the api struct changes */
#define CODEC_API_VERSION 10 #define CODEC_API_VERSION 11
/* update this to latest version if a change to the api struct breaks /* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */ new function which are "waiting" at the end of the function table) */
#define CODEC_MIN_API_VERSION 10 #define CODEC_MIN_API_VERSION 11
/* codec return codes */ /* codec return codes */
enum codec_status { enum codec_status {
@ -174,7 +174,7 @@ struct codec_api {
int (*close)(int fd); int (*close)(int fd);
ssize_t (*read)(int fd, void* buf, size_t count); ssize_t (*read)(int fd, void* buf, size_t count);
off_t (*PREFIX(lseek))(int fd, off_t offset, int whence); off_t (*PREFIX(lseek))(int fd, off_t offset, int whence);
int (*PREFIX(creat))(const char *pathname, mode_t mode); int (*PREFIX(creat))(const char *pathname);
ssize_t (*write)(int fd, const void* buf, size_t count); ssize_t (*write)(int fd, const void* buf, size_t count);
int (*PREFIX(remove))(const char* pathname); int (*PREFIX(remove))(const char* pathname);
int (*PREFIX(rename))(const char* path, const char* newname); int (*PREFIX(rename))(const char* path, const char* newname);

View file

@ -1933,14 +1933,14 @@ static bool dbg_save_roms(void)
int fd; int fd;
int oldmode = system_memory_guard(MEMGUARD_NONE); int oldmode = system_memory_guard(MEMGUARD_NONE);
fd = creat("/internal_rom_0000-FFFF.bin", O_WRONLY); fd = creat("/internal_rom_0000-FFFF.bin");
if(fd >= 0) if(fd >= 0)
{ {
write(fd, (void *)0, 0x10000); write(fd, (void *)0, 0x10000);
close(fd); close(fd);
} }
fd = creat("/internal_rom_2000000-203FFFF.bin", O_WRONLY); fd = creat("/internal_rom_2000000-203FFFF.bin");
if(fd >= 0) if(fd >= 0)
{ {
write(fd, (void *)0x2000000, 0x40000); write(fd, (void *)0x2000000, 0x40000);
@ -1957,11 +1957,11 @@ static bool dbg_save_roms(void)
int oldmode = system_memory_guard(MEMGUARD_NONE); int oldmode = system_memory_guard(MEMGUARD_NONE);
#if defined(IRIVER_H100_SERIES) #if defined(IRIVER_H100_SERIES)
fd = creat("/internal_rom_000000-1FFFFF.bin", O_WRONLY); fd = creat("/internal_rom_000000-1FFFFF.bin");
#elif defined(IRIVER_H300_SERIES) #elif defined(IRIVER_H300_SERIES)
fd = creat("/internal_rom_000000-3FFFFF.bin", O_WRONLY); fd = creat("/internal_rom_000000-3FFFFF.bin");
#elif defined(IAUDIO_X5) #elif defined(IAUDIO_X5)
fd = creat("/internal_rom_000000-3FFFFF.bin", O_WRONLY); fd = creat("/internal_rom_000000-3FFFFF.bin");
#endif #endif
if(fd >= 0) if(fd >= 0)
{ {
@ -1971,7 +1971,7 @@ static bool dbg_save_roms(void)
system_memory_guard(oldmode); system_memory_guard(oldmode);
#ifdef HAVE_EEPROM #ifdef HAVE_EEPROM
fd = creat("/internal_eeprom.bin", O_WRONLY); fd = creat("/internal_eeprom.bin");
if (fd >= 0) if (fd >= 0)
{ {
int old_irq_level; int old_irq_level;

View file

@ -716,7 +716,7 @@ static bool eq_save_preset(void)
/* allow user to modify filename */ /* allow user to modify filename */
while (true) { while (true) {
if (!kbd_input(filename, sizeof filename)) { if (!kbd_input(filename, sizeof filename)) {
fd = creat(filename, O_WRONLY); fd = creat(filename);
if (fd < 0) if (fd < 0)
gui_syncsplash(HZ, true, str(LANG_FAILED)); gui_syncsplash(HZ, true, str(LANG_FAILED));
else else

View file

@ -399,7 +399,7 @@ void screen_dump(void)
IF_CNFN_NUM_(, NULL)); IF_CNFN_NUM_(, NULL));
#endif #endif
fh = creat(filename, O_WRONLY); fh = creat(filename);
if (fh < 0) if (fh < 0)
return; return;

View file

@ -638,7 +638,7 @@ static bool clipboard_pastefile(const char *src, const char *target, bool copy)
src_fd = open(src, O_RDONLY); src_fd = open(src, O_RDONLY);
if (src_fd >= 0) { if (src_fd >= 0) {
target_fd = creat(target, O_WRONLY); target_fd = creat(target);
if (target_fd >= 0) { if (target_fd >= 0) {
result = true; result = true;

View file

@ -110,12 +110,12 @@
#define PLUGIN_MAGIC 0x526F634B /* RocK */ #define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */ /* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 41 #define PLUGIN_API_VERSION 42
/* update this to latest version if a change to the api struct breaks /* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */ new function which are "waiting" at the end of the function table) */
#define PLUGIN_MIN_API_VERSION 41 #define PLUGIN_MIN_API_VERSION 42
/* plugin return codes */ /* plugin return codes */
enum plugin_status { enum plugin_status {
@ -300,7 +300,7 @@ struct plugin_api {
int (*close)(int fd); int (*close)(int fd);
ssize_t (*read)(int fd, void* buf, size_t count); ssize_t (*read)(int fd, void* buf, size_t count);
off_t (*PREFIX(lseek))(int fd, off_t offset, int whence); off_t (*PREFIX(lseek))(int fd, off_t offset, int whence);
int (*PREFIX(creat))(const char *pathname, mode_t mode); int (*PREFIX(creat))(const char *pathname);
ssize_t (*write)(int fd, const void* buf, size_t count); ssize_t (*write)(int fd, const void* buf, size_t count);
int (*PREFIX(remove))(const char* pathname); int (*PREFIX(remove))(const char* pathname);
int (*PREFIX(rename))(const char* path, const char* newname); int (*PREFIX(rename))(const char* path, const char* newname);

View file

@ -316,7 +316,7 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown)
{ {
int fp,fq; int fp,fq;
fp = rb->open("/.rockbox/.memo",O_RDONLY | O_CREAT); fp = rb->open("/.rockbox/.memo",O_RDONLY | O_CREAT);
fq = rb->creat("/.rockbox/~temp", O_WRONLY); fq = rb->creat("/.rockbox/~temp");
if ( (fq != -1) && (fp != -1) ) if ( (fq != -1) && (fp != -1) )
{ {
int i; int i;
@ -345,7 +345,7 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown)
rb->write(fq,temp,1); rb->write(fq,temp,1);
} }
rb->close(fp); rb->close(fp);
fp = rb->creat("/.rockbox/.memo", O_WRONLY); fp = rb->creat("/.rockbox/.memo");
rb->lseek(fp, 0, SEEK_SET); rb->lseek(fp, 0, SEEK_SET);
rb->lseek(fq, 0, SEEK_SET); rb->lseek(fq, 0, SEEK_SET);
for (i = 0; i < rb->filesize(fq); i++) for (i = 0; i < rb->filesize(fq); i++)

View file

@ -903,7 +903,7 @@ void save_settings(bool interface)
rb->lcd_update(); rb->lcd_update();
} }
fd = rb->creat(default_filename, O_WRONLY); /* create the settings file */ fd = rb->creat(default_filename); /* create the settings file */
if(fd >= 0) /* file exists, save successful */ if(fd >= 0) /* file exists, save successful */
{ {

View file

@ -67,7 +67,7 @@ static int write_file(void)
rb->snprintf(tmpfilename, MAX_PATH+1, "%s.tmp", filename); rb->snprintf(tmpfilename, MAX_PATH+1, "%s.tmp", filename);
fd = rb->creat(tmpfilename, O_WRONLY); fd = rb->creat(tmpfilename);
if(fd < 0) if(fd < 0)
return 10 * fd - 1; return 10 * fd - 1;

View file

@ -56,7 +56,7 @@ int save_bmp_file( char* filename, struct bitmap *bm, struct plugin_api* rb )
int fh; int fh;
int x,y; int x,y;
if( bm->format != FORMAT_NATIVE ) return -1; if( bm->format != FORMAT_NATIVE ) return -1;
fh = rb->PREFIX(creat)( filename, O_WRONLY ); fh = rb->creat( filename );
if( fh < 0 ) return -1; if( fh < 0 ) return -1;
rb->write( fh, header, sizeof( header ) ); rb->write( fh, header, sizeof( header ) );

View file

@ -34,7 +34,7 @@ int configfile_save(const char *filename, struct configdata *cfg,
char buf[MAX_PATH]; char buf[MAX_PATH];
cfg_rb->snprintf(buf, MAX_PATH, "/.rockbox/rocks/%s", filename); cfg_rb->snprintf(buf, MAX_PATH, "/.rockbox/rocks/%s", filename);
fd = cfg_rb->creat(buf, O_WRONLY); fd = cfg_rb->creat(buf);
if(fd < 0) if(fd < 0)
return fd*10 - 1; return fd*10 - 1;

View file

@ -126,7 +126,7 @@ static bool search_init(char* file)
if (fd==-1) if (fd==-1)
return false; return false;
fdw = rb->creat(resultfile, O_WRONLY); fdw = rb->creat(resultfile);
if (fdw < 0) { if (fdw < 0) {
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP

View file

@ -140,7 +140,7 @@ static int write_file(void)
/* Create a temporary file */ /* Create a temporary file */
rb->snprintf(tmpfilename, MAX_PATH+1, "%s.tmp", filename); rb->snprintf(tmpfilename, MAX_PATH+1, "%s.tmp", filename);
fd = rb->creat(tmpfilename, O_WRONLY); fd = rb->creat(tmpfilename);
if(fd < 0) if(fd < 0)
return 10 * fd - 1; return 10 * fd - 1;

View file

@ -102,7 +102,7 @@ static bool test_fs(void)
rb->snprintf(text_buf, sizeof text_buf, "FS stress test: %dKB", (TEST_SIZE>>10)); rb->snprintf(text_buf, sizeof text_buf, "FS stress test: %dKB", (TEST_SIZE>>10));
log_lcd(text_buf, true); log_lcd(text_buf, true);
fd = rb->creat(TEST_FILE, 0); fd = rb->creat(TEST_FILE);
if (fd < 0) if (fd < 0)
{ {
rb->splash(0, true, "Couldn't create testfile."); rb->splash(0, true, "Couldn't create testfile.");
@ -193,7 +193,7 @@ static bool test_speed(void)
log_init(); log_init();
log_lcd("Disk speed test", true); log_lcd("Disk speed test", true);
fd = rb->creat(TEST_FILE, 0); fd = rb->creat(TEST_FILE);
if (fd < 0) if (fd < 0)
{ {
rb->splash(0, true, "Couldn't create testfile."); rb->splash(0, true, "Couldn't create testfile.");

View file

@ -50,7 +50,7 @@ static int insert_data_in_file(char *fname, int fpos, char *buf, int num_bytes)
return 10*orig_fd - 1; return 10*orig_fd - 1;
} }
fd = rb->creat(tmpname, O_WRONLY); fd = rb->creat(tmpname);
if(fd < 0) { if(fd < 0) {
rb->close(orig_fd); rb->close(orig_fd);
return 10*fd - 2; return 10*fd - 2;

View file

@ -1074,7 +1074,7 @@ static void viewer_load_settings(void) /* same name as global, but not the same
if (i < data->bookmarked_files_count) if (i < data->bookmarked_files_count)
{ {
/* it is in the list, write everything back in the correct order, and reload the file correctly */ /* it is in the list, write everything back in the correct order, and reload the file correctly */
settings_fd = rb->creat(BOOKMARKS_FILE, O_WRONLY); settings_fd = rb->creat(BOOKMARKS_FILE);
if (settings_fd >=0 ) if (settings_fd >=0 )
{ {
if (data->bookmarked_files_count > MAX_BOOKMARKED_FILES) if (data->bookmarked_files_count > MAX_BOOKMARKED_FILES)
@ -1092,7 +1092,7 @@ static void viewer_load_settings(void) /* same name as global, but not the same
} }
else /* not in list, write the list to the file */ else /* not in list, write the list to the file */
{ {
settings_fd = rb->creat(BOOKMARKS_FILE, O_WRONLY); settings_fd = rb->creat(BOOKMARKS_FILE);
if (settings_fd >=0 ) if (settings_fd >=0 )
{ {
if (++(data->bookmarked_files_count) > MAX_BOOKMARKED_FILES) if (++(data->bookmarked_files_count) > MAX_BOOKMARKED_FILES)
@ -1120,7 +1120,7 @@ static void viewer_load_settings(void) /* same name as global, but not the same
static void viewer_save_settings(void)/* same name as global, but not the same file.. */ static void viewer_save_settings(void)/* same name as global, but not the same file.. */
{ {
int settings_fd; int settings_fd;
settings_fd = rb->creat(SETTINGS_FILE, O_WRONLY); /* create the settings file */ settings_fd = rb->creat(SETTINGS_FILE); /* create the settings file */
rb->write (settings_fd, &prefs, sizeof(struct preferences)); rb->write (settings_fd, &prefs, sizeof(struct preferences));
rb->close(settings_fd); rb->close(settings_fd);

View file

@ -335,7 +335,7 @@ void load_settings(void) {
} }
void save_settings(void) { void save_settings(void) {
int fp = rb->creat("/.rockbox/rocks/.vu_meter", O_WRONLY); int fp = rb->creat("/.rockbox/rocks/.vu_meter");
if(fp >= 0) { if(fp >= 0) {
rb->write (fp, &settings, sizeof(struct saved_settings)); rb->write (fp, &settings, sizeof(struct saved_settings));
rb->close(fp); rb->close(fp);

View file

@ -174,7 +174,7 @@ static int wav2wv (char *filename)
extension [1] = extension [2]; extension [1] = extension [2];
extension [2] = 0; extension [2] = 0;
out_fd = rb->creat (filename, O_WRONLY); out_fd = rb->creat (filename);
extension [2] = extension [1]; extension [2] = extension [1];
extension [1] = save_a; extension [1] = save_a;

View file

@ -586,7 +586,7 @@ static void save_snapshot_file_type(char *name, int type)
int snsh; int snsh;
snsh = rb->open(name, O_WRONLY); snsh = rb->open(name, O_WRONLY);
if(snsh < 0) { if(snsh < 0) {
snsh = rb->creat(name, O_WRONLY); snsh = rb->creat(name);
if(snsh < 0) { if(snsh < 0) {
put_msg("Could not create snapshot file"); put_msg("Could not create snapshot file");
return; return;

View file

@ -972,7 +972,7 @@ static void radio_save_presets(void)
int fd; int fd;
int i; int i;
fd = creat(filepreset, O_WRONLY); fd = creat(filepreset);
if(fd >= 0) if(fd >= 0)
{ {
for(i = 0;i < num_presets;i++) for(i = 0;i < num_presets;i++)

View file

@ -1226,7 +1226,7 @@ bool create_playlist(void)
gui_textarea_update(&screens[i]); gui_textarea_update(&screens[i]);
#endif #endif
} }
fd = creat(filename, O_WRONLY); fd = creat(filename);
if (fd < 0) if (fd < 0)
return false; return false;

View file

@ -52,9 +52,8 @@ static struct filedesc openfiles[MAX_OPEN_FILES];
static int flush_cache(int fd); static int flush_cache(int fd);
int creat(const char *pathname, mode_t mode) int creat(const char *pathname)
{ {
(void)mode;
return open(pathname, O_WRONLY|O_CREAT|O_TRUNC); return open(pathname, O_WRONLY|O_CREAT|O_TRUNC);
} }

View file

@ -522,7 +522,7 @@ void glyph_cache_save(void)
if (fnt_file >= 0) { if (fnt_file >= 0) {
glyph_file = creat(GLYPH_CACHE_FILE, O_WRONLY); glyph_file = creat(GLYPH_CACHE_FILE);
if (glyph_file < 0) return; if (glyph_file < 0) return;

View file

@ -48,7 +48,7 @@
#ifdef SIMULATOR #ifdef SIMULATOR
#define open(x,y) sim_open(x,y) #define open(x,y) sim_open(x,y)
#define creat(x,y) sim_creat(x,y) #define creat(x) sim_creat(x)
#define remove(x) sim_remove(x) #define remove(x) sim_remove(x)
#define rename(x,y) sim_rename(x,y) #define rename(x,y) sim_rename(x,y)
#define filesize(x) sim_filesize(x) #define filesize(x) sim_filesize(x)
@ -59,7 +59,7 @@
typedef int (*open_func)(const char* pathname, int flags); typedef int (*open_func)(const char* pathname, int flags);
typedef ssize_t (*read_func)(int fd, void *buf, size_t count); typedef ssize_t (*read_func)(int fd, void *buf, size_t count);
typedef int (*creat_func)(const char *pathname, mode_t mode); typedef int (*creat_func)(const char *pathname);
typedef ssize_t (*write_func)(int fd, const void *buf, size_t count); typedef ssize_t (*write_func)(int fd, const void *buf, size_t count);
typedef void (*qsort_func)(void *base, size_t nmemb, size_t size, typedef void (*qsort_func)(void *base, size_t nmemb, size_t size,
int(*_compar)(const void *, const void *)); int(*_compar)(const void *, const void *));
@ -69,7 +69,7 @@ extern int close(int fd);
extern int fsync(int fd); extern int fsync(int fd);
extern ssize_t read(int fd, void *buf, size_t count); extern ssize_t read(int fd, void *buf, size_t count);
extern off_t lseek(int fildes, off_t offset, int whence); extern off_t lseek(int fildes, off_t offset, int whence);
extern int creat(const char *pathname, mode_t mode); extern int creat(const char *pathname);
extern ssize_t write(int fd, const void *buf, size_t count); extern ssize_t write(int fd, const void *buf, size_t count);
extern int remove(const char* pathname); extern int remove(const char* pathname);
extern int rename(const char* path, const char* newname); extern int rename(const char* path, const char* newname);

View file

@ -50,6 +50,12 @@
#include "debug.h" #include "debug.h"
#include "config.h" #include "config.h"
/* Windows (and potentially other OSes) distinguish binary and text files.
* Define a dummy for the others. */
#ifndef O_BINARY
#define O_BINARY 0
#endif
#ifdef HAVE_DIRCACHE #ifdef HAVE_DIRCACHE
void dircache_remove(const char *name); void dircache_remove(const char *name);
void dircache_rename(const char *oldpath, const char *newpath); void dircache_rename(const char *oldpath, const char *newpath);
@ -81,11 +87,8 @@ typedef struct mydir MYDIR;
#if 1 /* maybe this needs disabling for MSVC... */ #if 1 /* maybe this needs disabling for MSVC... */
static unsigned int rockbox2sim(int opt) static unsigned int rockbox2sim(int opt)
{ {
#ifdef WIN32
int newopt = O_BINARY; int newopt = O_BINARY;
#else
int newopt = 0;
#endif
if(opt & 1) if(opt & 1)
newopt |= O_WRONLY; newopt |= O_WRONLY;
if(opt & 2) if(opt & 2)
@ -189,24 +192,22 @@ int sim_open(const char *name, int o)
} }
int sim_creat(const char *name, mode_t mode) int sim_creat(const char *name)
{ {
int opts = rockbox2sim(mode);
#ifndef __PCTOOL__ #ifndef __PCTOOL__
char buffer[256]; /* sufficiently big */ char buffer[256]; /* sufficiently big */
if(name[0] == '/') if(name[0] == '/')
{ {
sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
debugf("We create the real file '%s'\n", buffer); debugf("We create the real file '%s'\n", buffer);
return open(buffer, opts | O_CREAT | O_TRUNC, 0666); return open(buffer, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666);
} }
fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", fprintf(stderr, "WARNING, bad file name lacks slash: %s\n",
name); name);
return -1; return -1;
#else #else
return open(name, opts | O_CREAT | O_TRUNC, 0666); return open(name, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666);
#endif #endif
} }
@ -390,15 +391,11 @@ void *sim_codec_load_ram(char* codecptr, int size,
{ {
sprintf(path, TEMP_CODEC_FILE, codec_count); sprintf(path, TEMP_CODEC_FILE, codec_count);
#ifdef WIN32
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU); fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU);
#else
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
#endif
if (fd >= 0) if (fd >= 0)
break; /* Created a file ok */ break; /* Created a file ok */
} }
if (fd < 0) if (fd < 0)
{ {
DEBUGF("failed to open for write: %s\n", path); DEBUGF("failed to open for write: %s\n", path);
return NULL; return NULL;

View file

@ -29,7 +29,7 @@
#include "lcd-sdl.h" #include "lcd-sdl.h"
/* extern functions, needed for screendump() */ /* extern functions, needed for screendump() */
extern int sim_creat(const char *name, mode_t mode); extern int sim_creat(const char *name);
SDL_Surface* lcd_surface; SDL_Surface* lcd_surface;
SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0}; SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0};
@ -185,7 +185,7 @@ void screen_dump(void)
IF_CNFN_NUM_(, NULL)); IF_CNFN_NUM_(, NULL));
DEBUGF("screen_dump\n"); DEBUGF("screen_dump\n");
fd = sim_creat(filename, O_WRONLY); fd = sim_creat(filename);
if (fd < 0) if (fd < 0)
return; return;