22 #include <sys/times.h>
24 #include <sys/types.h>
34 #define NEWLIB_PORT_AWARE
41 extern void *
ps2_sbrk(
size_t increment);
60 tim.tm_sec = ps2time[1];
61 tim.tm_min = ps2time[2];
62 tim.tm_hour = ps2time[3];
63 tim.tm_mday = ps2time[4];
64 tim.tm_mon = ps2time[5] - 1;
65 tim.tm_year = ((
u16)ps2time[6] | ((
u16)ps2time[7] << 8)) - 1900;
74 if (ps2mode &
FIO_SO_IROTH) posixmode |= S_IRUSR|S_IRGRP|S_IROTH;
75 if (ps2mode &
FIO_SO_IWOTH) posixmode |= S_IWUSR|S_IWGRP|S_IWOTH;
76 if (ps2mode &
FIO_SO_IXOTH) posixmode |= S_IXUSR|S_IXGRP|S_IXOTH;
89 stat->st_size = ((off_t)fiostat->
hisize << 32) | (off_t)fiostat->
size;
93 stat->st_blksize = 16*1024;
94 stat->st_blocks = stat->st_size / 512;
121 dir = malloc(
sizeof(DIR));
123 dir->dd_buf = malloc(
sizeof(
struct dirent));
139 de = (
struct dirent *)dir->dd_buf;
146 strncpy(de->d_name, fiode.
name, 255);
154 printf(
"rewinddir not implemented\n");
190 #define IOP_O_RDONLY 0x0001
191 #define IOP_O_WRONLY 0x0002
192 #define IOP_O_RDWR 0x0003
193 #define IOP_O_DIROPEN 0x0008
194 #define IOP_O_NBLOCK 0x0010
195 #define IOP_O_APPEND 0x0100
196 #define IOP_O_CREAT 0x0200
197 #define IOP_O_TRUNC 0x0400
198 #define IOP_O_EXCL 0x0800
199 #define IOP_O_NOWAIT 0x8000
201 #if INT_MAX != 0x7fffffffL
202 #error "INT_MAX != 0x7fffffffL"
205 #error "LONG_MAX not defined"
207 #if LONG_MAX != 0x7fffffffL
208 #error "LONG_MAX != 0x7fffffffL"
211 #define ct_assert(e) {enum { ct_assert_value = 1/(!!(e)) };}
218 ct_assert(
sizeof(
unsigned long long)==8);
219 ct_assert(
sizeof(
unsigned int __attribute__((
mode(TI) )))==16);
241 static char out[255];
244 strcpy(out, path_name);
249 for(i=0; out[i+1]; i++) {
250 if(out[i]==
'/' && out[i+1]==
'/') {
251 for(j=i+1; out[j]; j++)
258 for(i=0; out[i] && out[i+1] && out[i+2]; i++) {
259 if(out[i]==
'/' && out[i+1]==
'.' && out[i+2]==
'/') {
260 for(j=i+1; out[j]; j++)
271 if(out[next+1] && out[next+1]==
'.' &&
272 out[next+2] && out[next+2]==
'.' &&
273 out[next+3] && out[next+3]==
'/') {
274 for(j=0; out[first+j+1]; j++)
275 out[first+j+1] = out[next+j+4];
282 for(next=first+1; out[next] && out[next] !=
'/'; next++)
284 if(!out[next])
break;
288 for(i=1; out[i]; i++)
290 if(i >= 1 && out[i-1] ==
'/')
298 return !strncmp(path,
"cdrom0:", 7) || !strncmp(path,
"cdrom:", 6);
301 int _open(
const char *buf,
int flags, ...) {
307 if ((flags & 3) == O_RDWR ) iop_flags |=
IOP_O_RDWR;
316 char b_fname[FILENAME_MAX];
318 if (!strchr(buf,
':')) {
320 if (buf[0] ==
'/' || buf[0] ==
'\\') {
326 strcpy(b_fname,
"host:");
327 strcpy(b_fname + 5, buf);
332 strcpy(b_fname,
"host:");
336 b_fname[b_fname_len + 5] =
'\\';
339 b_fname[b_fname_len + 5] =
'/';
344 strcpy(b_fname + b_fname_len, buf);
348 if (!(b_fname[b_fname_len - 1] ==
'/' || b_fname[b_fname_len - 1] ==
'\\')) {
350 b_fname[b_fname_len] =
'\\';
353 b_fname[b_fname_len] =
'/';
357 strcpy(b_fname + b_fname_len, buf);
370 int _read(
int fd,
void *buf,
size_t nbytes) {
374 int _write(
int fd,
const void *buf,
size_t nbytes) {
383 if (fd >=0 && fd <= 1) {
385 buf->st_mode = S_IFCHR;
390 buf->st_mode = S_IFBLK;
391 buf->st_blksize = 16*1024;
397 int _stat(
const char *path,
struct stat *buf) {
405 if (
s.st_mode & S_IFDIR)
408 if (
s.st_mode & S_IWRITE)
438 if (
_fstat (fd, &buf) < 0) {
442 if (S_ISCHR (buf.st_mode))
448 off_t
_lseek(
int fd, off_t offset,
int whence)
474 int _link(
const char *old,
const char *
new) {
495 return pid == getpid() ? 0 : -1;
497 if (pid == getpid()) {
517 time_t
time(time_t *t) __attribute__((weak));
520 printf(
"ERROR: include libcdvd when using the time function\n");
534 tz->tz_minuteswest = 0;
539 tv->tv_sec =
time(0);
int fioRmdir(const char *dirname)
int fioWrite(int fd, const void *buff, int buff_size)
int fioRead(int fd, void *buff, int buff_size)
int fioMkdir(const char *dirname)
int fioGetstat(const char *name, io_stat_t *buf)
int fioRemove(const char *name)
int fioIoctl(int fd, int request, void *data)
int fioDopen(const char *name)
int fioDread(int fd, io_dirent_t *buf)
int fioLseek(int fd, int offset, int whence)
int fioOpen(const char *fname, int mode)
void ExitDeleteThread(void)
DIR *(* _ps2sdk_opendir)(const char *path)
int(* _ps2sdk_stat)(const char *path, struct stat *buf)
int chdir(const char *path)
int _kill(int pid, int sig)
int _open(const char *buf, int flags,...)
int _fstat(int fd, struct stat *buf)
void(* _ps2sdk_rewinddir)(DIR *dir)
int _unlink(const char *path)
static int isCdromPath(const char *path)
static void fill_stat(struct stat *stat, const io_stat_t *fiostat)
clock_t _times(struct tms *buffer)
int _stat(const char *path, struct stat *buf)
int64_t(* _ps2sdk_lseek64)(int, int64_t, int)
int(* _ps2sdk_closedir)(DIR *dir)
int _link(const char *old, const char *new)
int(* _ps2sdk_lseek)(int, int, int)
void * _sbrk(size_t incr)
int mkdir(const char *path, mode_t mode)
int(* _ps2sdk_write)(int, const void *, int)
int fioMkdirHelper(const char *path, int mode)
static void fioRewinddirHelper(DIR *dir)
int(* _ps2sdk_close)(int)
off_t _lseek(int fd, off_t offset, int whence)
off64_t lseek64(int fd, off64_t offset, int whence)
int access(const char *fn, int flags)
int _read(int fd, void *buf, size_t nbytes)
static int fioGetstatHelper(const char *path, struct stat *buf)
int _gettimeofday(struct timeval *tv, struct timezone *tz)
char * getcwd(char *buf, size_t len)
int(* _ps2sdk_ioctl)(int, int, void *)
static struct dirent * fioReaddirHelper(DIR *dir)
static mode_t io_to_posix_mode(unsigned int ps2mode)
int(* _ps2sdk_remove)(const char *)
int rmdir(const char *path)
void * ps2_sbrk(size_t increment)
int(* _ps2sdk_rename)(const char *, const char *)
static char * normalize_path(const char *path_name)
static int fioClosedirHelper(DIR *dir)
struct dirent * readdir(DIR *dir)
int fioRename(const char *old, const char *new)
static DIR * fioOpendirHelper(const char *path)
struct dirent *(* _ps2sdk_readdir)(DIR *dir)
int(* _ps2sdk_read)(int, void *, int)
static time_t io_to_posix_time(const unsigned char *ps2time)
int(* _ps2sdk_mkdir)(const char *, int)
void srandom(unsigned int seed)
void compile_time_check()
int(* _ps2sdk_rmdir)(const char *)
int(* _ps2sdk_open)(const char *, int,...)
DIR * opendir(const char *path)
int _write(int fd, const void *buf, size_t nbytes)
#define PS2_CLOCKS_PER_SEC
ps2_clock_t ps2_clock(void)