From 22b7701fe75cce9afdbc27046821dc089f9e7dac Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 22 Feb 2005 12:19:12 +0000 Subject: Build cleanup and general fixes. fprintf() is now fdprintf(), the separation between uisimulator files and firmware/apps files are better done. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6031 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/common/io.c | 124 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 7 deletions(-) (limited to 'uisimulator/common/io.c') diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index 6335735f8f..48b888a027 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #ifdef __FreeBSD__ #include @@ -28,6 +29,10 @@ #include #endif +#ifdef WIN32 +#include +#endif + #ifndef _MSC_VER #include #include @@ -35,18 +40,27 @@ #include "dir-win32.h" #endif +#define MAX_PATH 260 + #include #include "debug.h" -#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */ -#define dirent sim_dirent -#define DIR SIMDIR -#include "../../firmware/include/dir.h" -#undef dirent -#undef DIR - #define SIMULATOR_ARCHOS_ROOT "archos" +struct sim_dirent { + unsigned char d_name[MAX_PATH]; + int attribute; + int size; + int startcluster; + unsigned short wrtdate; /* Last write date */ + unsigned short wrttime; /* Last write time */ +}; + +struct dirstruct { + void *dir; /* actually a DIR* dir */ + char *name; +} SIM_DIR; + struct mydir { DIR *dir; char *name; @@ -113,6 +127,8 @@ struct sim_dirent *sim_readdir(MYDIR *dir) dir->name, x11->d_name); stat(buffer, &s); /* get info */ +#define ATTR_DIRECTORY 0x10 + secret.attribute = S_ISDIR(s.st_mode)?ATTR_DIRECTORY:0; secret.size = s.st_size; secret.wrtdate = (unsigned short)(s.st_mtime >> 16); @@ -181,6 +197,7 @@ int sim_mkdir(const char *name, mode_t mode) debugf("We create the real directory '%s'\n", buffer); #ifdef WIN32 + /* since we build with -DNOCYGWIN we have the plain win32 version */ return (mkdir)(buffer); #else return (mkdir)(buffer, 0666); @@ -260,3 +277,96 @@ void fat_size(unsigned int* size, unsigned int* free) } #endif } + +int sim_fsync(int fd) +{ +#ifdef WIN32 + return _commit(fd); +#else + return fsync(fd); +#endif +} + +#ifdef WIN32 +/* sim-win32 */ +typedef enum plugin_status (*plugin_fn)(void* api, void* param); +#define dlopen(_x_, _y_) LoadLibrary(_x_) +#define dlsym(_x_, _y_) (plugin_fn)GetProcAddress(_x_, _y_) +#define dlclose(_x_) FreeLibrary(_x_) +#define dlerror() "Unknown" +#else +/* sim-x11 */ +#include +#endif + +void *sim_plugin_load(char *plugin, int *fd) +{ + void* pd; + char path[256]; + char buf[256]; + int (*plugin_start)(void * api, void* param); + + snprintf(path, sizeof path, "archos%s", plugin); + + *fd = -1; + + pd = dlopen(path, RTLD_NOW); + if (!pd) { + snprintf(buf, sizeof buf, "failed to load %s", plugin); + DEBUGF("dlopen(%s): %s\n",path,dlerror()); + dlclose(pd); + return NULL; + } + + plugin_start = dlsym(pd, "plugin_start"); + if (!plugin_start) { + plugin_start = dlsym(pd, "_plugin_start"); + if (!plugin_start) { + dlclose(pd); + return NULL; + } + } + *fd = pd; /* success */ + return plugin_start; +} + +void sim_plugin_close(int pd) +{ + dlclose(pd); +} + +#ifndef WIN32 +/* the win32 version is in debug-win32.c */ + +void debug_init(void) +{ + /* nothing to be done */ +} + +void debugf(const char *fmt, ...) +{ + va_list ap; + va_start( ap, fmt ); + vfprintf( stderr, fmt, ap ); + va_end( ap ); +} + +void ldebugf(const char* file, int line, const char *fmt, ...) +{ + va_list ap; + va_start( ap, fmt ); + fprintf( stderr, "%s:%d ", file, line ); + vfprintf( stderr, fmt, ap ); + va_end( ap ); +} + +#endif + +int sim_ftruncate(int fd, off_t length) +{ +#ifdef WIN32 + return _chsize(fd, length); +#else + return ftruncate(fd, length); +#endif +} -- cgit v1.2.3