2002-05-13 15:23:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Daniel Stenberg
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2002-04-30 13:14:59 +00:00
|
|
|
|
2002-06-14 11:00:13 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2005-02-22 12:19:12 +00:00
|
|
|
#include <stdarg.h>
|
2002-05-07 12:06:32 +00:00
|
|
|
#include <sys/stat.h>
|
2007-04-06 23:54:21 +00:00
|
|
|
#include <time.h>
|
2003-07-04 08:30:01 +00:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
2006-09-29 16:15:11 +00:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
2004-06-10 13:29:52 +00:00
|
|
|
#elif !defined(WIN32)
|
2002-11-12 11:32:26 +00:00
|
|
|
#include <sys/vfs.h>
|
2003-07-04 08:30:01 +00:00
|
|
|
#endif
|
2004-06-14 07:00:50 +00:00
|
|
|
|
2005-02-22 12:19:12 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2004-06-14 07:00:50 +00:00
|
|
|
#ifndef _MSC_VER
|
2002-05-07 12:25:30 +00:00
|
|
|
#include <dirent.h>
|
2003-01-28 23:14:41 +00:00
|
|
|
#include <unistd.h>
|
2004-06-14 07:00:50 +00:00
|
|
|
#else
|
|
|
|
#include "dir-win32.h"
|
|
|
|
#endif
|
2002-04-30 13:14:59 +00:00
|
|
|
|
2005-02-22 12:19:12 +00:00
|
|
|
#define MAX_PATH 260
|
2007-10-09 15:15:00 +00:00
|
|
|
#define MAX_OPEN_FILES 11
|
2005-02-22 12:19:12 +00:00
|
|
|
|
2002-06-14 11:00:13 +00:00
|
|
|
#include <fcntl.h>
|
2007-09-08 12:20:53 +00:00
|
|
|
#include <SDL.h>
|
|
|
|
#include <SDL_thread.h>
|
|
|
|
#include "thread.h"
|
|
|
|
#include "kernel.h"
|
2002-06-14 11:00:13 +00:00
|
|
|
#include "debug.h"
|
2006-08-26 14:19:18 +00:00
|
|
|
#include "config.h"
|
2007-09-13 20:53:32 +00:00
|
|
|
#include "ata.h" /* for IF_MV2 et al. */
|
2006-08-26 14:19:18 +00:00
|
|
|
|
2007-02-01 23:08:15 +00:00
|
|
|
/* Windows (and potentially other OSes) distinguish binary and text files.
|
|
|
|
* Define a dummy for the others. */
|
|
|
|
#ifndef O_BINARY
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2007-04-19 20:17:24 +00:00
|
|
|
/* Unicode compatibility for win32 */
|
|
|
|
#if defined __MINGW32__
|
|
|
|
/* Rockbox unicode functions */
|
|
|
|
extern const unsigned char* utf8decode(const unsigned char *utf8,
|
|
|
|
unsigned short *ucs);
|
|
|
|
extern unsigned char* utf8encode(unsigned long ucs, unsigned char *utf8);
|
|
|
|
|
2007-04-20 17:35:05 +00:00
|
|
|
/* Static buffers for the conversion results. This isn't thread safe,
|
|
|
|
* but it's sufficient for rockbox. */
|
|
|
|
static unsigned char convbuf1[3*MAX_PATH];
|
|
|
|
static unsigned char convbuf2[3*MAX_PATH];
|
|
|
|
|
|
|
|
static wchar_t* utf8_to_ucs2(const unsigned char *utf8, void *buffer)
|
2007-04-19 20:17:24 +00:00
|
|
|
{
|
2007-04-20 17:35:05 +00:00
|
|
|
wchar_t *ucs = buffer;
|
2007-04-19 20:17:24 +00:00
|
|
|
|
|
|
|
while (*utf8)
|
|
|
|
utf8 = utf8decode(utf8, ucs++);
|
2007-11-08 12:11:34 +00:00
|
|
|
|
2007-04-19 20:17:24 +00:00
|
|
|
*ucs = 0;
|
2007-04-20 17:35:05 +00:00
|
|
|
return buffer;
|
2007-04-19 20:17:24 +00:00
|
|
|
}
|
2007-04-20 17:35:05 +00:00
|
|
|
static unsigned char *ucs2_to_utf8(const wchar_t *ucs, unsigned char *buffer)
|
2007-04-19 20:17:24 +00:00
|
|
|
{
|
|
|
|
unsigned char *utf8 = buffer;
|
2007-04-20 17:35:05 +00:00
|
|
|
|
2007-04-19 20:17:24 +00:00
|
|
|
while (*ucs)
|
|
|
|
utf8 = utf8encode(*ucs++, utf8);
|
2007-11-08 12:11:34 +00:00
|
|
|
|
2007-04-19 20:17:24 +00:00
|
|
|
*utf8 = 0;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2007-04-20 17:35:05 +00:00
|
|
|
#define UTF8_TO_OS(a) utf8_to_ucs2(a,convbuf1)
|
|
|
|
#define OS_TO_UTF8(a) ucs2_to_utf8(a,convbuf1)
|
2007-04-19 20:17:24 +00:00
|
|
|
#define DIR_T _WDIR
|
|
|
|
#define DIRENT_T struct _wdirent
|
|
|
|
#define STAT_T struct _stat
|
|
|
|
extern int _wmkdir(const wchar_t*);
|
|
|
|
extern int _wrmdir(const wchar_t*);
|
|
|
|
#define MKDIR(a,b) (_wmkdir)(UTF8_TO_OS(a))
|
|
|
|
#define RMDIR(a) (_wrmdir)(UTF8_TO_OS(a))
|
|
|
|
#define OPENDIR(a) (_wopendir)(UTF8_TO_OS(a))
|
|
|
|
#define READDIR(a) (_wreaddir)(a)
|
|
|
|
#define CLOSEDIR(a) (_wclosedir)(a)
|
|
|
|
#define STAT(a,b) (_wstat)(UTF8_TO_OS(a),b)
|
|
|
|
#define OPEN(a,b,c) (_wopen)(UTF8_TO_OS(a),b,c)
|
2007-10-09 17:51:02 +00:00
|
|
|
#define CLOSE(a) (close)(a)
|
2007-04-19 20:17:24 +00:00
|
|
|
#define REMOVE(a) (_wremove)(UTF8_TO_OS(a))
|
2007-04-20 17:35:05 +00:00
|
|
|
#define RENAME(a,b) (_wrename)(UTF8_TO_OS(a),utf8_to_ucs2(b,convbuf2))
|
2007-04-19 20:17:24 +00:00
|
|
|
|
|
|
|
#else /* !__MINGW32__ */
|
|
|
|
|
|
|
|
#define UTF8_TO_OS(a) (a)
|
|
|
|
#define OS_TO_UTF8(a) (a)
|
|
|
|
#define DIR_T DIR
|
|
|
|
#define DIRENT_T struct dirent
|
|
|
|
#define STAT_T struct stat
|
|
|
|
#define MKDIR(a,b) (mkdir)(a,b)
|
|
|
|
#define RMDIR(a) (rmdir)(a)
|
|
|
|
#define OPENDIR(a) (opendir)(a)
|
|
|
|
#define READDIR(a) (readdir)(a)
|
|
|
|
#define CLOSEDIR(a) (closedir)(a)
|
|
|
|
#define STAT(a,b) (stat)(a,b)
|
|
|
|
#define OPEN(a,b,c) (open)(a,b,c)
|
2007-10-09 15:15:00 +00:00
|
|
|
#define CLOSE(x) (close)(x)
|
2007-04-19 20:17:24 +00:00
|
|
|
#define REMOVE(a) (remove)(a)
|
|
|
|
#define RENAME(a,b) (rename)(a,b)
|
|
|
|
|
|
|
|
#endif /* !__MINGW32__ */
|
|
|
|
|
|
|
|
|
2006-08-26 14:19:18 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
void dircache_remove(const char *name);
|
|
|
|
void dircache_rename(const char *oldpath, const char *newpath);
|
|
|
|
#endif
|
2002-06-14 11:00:13 +00:00
|
|
|
|
2007-11-08 10:15:44 +00:00
|
|
|
|
|
|
|
#define SIMULATOR_DEFAULT_ROOT "archos"
|
|
|
|
extern const char *sim_root_dir;
|
2002-05-07 12:25:30 +00:00
|
|
|
|
2007-10-09 15:15:00 +00:00
|
|
|
static int num_openfiles = 0;
|
|
|
|
|
2005-02-22 12:19:12 +00:00
|
|
|
struct sim_dirent {
|
|
|
|
unsigned char d_name[MAX_PATH];
|
|
|
|
int attribute;
|
2007-04-07 00:14:16 +00:00
|
|
|
long size;
|
|
|
|
long startcluster;
|
2007-11-08 12:11:34 +00:00
|
|
|
unsigned short wrtdate; /* Last write date */
|
2005-02-22 12:19:12 +00:00
|
|
|
unsigned short wrttime; /* Last write time */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dirstruct {
|
|
|
|
void *dir; /* actually a DIR* dir */
|
2007-11-08 12:11:34 +00:00
|
|
|
char *name;
|
2005-02-22 12:19:12 +00:00
|
|
|
} SIM_DIR;
|
|
|
|
|
2002-05-07 12:25:30 +00:00
|
|
|
struct mydir {
|
2007-04-19 20:17:24 +00:00
|
|
|
DIR_T *dir;
|
2003-03-05 22:59:36 +00:00
|
|
|
char *name;
|
2002-05-07 12:25:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct mydir MYDIR;
|
2002-04-30 13:14:59 +00:00
|
|
|
|
2005-02-24 23:11:21 +00:00
|
|
|
#if 1 /* maybe this needs disabling for MSVC... */
|
2004-06-14 22:22:49 +00:00
|
|
|
static unsigned int rockbox2sim(int opt)
|
|
|
|
{
|
2006-02-03 15:19:58 +00:00
|
|
|
int newopt = O_BINARY;
|
2007-02-01 23:08:15 +00:00
|
|
|
|
2004-06-14 22:22:49 +00:00
|
|
|
if(opt & 1)
|
|
|
|
newopt |= O_WRONLY;
|
|
|
|
if(opt & 2)
|
|
|
|
newopt |= O_RDWR;
|
|
|
|
if(opt & 4)
|
|
|
|
newopt |= O_CREAT;
|
|
|
|
if(opt & 8)
|
|
|
|
newopt |= O_APPEND;
|
|
|
|
if(opt & 0x10)
|
|
|
|
newopt |= O_TRUNC;
|
|
|
|
|
|
|
|
return newopt;
|
|
|
|
}
|
2004-07-08 05:50:20 +00:00
|
|
|
#endif
|
2004-06-14 22:22:49 +00:00
|
|
|
|
2007-09-08 12:20:53 +00:00
|
|
|
/** Simulator I/O engine routines **/
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
IO_QUIT = -1,
|
|
|
|
IO_OPEN,
|
|
|
|
IO_CLOSE,
|
|
|
|
IO_READ,
|
|
|
|
IO_WRITE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sim_io
|
|
|
|
{
|
|
|
|
SDL_mutex *m; /* Mutex for condition */
|
|
|
|
SDL_cond *c; /* Condition for synchronizing threads */
|
|
|
|
SDL_Thread *t; /* The I/O thread */
|
|
|
|
struct mutex sim_mutex; /* Rockbox mutex */
|
|
|
|
volatile int cmd; /* The command to perform */
|
|
|
|
volatile int ready; /* I/O ready flag - 1= ready */
|
|
|
|
volatile int fd; /* The file to read/write */
|
|
|
|
void* volatile buf; /* The buffer to read/write */
|
|
|
|
volatile size_t count; /* Number of bytes to read/write */
|
|
|
|
ssize_t result; /* Result of operation */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct sim_io io;
|
|
|
|
|
|
|
|
static int io_thread(void *data)
|
|
|
|
{
|
|
|
|
SDL_LockMutex(io.m);
|
|
|
|
|
|
|
|
io.ready = 1; /* Indication mutex has been locked */
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
SDL_CondWait(io.c, io.m); /* unlock mutex and wait */
|
|
|
|
|
|
|
|
switch (io.cmd)
|
|
|
|
{
|
|
|
|
case IO_READ:
|
|
|
|
io.result = read(io.fd, io.buf, io.count);
|
|
|
|
io.ready = 1;
|
|
|
|
break;
|
|
|
|
case IO_WRITE:
|
|
|
|
io.result = write(io.fd, io.buf, io.count);
|
|
|
|
io.ready = 1;
|
|
|
|
break;
|
|
|
|
case IO_QUIT:
|
|
|
|
SDL_UnlockMutex(io.m);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
2007-09-10 03:49:12 +00:00
|
|
|
bool sim_io_init(void)
|
2007-09-08 12:20:53 +00:00
|
|
|
{
|
|
|
|
io.ready = 0;
|
|
|
|
|
|
|
|
io.m = SDL_CreateMutex();
|
|
|
|
if (io.m == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to create IO mutex\n");
|
2007-09-10 03:49:12 +00:00
|
|
|
return false;
|
2007-09-08 12:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
io.c = SDL_CreateCond();
|
|
|
|
if (io.c == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to create IO cond\n");
|
2007-09-10 03:49:12 +00:00
|
|
|
return false;
|
2007-09-08 12:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
io.t = SDL_CreateThread(io_thread, NULL);
|
|
|
|
if (io.t == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to create IO thread\n");
|
2007-09-10 03:49:12 +00:00
|
|
|
return false;
|
2007-09-08 12:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for IO thread to lock mutex */
|
2007-09-09 01:59:07 +00:00
|
|
|
while (!io.ready)
|
|
|
|
SDL_Delay(0);
|
2007-09-08 12:20:53 +00:00
|
|
|
|
|
|
|
/* Wait for it to unlock */
|
|
|
|
SDL_LockMutex(io.m);
|
|
|
|
/* Free it for another thread */
|
|
|
|
SDL_UnlockMutex(io.m);
|
2007-09-10 03:49:12 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ata_init(void)
|
|
|
|
{
|
|
|
|
/* Initialize the rockbox kernel objects on a rockbox thread */
|
|
|
|
mutex_init(&io.sim_mutex);
|
|
|
|
return 1;
|
2007-09-08 12:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sim_io_shutdown(void)
|
|
|
|
{
|
|
|
|
SDL_LockMutex(io.m);
|
|
|
|
|
|
|
|
io.cmd = IO_QUIT;
|
|
|
|
|
|
|
|
SDL_CondSignal(io.c);
|
|
|
|
SDL_UnlockMutex(io.m);
|
|
|
|
|
|
|
|
SDL_WaitThread(io.t, NULL);
|
|
|
|
|
|
|
|
SDL_DestroyMutex(io.m);
|
|
|
|
SDL_DestroyCond(io.c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void io_trigger_and_wait(int cmd)
|
|
|
|
{
|
|
|
|
/* Lock mutex before setting up new params and signaling condition */
|
|
|
|
SDL_LockMutex(io.m);
|
|
|
|
|
|
|
|
io.cmd = cmd;
|
|
|
|
io.ready = 0;
|
|
|
|
|
|
|
|
/* Get thread started */
|
|
|
|
SDL_CondSignal(io.c);
|
|
|
|
|
|
|
|
/* Let it run */
|
|
|
|
SDL_UnlockMutex(io.m);
|
|
|
|
|
|
|
|
/* Wait for IO to complete */
|
|
|
|
while (!io.ready)
|
|
|
|
yield();
|
|
|
|
}
|
|
|
|
|
2007-11-08 10:15:44 +00:00
|
|
|
static const char *get_sim_rootdir()
|
|
|
|
{
|
|
|
|
if (sim_root_dir != NULL)
|
|
|
|
return sim_root_dir;
|
|
|
|
return SIMULATOR_DEFAULT_ROOT;
|
|
|
|
}
|
|
|
|
|
2004-06-10 13:29:52 +00:00
|
|
|
MYDIR *sim_opendir(const char *name)
|
2002-04-30 13:14:59 +00:00
|
|
|
{
|
2007-04-12 22:38:54 +00:00
|
|
|
char buffer[MAX_PATH]; /* sufficiently big */
|
2007-04-19 20:17:24 +00:00
|
|
|
DIR_T *dir;
|
2003-03-05 22:59:36 +00:00
|
|
|
|
2006-11-10 08:03:33 +00:00
|
|
|
#ifndef __PCTOOL__
|
2007-04-19 20:17:24 +00:00
|
|
|
if(name[0] == '/')
|
2006-11-10 08:03:33 +00:00
|
|
|
{
|
2007-11-08 10:15:44 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name);
|
2007-04-19 20:17:24 +00:00
|
|
|
dir=(DIR_T *)OPENDIR(buffer);
|
2003-03-05 22:59:36 +00:00
|
|
|
}
|
|
|
|
else
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
2007-04-19 20:17:24 +00:00
|
|
|
dir=(DIR_T *)OPENDIR(name);
|
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
if(dir) {
|
|
|
|
MYDIR *my = (MYDIR *)malloc(sizeof(MYDIR));
|
|
|
|
my->dir = dir;
|
|
|
|
my->name = (char *)strdup(name);
|
|
|
|
|
|
|
|
return my;
|
|
|
|
}
|
|
|
|
/* failed open, return NULL */
|
|
|
|
return (MYDIR *)0;
|
2002-04-30 13:14:59 +00:00
|
|
|
}
|
2002-05-05 10:28:23 +00:00
|
|
|
|
2004-06-10 13:29:52 +00:00
|
|
|
struct sim_dirent *sim_readdir(MYDIR *dir)
|
2002-05-07 11:35:03 +00:00
|
|
|
{
|
2007-11-08 12:11:34 +00:00
|
|
|
char buffer[MAX_PATH]; /* sufficiently big */
|
2004-06-10 13:29:52 +00:00
|
|
|
static struct sim_dirent secret;
|
2007-04-19 20:17:24 +00:00
|
|
|
STAT_T s;
|
|
|
|
DIRENT_T *x11 = READDIR(dir->dir);
|
2007-04-06 23:33:33 +00:00
|
|
|
struct tm* tm;
|
2002-05-07 11:35:03 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
if(!x11)
|
2004-06-10 13:29:52 +00:00
|
|
|
return (struct sim_dirent *)0;
|
2002-05-07 11:35:03 +00:00
|
|
|
|
2007-04-19 20:17:24 +00:00
|
|
|
strcpy((char *)secret.d_name, OS_TO_UTF8(x11->d_name));
|
2002-05-07 12:06:32 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
/* build file name */
|
2006-11-10 08:03:33 +00:00
|
|
|
#ifdef __PCTOOL__
|
2007-04-19 20:17:24 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s/%s", dir->name, secret.d_name);
|
2006-11-10 08:03:33 +00:00
|
|
|
#else
|
2007-11-08 10:15:44 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s/%s/%s",
|
|
|
|
get_sim_rootdir(), dir->name, secret.d_name);
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
2007-04-19 20:17:24 +00:00
|
|
|
STAT(buffer, &s); /* get info */
|
2002-05-07 12:06:32 +00:00
|
|
|
|
2005-02-22 12:19:12 +00:00
|
|
|
#define ATTR_DIRECTORY 0x10
|
2007-11-08 12:11:34 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
secret.attribute = S_ISDIR(s.st_mode)?ATTR_DIRECTORY:0;
|
|
|
|
secret.size = s.st_size;
|
2002-05-07 11:35:03 +00:00
|
|
|
|
2007-04-06 23:33:33 +00:00
|
|
|
tm = localtime(&(s.st_mtime));
|
|
|
|
secret.wrtdate = ((tm->tm_year - 80) << 9) |
|
|
|
|
((tm->tm_mon + 1) << 5) |
|
|
|
|
tm->tm_mday;
|
|
|
|
secret.wrttime = (tm->tm_hour << 11) |
|
|
|
|
(tm->tm_min << 5) |
|
|
|
|
(tm->tm_sec >> 1);
|
2003-03-05 22:59:36 +00:00
|
|
|
return &secret;
|
2002-05-07 11:35:03 +00:00
|
|
|
}
|
|
|
|
|
2004-06-10 13:29:52 +00:00
|
|
|
void sim_closedir(MYDIR *dir)
|
2002-05-07 12:06:32 +00:00
|
|
|
{
|
2003-03-05 22:59:36 +00:00
|
|
|
free(dir->name);
|
2007-04-19 20:17:24 +00:00
|
|
|
CLOSEDIR(dir->dir);
|
2002-05-07 12:06:32 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
free(dir);
|
2002-05-07 12:06:32 +00:00
|
|
|
}
|
|
|
|
|
2004-06-14 22:22:49 +00:00
|
|
|
int sim_open(const char *name, int o)
|
2002-05-05 10:28:23 +00:00
|
|
|
{
|
2007-04-12 22:38:54 +00:00
|
|
|
char buffer[MAX_PATH]; /* sufficiently big */
|
2004-06-14 22:22:49 +00:00
|
|
|
int opts = rockbox2sim(o);
|
2007-10-09 15:15:00 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (num_openfiles >= MAX_OPEN_FILES)
|
|
|
|
return -2;
|
2002-05-05 10:28:23 +00:00
|
|
|
|
2006-11-10 08:03:33 +00:00
|
|
|
#ifndef __PCTOOL__
|
2007-10-09 15:15:00 +00:00
|
|
|
if(name[0] == '/')
|
2006-11-10 08:03:33 +00:00
|
|
|
{
|
2007-11-08 10:15:44 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name);
|
2005-02-28 18:32:57 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
debugf("We open the real file '%s'\n", buffer);
|
2007-10-09 15:15:00 +00:00
|
|
|
if (num_openfiles < MAX_OPEN_FILES)
|
|
|
|
{
|
|
|
|
ret = OPEN(buffer, opts, 0666);
|
|
|
|
if (ret >= 0) num_openfiles++;
|
|
|
|
return ret;
|
|
|
|
}
|
2003-03-05 22:59:36 +00:00
|
|
|
}
|
2007-10-09 15:15:00 +00:00
|
|
|
|
2004-06-14 22:32:13 +00:00
|
|
|
fprintf(stderr, "WARNING, bad file name lacks slash: %s\n",
|
|
|
|
name);
|
|
|
|
return -1;
|
2006-11-10 08:03:33 +00:00
|
|
|
#else
|
2007-10-09 15:15:00 +00:00
|
|
|
if (num_openfiles < MAX_OPEN_FILES)
|
|
|
|
{
|
|
|
|
ret = OPEN(buffer, opts, 0666);
|
|
|
|
if (ret >= 0) num_openfiles++;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
2007-10-09 15:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int sim_close(int fd)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
ret = CLOSE(fd);
|
|
|
|
if (ret == 0) num_openfiles--;
|
|
|
|
return ret;
|
2002-05-05 10:28:23 +00:00
|
|
|
}
|
2002-11-12 11:32:26 +00:00
|
|
|
|
2007-02-01 23:08:15 +00:00
|
|
|
int sim_creat(const char *name)
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
2006-11-10 08:03:33 +00:00
|
|
|
#ifndef __PCTOOL__
|
2007-04-12 22:38:54 +00:00
|
|
|
char buffer[MAX_PATH]; /* sufficiently big */
|
2007-02-01 23:08:15 +00:00
|
|
|
if(name[0] == '/')
|
2006-11-10 08:03:33 +00:00
|
|
|
{
|
2007-11-08 10:15:44 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name);
|
2007-11-08 12:11:34 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
debugf("We create the real file '%s'\n", buffer);
|
2007-04-19 20:17:24 +00:00
|
|
|
return OPEN(buffer, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
2003-03-05 22:59:36 +00:00
|
|
|
}
|
2007-04-12 22:38:54 +00:00
|
|
|
fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name);
|
2004-06-14 22:32:13 +00:00
|
|
|
return -1;
|
2006-11-10 08:03:33 +00:00
|
|
|
#else
|
2007-04-19 20:17:24 +00:00
|
|
|
return OPEN(name, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
2007-11-08 12:11:34 +00:00
|
|
|
}
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2007-09-08 12:20:53 +00:00
|
|
|
ssize_t sim_read(int fd, void *buf, size_t count)
|
|
|
|
{
|
|
|
|
ssize_t result;
|
|
|
|
|
|
|
|
mutex_lock(&io.sim_mutex);
|
|
|
|
|
|
|
|
/* Setup parameters */
|
|
|
|
io.fd = fd;
|
|
|
|
io.buf = buf;
|
|
|
|
io.count = count;
|
|
|
|
|
|
|
|
io_trigger_and_wait(IO_READ);
|
|
|
|
|
|
|
|
result = io.result;
|
|
|
|
|
|
|
|
mutex_unlock(&io.sim_mutex);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t sim_write(int fd, const void *buf, size_t count)
|
|
|
|
{
|
|
|
|
ssize_t result;
|
|
|
|
|
|
|
|
mutex_lock(&io.sim_mutex);
|
|
|
|
|
|
|
|
io.fd = fd;
|
|
|
|
io.buf = (void*)buf;
|
|
|
|
io.count = count;
|
|
|
|
|
|
|
|
io_trigger_and_wait(IO_WRITE);
|
|
|
|
|
|
|
|
result = io.result;
|
|
|
|
|
|
|
|
mutex_unlock(&io.sim_mutex);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-02-03 10:28:55 +00:00
|
|
|
int sim_mkdir(const char *name)
|
2004-01-21 14:58:40 +00:00
|
|
|
{
|
2006-11-10 08:03:33 +00:00
|
|
|
#ifdef __PCTOOL__
|
2007-04-19 20:17:24 +00:00
|
|
|
return MKDIR(name, 0777);
|
2006-11-10 08:03:33 +00:00
|
|
|
#else
|
2007-04-12 22:38:54 +00:00
|
|
|
char buffer[MAX_PATH]; /* sufficiently big */
|
|
|
|
|
2007-11-08 10:15:44 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name);
|
2004-06-10 13:29:52 +00:00
|
|
|
|
|
|
|
debugf("We create the real directory '%s'\n", buffer);
|
2007-04-19 20:17:24 +00:00
|
|
|
return MKDIR(buffer, 0777);
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
2004-01-21 14:58:40 +00:00
|
|
|
}
|
|
|
|
|
2004-06-10 13:29:52 +00:00
|
|
|
int sim_rmdir(const char *name)
|
2004-04-16 09:24:38 +00:00
|
|
|
{
|
2006-11-10 08:03:33 +00:00
|
|
|
#ifdef __PCTOOL__
|
2007-04-19 20:17:24 +00:00
|
|
|
return RMDIR(name);
|
2006-11-10 08:03:33 +00:00
|
|
|
#else
|
2007-04-12 22:38:54 +00:00
|
|
|
char buffer[MAX_PATH]; /* sufficiently big */
|
2007-11-08 12:11:34 +00:00
|
|
|
if(name[0] == '/')
|
2006-11-10 08:03:33 +00:00
|
|
|
{
|
2007-11-08 10:15:44 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name);
|
2007-04-12 22:38:54 +00:00
|
|
|
|
2004-04-16 09:24:38 +00:00
|
|
|
debugf("We remove the real directory '%s'\n", buffer);
|
2007-04-19 20:17:24 +00:00
|
|
|
return RMDIR(buffer);
|
2004-04-16 09:24:38 +00:00
|
|
|
}
|
2007-04-19 20:17:24 +00:00
|
|
|
return RMDIR(name);
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
2004-04-16 09:24:38 +00:00
|
|
|
}
|
|
|
|
|
2004-06-10 13:29:52 +00:00
|
|
|
int sim_remove(const char *name)
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
2006-11-10 08:03:33 +00:00
|
|
|
#ifdef __PCTOOL__
|
2007-04-19 20:17:24 +00:00
|
|
|
return REMOVE(name);
|
2006-11-10 08:03:33 +00:00
|
|
|
#else
|
2007-04-12 22:38:54 +00:00
|
|
|
char buffer[MAX_PATH]; /* sufficiently big */
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2006-08-26 14:19:18 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
dircache_remove(name);
|
|
|
|
#endif
|
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
if(name[0] == '/') {
|
2007-11-08 10:15:44 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name);
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
debugf("We remove the real file '%s'\n", buffer);
|
2007-04-19 20:17:24 +00:00
|
|
|
return REMOVE(buffer);
|
2003-03-05 22:59:36 +00:00
|
|
|
}
|
2007-04-19 20:17:24 +00:00
|
|
|
return REMOVE(name);
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
|
|
|
|
2004-06-10 13:29:52 +00:00
|
|
|
int sim_rename(const char *oldpath, const char* newpath)
|
2003-01-15 11:38:03 +00:00
|
|
|
{
|
2006-11-10 08:03:33 +00:00
|
|
|
#ifdef __PCTOOL__
|
2007-04-19 20:17:24 +00:00
|
|
|
return RENAME(oldpath, newpath);
|
2006-11-10 08:03:33 +00:00
|
|
|
#else
|
2007-04-12 22:38:54 +00:00
|
|
|
char buffer1[MAX_PATH];
|
|
|
|
char buffer2[MAX_PATH];
|
2003-01-15 11:38:03 +00:00
|
|
|
|
2006-08-26 14:19:18 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
dircache_rename(oldpath, newpath);
|
|
|
|
#endif
|
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
if(oldpath[0] == '/') {
|
2007-11-08 10:15:44 +00:00
|
|
|
snprintf(buffer1, sizeof(buffer1), "%s%s", get_sim_rootdir(),
|
2007-04-12 22:38:54 +00:00
|
|
|
oldpath);
|
2007-11-08 10:15:44 +00:00
|
|
|
snprintf(buffer2, sizeof(buffer2), "%s%s", get_sim_rootdir(),
|
2007-04-12 22:38:54 +00:00
|
|
|
newpath);
|
2003-01-15 11:38:03 +00:00
|
|
|
|
2003-03-05 22:59:36 +00:00
|
|
|
debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2);
|
2007-04-19 20:17:24 +00:00
|
|
|
return RENAME(buffer1, buffer2);
|
2003-03-05 22:59:36 +00:00
|
|
|
}
|
|
|
|
return -1;
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
2003-01-15 11:38:03 +00:00
|
|
|
}
|
|
|
|
|
2005-02-28 18:32:57 +00:00
|
|
|
/* rockbox off_t may be different from system off_t */
|
|
|
|
long sim_lseek(int fildes, long offset, int whence)
|
|
|
|
{
|
|
|
|
return lseek(fildes, offset, whence);
|
|
|
|
}
|
|
|
|
|
|
|
|
long sim_filesize(int fd)
|
2003-03-18 00:39:57 +00:00
|
|
|
{
|
2005-03-09 19:26:59 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
return _filelength(fd);
|
|
|
|
#else
|
|
|
|
struct stat buf;
|
2007-11-08 12:11:34 +00:00
|
|
|
|
2005-03-09 19:26:59 +00:00
|
|
|
if (!fstat(fd, &buf))
|
|
|
|
return buf.st_size;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
#endif
|
2003-03-18 00:39:57 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 20:53:32 +00:00
|
|
|
void fat_size(IF_MV2(int volume,) unsigned long* size, unsigned long* free)
|
2002-11-12 11:32:26 +00:00
|
|
|
{
|
2007-09-13 20:53:32 +00:00
|
|
|
#ifdef HAVE_MULTIVOLUME
|
|
|
|
if (volume != 0) {
|
|
|
|
debugf("io.c: fat_size(volume=%d); simulator only supports volume 0\n",
|
|
|
|
volume);
|
2007-11-08 12:11:34 +00:00
|
|
|
|
2007-09-13 20:53:32 +00:00
|
|
|
if (size) *size = 0;
|
|
|
|
if (free) *free = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-06-10 13:29:52 +00:00
|
|
|
#ifdef WIN32
|
2005-02-22 21:55:48 +00:00
|
|
|
long secperclus, bytespersec, free_clusters, num_clusters;
|
|
|
|
|
|
|
|
if (GetDiskFreeSpace(NULL, &secperclus, &bytespersec, &free_clusters,
|
|
|
|
&num_clusters)) {
|
|
|
|
if (size)
|
|
|
|
*size = num_clusters * secperclus / 2 * (bytespersec / 512);
|
|
|
|
if (free)
|
|
|
|
*free = free_clusters * secperclus / 2 * (bytespersec / 512);
|
|
|
|
}
|
2004-06-10 13:29:52 +00:00
|
|
|
#else
|
2002-11-12 11:32:26 +00:00
|
|
|
struct statfs fs;
|
|
|
|
|
|
|
|
if (!statfs(".", &fs)) {
|
2007-03-17 10:50:58 +00:00
|
|
|
DEBUGF("statfs: bsize=%d blocks=%ld free=%ld\n",
|
|
|
|
(int)fs.f_bsize, fs.f_blocks, fs.f_bfree);
|
2002-11-12 11:32:26 +00:00
|
|
|
if (size)
|
|
|
|
*size = fs.f_blocks * (fs.f_bsize / 1024);
|
|
|
|
if (free)
|
|
|
|
*free = fs.f_bfree * (fs.f_bsize / 1024);
|
|
|
|
}
|
2005-02-22 21:55:48 +00:00
|
|
|
#endif
|
2002-11-12 11:32:26 +00:00
|
|
|
else {
|
|
|
|
if (size)
|
|
|
|
*size = 0;
|
|
|
|
if (free)
|
|
|
|
*free = 0;
|
|
|
|
}
|
|
|
|
}
|
2005-02-22 12:19:12 +00:00
|
|
|
|
|
|
|
int sim_fsync(int fd)
|
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
return _commit(fd);
|
|
|
|
#else
|
|
|
|
return fsync(fd);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
/* sim-win32 */
|
2007-04-19 20:17:24 +00:00
|
|
|
#define dlopen(_x_, _y_) LoadLibraryW(UTF8_TO_OS(_x_))
|
2005-02-22 18:21:16 +00:00
|
|
|
#define dlsym(_x_, _y_) (void *)GetProcAddress(_x_, _y_)
|
2005-02-22 12:19:12 +00:00
|
|
|
#define dlclose(_x_) FreeLibrary(_x_)
|
|
|
|
#else
|
|
|
|
/* sim-x11 */
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
2006-06-17 09:42:16 +00:00
|
|
|
#define TEMP_CODEC_FILE "archos/_temp_codec%d.dll"
|
|
|
|
|
2007-11-02 17:43:37 +00:00
|
|
|
void *sim_codec_load_ram(char* codecptr, int size, void **pd)
|
2005-07-10 16:33:03 +00:00
|
|
|
{
|
2006-03-02 01:08:38 +00:00
|
|
|
void *hdr;
|
2006-06-17 09:42:16 +00:00
|
|
|
char path[MAX_PATH];
|
2005-07-10 16:33:03 +00:00
|
|
|
int fd;
|
2006-09-28 08:46:28 +00:00
|
|
|
int codec_count;
|
2005-07-10 16:33:03 +00:00
|
|
|
#ifdef WIN32
|
2007-04-12 22:38:54 +00:00
|
|
|
char buf[MAX_PATH];
|
2005-07-10 16:33:03 +00:00
|
|
|
#endif
|
|
|
|
|
2006-03-02 01:08:38 +00:00
|
|
|
*pd = NULL;
|
2006-01-18 00:05:14 +00:00
|
|
|
|
2007-11-08 12:11:34 +00:00
|
|
|
/* We have to create the dynamic link library file from ram so we
|
2006-09-28 08:46:28 +00:00
|
|
|
can simulate the codec loading. With voice and crossfade,
|
2007-11-08 12:11:34 +00:00
|
|
|
multiple codecs may be loaded at the same time, so we need
|
2006-09-28 08:46:28 +00:00
|
|
|
to find an unused filename */
|
|
|
|
for (codec_count = 0; codec_count < 10; codec_count++)
|
|
|
|
{
|
2007-04-12 22:38:54 +00:00
|
|
|
snprintf(path, sizeof(path), TEMP_CODEC_FILE, codec_count);
|
2006-09-28 08:46:28 +00:00
|
|
|
|
2007-04-19 20:17:24 +00:00
|
|
|
fd = OPEN(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU);
|
2006-09-28 08:46:28 +00:00
|
|
|
if (fd >= 0)
|
|
|
|
break; /* Created a file ok */
|
|
|
|
}
|
2007-02-01 23:08:15 +00:00
|
|
|
if (fd < 0)
|
2006-09-28 08:46:28 +00:00
|
|
|
{
|
2005-07-10 16:33:03 +00:00
|
|
|
DEBUGF("failed to open for write: %s\n", path);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-02 17:43:37 +00:00
|
|
|
if (write(fd, codecptr, size) != size) {
|
2005-07-10 16:33:03 +00:00
|
|
|
DEBUGF("write failed");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
close(fd);
|
2006-01-18 00:05:14 +00:00
|
|
|
|
2005-07-10 16:33:03 +00:00
|
|
|
/* Now load the library. */
|
2006-03-02 01:08:38 +00:00
|
|
|
*pd = dlopen(path, RTLD_NOW);
|
|
|
|
if (*pd == NULL) {
|
2007-11-08 12:11:34 +00:00
|
|
|
DEBUGF("failed to load %s\n", path);
|
2005-07-10 16:33:03 +00:00
|
|
|
#ifdef WIN32
|
2007-04-19 20:17:24 +00:00
|
|
|
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
|
|
|
|
buf, sizeof buf, NULL);
|
2005-07-10 16:33:03 +00:00
|
|
|
DEBUGF("dlopen(%s): %s\n", path, buf);
|
|
|
|
#else
|
|
|
|
DEBUGF("dlopen(%s): %s\n", path, dlerror());
|
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-03-02 01:08:38 +00:00
|
|
|
hdr = dlsym(*pd, "__header");
|
2006-01-18 00:05:14 +00:00
|
|
|
if (!hdr)
|
2006-03-02 01:08:38 +00:00
|
|
|
hdr = dlsym(*pd, "___header");
|
2005-07-10 16:33:03 +00:00
|
|
|
|
2006-01-18 00:05:14 +00:00
|
|
|
return hdr; /* maybe NULL if symbol not present */
|
2005-07-10 16:33:03 +00:00
|
|
|
}
|
|
|
|
|
2006-03-02 01:08:38 +00:00
|
|
|
void sim_codec_close(void *pd)
|
2005-07-10 16:33:03 +00:00
|
|
|
{
|
2006-03-02 01:08:38 +00:00
|
|
|
dlclose(pd);
|
2005-07-10 16:33:03 +00:00
|
|
|
}
|
|
|
|
|
2006-03-02 01:08:38 +00:00
|
|
|
void *sim_plugin_load(char *plugin, void **pd)
|
2005-02-22 12:19:12 +00:00
|
|
|
{
|
2006-03-02 01:08:38 +00:00
|
|
|
void *hdr;
|
2007-04-12 22:38:54 +00:00
|
|
|
char path[MAX_PATH];
|
2005-02-22 18:21:16 +00:00
|
|
|
#ifdef WIN32
|
2007-04-12 22:38:54 +00:00
|
|
|
char buf[MAX_PATH];
|
2005-02-22 18:21:16 +00:00
|
|
|
#endif
|
|
|
|
|
2007-04-12 22:38:54 +00:00
|
|
|
snprintf(path, sizeof(path), "archos%s", plugin);
|
|
|
|
|
2006-03-02 01:08:38 +00:00
|
|
|
*pd = NULL;
|
2006-01-16 23:20:58 +00:00
|
|
|
|
2006-03-02 01:08:38 +00:00
|
|
|
*pd = dlopen(path, RTLD_NOW);
|
|
|
|
if (*pd == NULL) {
|
2005-02-22 18:21:16 +00:00
|
|
|
DEBUGF("failed to load %s\n", plugin);
|
|
|
|
#ifdef WIN32
|
2007-04-19 20:17:24 +00:00
|
|
|
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
|
|
|
|
buf, sizeof(buf), NULL);
|
2005-02-22 18:21:16 +00:00
|
|
|
DEBUGF("dlopen(%s): %s\n", path, buf);
|
|
|
|
#else
|
|
|
|
DEBUGF("dlopen(%s): %s\n", path, dlerror());
|
|
|
|
#endif
|
2005-02-22 12:19:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-03-02 01:08:38 +00:00
|
|
|
hdr = dlsym(*pd, "__header");
|
2006-01-16 23:20:58 +00:00
|
|
|
if (!hdr)
|
2006-03-02 01:08:38 +00:00
|
|
|
hdr = dlsym(*pd, "___header");
|
2006-01-16 23:20:58 +00:00
|
|
|
|
|
|
|
return hdr; /* maybe NULL if symbol not present */
|
2005-02-22 12:19:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-02 01:08:38 +00:00
|
|
|
void sim_plugin_close(void *pd)
|
2005-02-22 12:19:12 +00:00
|
|
|
{
|
2006-03-02 01:08:38 +00:00
|
|
|
dlclose(pd);
|
2005-02-22 12:19:12 +00:00
|
|
|
}
|
|
|
|
|
2007-04-19 20:17:24 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
static unsigned old_cp;
|
|
|
|
|
|
|
|
void debug_exit(void)
|
|
|
|
{
|
|
|
|
/* Reset console output codepage */
|
|
|
|
SetConsoleOutputCP(old_cp);
|
|
|
|
}
|
2005-02-22 12:19:12 +00:00
|
|
|
|
2007-04-19 20:17:24 +00:00
|
|
|
void debug_init(void)
|
|
|
|
{
|
|
|
|
old_cp = GetConsoleOutputCP();
|
|
|
|
/* Set console output codepage to UTF8. Only works
|
|
|
|
* correctly when the console uses a truetype font. */
|
|
|
|
SetConsoleOutputCP(65001);
|
|
|
|
atexit(debug_exit);
|
|
|
|
}
|
|
|
|
#else
|
2005-02-22 12:19:12 +00:00
|
|
|
void debug_init(void)
|
|
|
|
{
|
|
|
|
/* nothing to be done */
|
|
|
|
}
|
2007-04-19 20:17:24 +00:00
|
|
|
#endif
|
2005-02-22 12:19:12 +00:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2005-03-05 21:48:58 +00:00
|
|
|
/* rockbox off_t may be different from system off_t */
|
|
|
|
int sim_ftruncate(int fd, long length)
|
2005-02-22 12:19:12 +00:00
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
return _chsize(fd, length);
|
|
|
|
#else
|
|
|
|
return ftruncate(fd, length);
|
|
|
|
#endif
|
|
|
|
}
|