ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
ps2sdkapi.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <string.h>
#include <kernel.h>
#include <malloc.h>
#include <sio.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdint.h>
#include <limits.h>
#include <inttypes.h>
#include <tamtypes.h>
#include "fileio.h"
#include "io_common.h"
#include "iox_stat.h"
#include "ps2sdkapi.h"
+ Include dependency graph for ps2sdkapi.c:

Go to the source code of this file.

Macros

#define NEWLIB_PORT_AWARE
 
#define IOP_O_RDONLY   0x0001
 
#define IOP_O_WRONLY   0x0002
 
#define IOP_O_RDWR   0x0003
 
#define IOP_O_DIROPEN   0x0008
 
#define IOP_O_NBLOCK   0x0010
 
#define IOP_O_APPEND   0x0100
 
#define IOP_O_CREAT   0x0200
 
#define IOP_O_TRUNC   0x0400
 
#define IOP_O_EXCL   0x0800
 
#define IOP_O_NOWAIT   0x8000
 
#define ct_assert(e)   {enum { ct_assert_value = 1/(!!(e)) };}
 

Functions

void * ps2_sbrk (size_t increment)
 
int fioRename (const char *old, const char *new)
 
int fioMkdirHelper (const char *path, int mode)
 
static time_t io_to_posix_time (const unsigned char *ps2time)
 
static mode_t io_to_posix_mode (unsigned int ps2mode)
 
static void fill_stat (struct stat *stat, const io_stat_t *fiostat)
 
static int fioGetstatHelper (const char *path, struct stat *buf)
 
static DIR * fioOpendirHelper (const char *path)
 
static struct dirent * fioReaddirHelper (DIR *dir)
 
static void fioRewinddirHelper (DIR *dir)
 
static int fioClosedirHelper (DIR *dir)
 
void compile_time_check ()
 
static char * normalize_path (const char *path_name)
 
static int isCdromPath (const char *path)
 
int _open (const char *buf, int flags,...)
 
int _close (int fd)
 
int _read (int fd, void *buf, size_t nbytes)
 
int _write (int fd, const void *buf, size_t nbytes)
 
int _fstat (int fd, struct stat *buf)
 
int _stat (const char *path, struct stat *buf)
 
int access (const char *fn, int flags)
 
DIR * opendir (const char *path)
 
struct dirent * readdir (DIR *dir)
 
void rewinddir (DIR *dir)
 
int closedir (DIR *dir)
 
int _isatty (int fd)
 
off_t _lseek (int fd, off_t offset, int whence)
 
off64_t lseek64 (int fd, off64_t offset, int whence)
 
int chdir (const char *path)
 
int mkdir (const char *path, mode_t mode)
 
int rmdir (const char *path)
 
int _link (const char *old, const char *new)
 
int _unlink (const char *path)
 
char * getcwd (char *buf, size_t len)
 
int _getpid (void)
 
int _kill (int pid, int sig)
 
void * _sbrk (size_t incr)
 
time_t time (time_t *t)
 
int _gettimeofday (struct timeval *tv, struct timezone *tz)
 
clock_t _times (struct tms *buffer)
 
long int random (void)
 
void srandom (unsigned int seed)
 

Variables

char __direct_pwd [256] = ""
 
int(* _ps2sdk_close )(int) = fioClose
 
int(* _ps2sdk_open )(const char *, int,...) = (void *)fioOpen
 
int(* _ps2sdk_read )(int, void *, int) = fioRead
 
int(* _ps2sdk_lseek )(int, int, int) = fioLseek
 
int64_t(* _ps2sdk_lseek64 )(int, int64_t, int) = NULL
 
int(* _ps2sdk_write )(int, const void *, int) = fioWrite
 
int(* _ps2sdk_ioctl )(int, int, void *) = fioIoctl
 
int(* _ps2sdk_remove )(const char *) = fioRemove
 
int(* _ps2sdk_rename )(const char *, const char *) = fioRename
 
int(* _ps2sdk_mkdir )(const char *, int) = fioMkdirHelper
 
int(* _ps2sdk_rmdir )(const char *) = fioRmdir
 
int(* _ps2sdk_stat )(const char *path, struct stat *buf) = fioGetstatHelper
 
DIR *(* _ps2sdk_opendir )(const char *path) = fioOpendirHelper
 
struct dirent *(* _ps2sdk_readdir )(DIR *dir) = fioReaddirHelper
 
void(* _ps2sdk_rewinddir )(DIR *dir) = fioRewinddirHelper
 
int(* _ps2sdk_closedir )(DIR *dir) = fioClosedirHelper
 

Macro Definition Documentation

◆ ct_assert

#define ct_assert (   e)    {enum { ct_assert_value = 1/(!!(e)) };}

Definition at line 211 of file ps2sdkapi.c.

◆ IOP_O_APPEND

#define IOP_O_APPEND   0x0100

Definition at line 195 of file ps2sdkapi.c.

◆ IOP_O_CREAT

#define IOP_O_CREAT   0x0200

Definition at line 196 of file ps2sdkapi.c.

◆ IOP_O_DIROPEN

#define IOP_O_DIROPEN   0x0008

Definition at line 193 of file ps2sdkapi.c.

◆ IOP_O_EXCL

#define IOP_O_EXCL   0x0800

Definition at line 198 of file ps2sdkapi.c.

◆ IOP_O_NBLOCK

#define IOP_O_NBLOCK   0x0010

Definition at line 194 of file ps2sdkapi.c.

◆ IOP_O_NOWAIT

#define IOP_O_NOWAIT   0x8000

Definition at line 199 of file ps2sdkapi.c.

◆ IOP_O_RDONLY

#define IOP_O_RDONLY   0x0001

Definition at line 190 of file ps2sdkapi.c.

◆ IOP_O_RDWR

#define IOP_O_RDWR   0x0003

Definition at line 192 of file ps2sdkapi.c.

◆ IOP_O_TRUNC

#define IOP_O_TRUNC   0x0400

Definition at line 197 of file ps2sdkapi.c.

◆ IOP_O_WRONLY

#define IOP_O_WRONLY   0x0002

Definition at line 191 of file ps2sdkapi.c.

◆ NEWLIB_PORT_AWARE

#define NEWLIB_PORT_AWARE

Definition at line 34 of file ps2sdkapi.c.

Function Documentation

◆ _close()

int _close ( int  fd)

Definition at line 366 of file ps2sdkapi.c.

366  {
367  return _ps2sdk_close(fd);
368 }
int(* _ps2sdk_close)(int)
Definition: ps2sdkapi.c:171

References _ps2sdk_close.

◆ _fstat()

int _fstat ( int  fd,
struct stat *  buf 
)

Definition at line 382 of file ps2sdkapi.c.

382  {
383  if (fd >=0 && fd <= 1) {
384  // Character device
385  buf->st_mode = S_IFCHR;
386  buf->st_blksize = 0;
387  }
388  else {
389  // Block device
390  buf->st_mode = S_IFBLK;
391  buf->st_blksize = 16*1024;
392  }
393 
394  return 0;
395 }

Referenced by _isatty().

◆ _getpid()

int _getpid ( void  )

Definition at line 487 of file ps2sdkapi.c.

487  {
488  return GetThreadId();
489 }
s32 GetThreadId(void)

References GetThreadId().

◆ _gettimeofday()

int _gettimeofday ( struct timeval *  tv,
struct timezone *  tz 
)

Definition at line 531 of file ps2sdkapi.c.

531  {
532  if (tz) {
533  /* Timezone not supported for gettimeofday */
534  tz->tz_minuteswest = 0;
535  tz->tz_dsttime = 0;
536  }
537 
538  tv->tv_usec = 0;
539  tv->tv_sec = time(0);
540 
541  return 0;
542 }
time_t time(time_t *t)
Definition: ps2sdkapi.c:518

References time().

◆ _isatty()

int _isatty ( int  fd)

Definition at line 435 of file ps2sdkapi.c.

435  {
436  struct stat buf;
437 
438  if (_fstat (fd, &buf) < 0) {
439  //errno = EBADF;
440  return 0;
441  }
442  if (S_ISCHR (buf.st_mode))
443  return 1;
444  //errno = ENOTTY;
445  return 0;
446 }
int _fstat(int fd, struct stat *buf)
Definition: ps2sdkapi.c:382

References _fstat().

◆ _kill()

int _kill ( int  pid,
int  sig 
)

Definition at line 491 of file ps2sdkapi.c.

491  {
492 #if 0 // needs to be tested first
493  // null signal: do error checking on pid only
494  if (sig == 0)
495  return pid == getpid() ? 0 : -1;
496 
497  if (pid == getpid()) {
499  // NOTE: ExitDeleteThread does not return
500  return 0;
501  }
502 #endif
503  // FIXME: set errno
504  return -1;
505 }
void ExitDeleteThread(void)

References ExitDeleteThread().

◆ _link()

int _link ( const char *  old,
const char *  new 
)

Definition at line 474 of file ps2sdkapi.c.

474  {
475  return _ps2sdk_rename(old, new);
476 }
int(* _ps2sdk_rename)(const char *, const char *)
Definition: ps2sdkapi.c:179

References _ps2sdk_rename.

◆ _lseek()

off_t _lseek ( int  fd,
off_t  offset,
int  whence 
)

Definition at line 448 of file ps2sdkapi.c.

449 {
450  return _ps2sdk_lseek(fd, offset, whence);
451 }
int(* _ps2sdk_lseek)(int, int, int)
Definition: ps2sdkapi.c:174

References _ps2sdk_lseek.

◆ _open()

int _open ( const char *  buf,
int  flags,
  ... 
)

Definition at line 301 of file ps2sdkapi.c.

301  {
302  int iop_flags = 0;
303 
304  // newlib frags differ from iop flags
305  if ((flags & 3) == O_RDONLY) iop_flags |= IOP_O_RDONLY;
306  if ((flags & 3) == O_WRONLY) iop_flags |= IOP_O_WRONLY;
307  if ((flags & 3) == O_RDWR ) iop_flags |= IOP_O_RDWR;
308  if (flags & O_NONBLOCK) iop_flags |= IOP_O_NBLOCK;
309  if (flags & O_APPEND) iop_flags |= IOP_O_APPEND;
310  if (flags & O_CREAT) iop_flags |= IOP_O_CREAT;
311  if (flags & O_TRUNC) iop_flags |= IOP_O_TRUNC;
312  if (flags & O_EXCL) iop_flags |= IOP_O_EXCL;
313  //if (flags & O_???) iop_flags |= IOP_O_NOWAIT;
314 
315  char *t_fname = normalize_path(buf);
316  char b_fname[FILENAME_MAX];
317 
318  if (!strchr(buf, ':')) { // filename doesn't contain device
319  t_fname = b_fname;
320  if (buf[0] == '/' || buf[0] == '\\') { // does it contain root ?
321  char *device_end = strchr(__direct_pwd, ':');
322  if (device_end) { // yes, let's strip pwd a bit to keep device only
323  strncpy(b_fname, __direct_pwd, device_end - __direct_pwd);
324  strcpy(b_fname + (device_end - __direct_pwd), buf);
325  } else { // but pwd doesn't contain any device, let's default to host
326  strcpy(b_fname, "host:");
327  strcpy(b_fname + 5, buf);
328  }
329  } else { // otherwise, it's relative directory, let's copy pwd straight
330  int b_fname_len = strlen(__direct_pwd);
331  if (!strchr(__direct_pwd, ':')) { // check if pwd contains device name
332  strcpy(b_fname, "host:");
333  strcpy(b_fname + 5, __direct_pwd);
334  if (!(__direct_pwd[b_fname_len - 1] == '/' || __direct_pwd[b_fname_len - 1] == '\\')) { // does it has trailing slash ?
335  if(isCdromPath(b_fname)) {
336  b_fname[b_fname_len + 5] = '\\';
337  b_fname_len++;
338  } else {
339  b_fname[b_fname_len + 5] = '/';
340  b_fname_len++;
341  }
342  }
343  b_fname_len += 5;
344  strcpy(b_fname + b_fname_len, buf);
345  } else { // device name is here
346  if (b_fname_len) {
347  strcpy(b_fname, __direct_pwd);
348  if (!(b_fname[b_fname_len - 1] == '/' || b_fname[b_fname_len - 1] == '\\')) {
349  if(isCdromPath(b_fname)) {
350  b_fname[b_fname_len] = '\\';
351  b_fname_len++;
352  } else {
353  b_fname[b_fname_len] = '/';
354  b_fname_len++;
355  }
356  }
357  strcpy(b_fname + b_fname_len, buf);
358  }
359  }
360  }
361  }
362 
363  return _ps2sdk_open(t_fname, iop_flags);
364 }
#define IOP_O_WRONLY
Definition: ps2sdkapi.c:191
#define IOP_O_CREAT
Definition: ps2sdkapi.c:196
static int isCdromPath(const char *path)
Definition: ps2sdkapi.c:296
#define IOP_O_TRUNC
Definition: ps2sdkapi.c:197
#define IOP_O_RDONLY
Definition: ps2sdkapi.c:190
#define IOP_O_NBLOCK
Definition: ps2sdkapi.c:194
#define IOP_O_EXCL
Definition: ps2sdkapi.c:198
char __direct_pwd[256]
Definition: ps2sdkapi.c:45
#define IOP_O_APPEND
Definition: ps2sdkapi.c:195
static char * normalize_path(const char *path_name)
Definition: ps2sdkapi.c:237
#define IOP_O_RDWR
Definition: ps2sdkapi.c:192
int(* _ps2sdk_open)(const char *, int,...)
Definition: ps2sdkapi.c:172
#define O_NONBLOCK
Definition: tcpip.h:1574

References __direct_pwd, _ps2sdk_open, IOP_O_APPEND, IOP_O_CREAT, IOP_O_EXCL, IOP_O_NBLOCK, IOP_O_RDONLY, IOP_O_RDWR, IOP_O_TRUNC, IOP_O_WRONLY, isCdromPath(), normalize_path(), and O_NONBLOCK.

◆ _read()

int _read ( int  fd,
void *  buf,
size_t  nbytes 
)

Definition at line 370 of file ps2sdkapi.c.

370  {
371  return _ps2sdk_read(fd, buf, nbytes);
372 }
int(* _ps2sdk_read)(int, void *, int)
Definition: ps2sdkapi.c:173

References _ps2sdk_read.

◆ _sbrk()

void* _sbrk ( size_t  incr)

Definition at line 507 of file ps2sdkapi.c.

507  {
508  return ps2_sbrk(incr);
509 }
void * ps2_sbrk(size_t increment)
Definition: sbrk.c:22

References ps2_sbrk().

◆ _stat()

int _stat ( const char *  path,
struct stat *  buf 
)

Definition at line 397 of file ps2sdkapi.c.

397  {
398  return _ps2sdk_stat(path, buf);
399 }
int(* _ps2sdk_stat)(const char *path, struct stat *buf)
Definition: ps2sdkapi.c:183

References _ps2sdk_stat.

◆ _times()

clock_t _times ( struct tms *  buffer)

Definition at line 544 of file ps2sdkapi.c.

544  {
545  clock_t clk = ps2_clock() / (PS2_CLOCKS_PER_SEC / CLOCKS_PER_SEC);
546 
547  if (buffer != NULL) {
548  buffer->tms_utime = clk;
549  buffer->tms_stime = 0;
550  buffer->tms_cutime = clk;
551  buffer->tms_cstime = 0;
552  }
553 
554  return clk;
555 }
#define PS2_CLOCKS_PER_SEC
Definition: ps2sdkapi.h:38
ps2_clock_t ps2_clock(void)
u8 buffer[128]
Definition: rpc_client.c:19
#define NULL
Definition: tamtypes.h:91

References buffer, NULL, ps2_clock(), and PS2_CLOCKS_PER_SEC.

◆ _unlink()

int _unlink ( const char *  path)

Definition at line 478 of file ps2sdkapi.c.

478  {
479  return _ps2sdk_remove(path);
480 }
int(* _ps2sdk_remove)(const char *)
Definition: ps2sdkapi.c:178

References _ps2sdk_remove.

◆ _write()

int _write ( int  fd,
const void *  buf,
size_t  nbytes 
)

Definition at line 374 of file ps2sdkapi.c.

374  {
375  // HACK: stdout and strerr to serial
376  //if ((fd==1) || (fd==2))
377  // return sio_write((void *)buf, nbytes);
378 
379  return _ps2sdk_write(fd, buf, nbytes);
380 }
int(* _ps2sdk_write)(int, const void *, int)
Definition: ps2sdkapi.c:176

References _ps2sdk_write.

◆ access()

int access ( const char *  fn,
int  flags 
)

Definition at line 401 of file ps2sdkapi.c.

401  {
402  struct stat s;
403  if (stat(fn, &s))
404  return -1;
405  if (s.st_mode & S_IFDIR)
406  return 0;
407  if (flags & W_OK) {
408  if (s.st_mode & S_IWRITE)
409  return 0;
410  return -1;
411  }
412  return 0;
413 }
s32 s
Definition: ps2ipc.c:30

References s.

◆ chdir()

int chdir ( const char *  path)

Definition at line 461 of file ps2sdkapi.c.

461  {
462  strcpy(__direct_pwd, path);
463  return 0;
464 }

References __direct_pwd.

◆ closedir()

int closedir ( DIR *  dir)

Definition at line 430 of file ps2sdkapi.c.

431 {
432  return _ps2sdk_closedir(dir);
433 }
int(* _ps2sdk_closedir)(DIR *dir)
Definition: ps2sdkapi.c:188

References _ps2sdk_closedir.

◆ compile_time_check()

void compile_time_check ( )

Definition at line 212 of file ps2sdkapi.c.

212  {
213  // Compiler (ABI n32)
214  ct_assert(sizeof(unsigned char)==1);
215  ct_assert(sizeof(unsigned short)==2);
216  ct_assert(sizeof(unsigned int)==4);
217  ct_assert(sizeof(unsigned long)==4);
218  ct_assert(sizeof(unsigned long long)==8);
219  ct_assert(sizeof(unsigned int __attribute__(( mode(TI) )))==16);
220  ct_assert(sizeof(void *)==4);
221 
222  // Defined in tamtypes.h (ps2sdk)
223  ct_assert(sizeof(u8)==1);
224  ct_assert(sizeof(u16)==2);
225  ct_assert(sizeof(u32)==4);
226  ct_assert(sizeof(u64)==8);
227  ct_assert(sizeof(u128)==16);
228 
229  // Defined in inttypes.h/stdint.h (newlib)
230  ct_assert(sizeof(uint8_t)==1);
231  ct_assert(sizeof(uint16_t)==2);
232  ct_assert(sizeof(uint32_t)==4);
233  ct_assert(sizeof(uint64_t)==8);
234 }
#define ct_assert(e)
Definition: ps2sdkapi.c:211
s32 mode
Definition: rpc_client.c:15
unsigned int u32
Definition: tamtypes.h:30
unsigned int u128
Definition: tamtypes.h:36
unsigned short u16
Definition: tamtypes.h:24
unsigned char u8
Definition: tamtypes.h:23
unsigned long u64
Definition: tamtypes.h:34

References ct_assert, and mode.

◆ fill_stat()

static void fill_stat ( struct stat *  stat,
const io_stat_t fiostat 
)
static

Definition at line 80 of file ps2sdkapi.c.

81 {
82  stat->st_dev = 0;
83  stat->st_ino = 0;
84  stat->st_mode = io_to_posix_mode(fiostat->mode);
85  stat->st_nlink = 0;
86  stat->st_uid = 0;
87  stat->st_gid = 0;
88  stat->st_rdev = 0;
89  stat->st_size = ((off_t)fiostat->hisize << 32) | (off_t)fiostat->size;
90  stat->st_atime = io_to_posix_time(fiostat->atime);
91  stat->st_mtime = io_to_posix_time(fiostat->mtime);
92  stat->st_ctime = io_to_posix_time(fiostat->ctime);
93  stat->st_blksize = 16*1024;
94  stat->st_blocks = stat->st_size / 512;
95 }
static mode_t io_to_posix_mode(unsigned int ps2mode)
Definition: ps2sdkapi.c:69
static time_t io_to_posix_time(const unsigned char *ps2time)
Definition: ps2sdkapi.c:57
unsigned char atime[8]
Definition: io_common.h:52
unsigned int size
Definition: io_common.h:50
unsigned int mode
Definition: io_common.h:48
unsigned char ctime[8]
Definition: io_common.h:51
unsigned int hisize
Definition: io_common.h:54
unsigned char mtime[8]
Definition: io_common.h:53

References io_stat_t::atime, io_stat_t::ctime, io_stat_t::hisize, io_to_posix_mode(), io_to_posix_time(), io_stat_t::mode, io_stat_t::mtime, and io_stat_t::size.

Referenced by fioGetstatHelper(), and fioReaddirHelper().

◆ fioClosedirHelper()

static int fioClosedirHelper ( DIR *  dir)
static

Definition at line 157 of file ps2sdkapi.c.

158 {
159  if(dir == NULL) {
160  //errno = EBADF;
161  return -1;
162  }
163 
164  fioDclose(dir->dd_fd); // Check return value?
165  free(dir->dd_buf);
166  free(dir);
167 
168  return 0;
169 }
int fioDclose(int fd)

References fioDclose(), and NULL.

◆ fioGetstatHelper()

static int fioGetstatHelper ( const char *  path,
struct stat *  buf 
)
static

Definition at line 97 of file ps2sdkapi.c.

97  {
98  io_stat_t fiostat;
99 
100  if (fioGetstat(path, &fiostat) < 0) {
101  //errno = ENOENT;
102  return -1;
103  }
104 
105  fill_stat(buf, &fiostat);
106 
107  return 0;
108 }
int fioGetstat(const char *name, io_stat_t *buf)
static void fill_stat(struct stat *stat, const io_stat_t *fiostat)
Definition: ps2sdkapi.c:80

References fill_stat(), and fioGetstat().

◆ fioMkdirHelper()

int fioMkdirHelper ( const char *  path,
int  mode 
)

Definition at line 52 of file ps2sdkapi.c.

52  {
53  // Old fio mkdir has no mode argument
54  return fioMkdir(path);
55 }
int fioMkdir(const char *dirname)

References fioMkdir().

◆ fioOpendirHelper()

static DIR* fioOpendirHelper ( const char *  path)
static

Definition at line 110 of file ps2sdkapi.c.

111 {
112  int dd;
113  DIR *dir;
114 
115  dd = fioDopen(path);
116  if (dd < 0) {
117  //errno = ENOENT;
118  return NULL;
119  }
120 
121  dir = malloc(sizeof(DIR));
122  dir->dd_fd = dd;
123  dir->dd_buf = malloc(sizeof(struct dirent));
124 
125  return dir;
126 }
int fioDopen(const char *name)

References fioDopen(), and NULL.

◆ fioReaddirHelper()

static struct dirent* fioReaddirHelper ( DIR *  dir)
static

Definition at line 128 of file ps2sdkapi.c.

129 {
130  int rv;
131  struct dirent *de;
132  io_dirent_t fiode;
133 
134  if(dir == NULL) {
135  //errno = EBADF;
136  return NULL;
137  }
138 
139  de = (struct dirent *)dir->dd_buf;
140  rv = fioDread(dir->dd_fd, &fiode);
141  if (rv <= 0) {
142  return NULL;
143  }
144 
145  fill_stat(&de->d_stat, &fiode.stat);
146  strncpy(de->d_name, fiode.name, 255);
147  de->d_name[255] = 0;
148 
149  return de;
150 }
int fioDread(int fd, io_dirent_t *buf)
char name[256]
Definition: io_common.h:59
io_stat_t stat
Definition: io_common.h:58

References fill_stat(), fioDread(), io_dirent_t::name, NULL, and io_dirent_t::stat.

◆ fioRename()

int fioRename ( const char *  old,
const char *  new 
)

Definition at line 48 of file ps2sdkapi.c.

48  {
49  return -ENOSYS;
50 }
#define ENOSYS
Definition: errno.h:180

References ENOSYS.

◆ fioRewinddirHelper()

static void fioRewinddirHelper ( DIR *  dir)
static

Definition at line 152 of file ps2sdkapi.c.

153 {
154  printf("rewinddir not implemented\n");
155 }

◆ getcwd()

char* getcwd ( char *  buf,
size_t  len 
)

Definition at line 482 of file ps2sdkapi.c.

482  {
483  strncpy(buf, __direct_pwd, len);
484  return buf;
485 }

References __direct_pwd.

◆ io_to_posix_mode()

static mode_t io_to_posix_mode ( unsigned int  ps2mode)
static

Definition at line 69 of file ps2sdkapi.c.

70 {
71  mode_t posixmode = 0;
72  if (ps2mode & FIO_SO_IFREG) posixmode |= S_IFREG;
73  if (ps2mode & FIO_SO_IFDIR) posixmode |= S_IFDIR;
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;
77  return posixmode;
78 }
#define FIO_SO_IFDIR
Definition: iox_stat.h:126
#define FIO_SO_IXOTH
Definition: iox_stat.h:133
#define FIO_SO_IWOTH
Definition: iox_stat.h:131
#define FIO_SO_IFREG
Definition: iox_stat.h:124
#define FIO_SO_IROTH
Definition: iox_stat.h:129

References FIO_SO_IFDIR, FIO_SO_IFREG, FIO_SO_IROTH, FIO_SO_IWOTH, and FIO_SO_IXOTH.

Referenced by fill_stat().

◆ io_to_posix_time()

static time_t io_to_posix_time ( const unsigned char *  ps2time)
static

Definition at line 57 of file ps2sdkapi.c.

58 {
59  struct tm tim;
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;
66  return mktime(&tim);
67 }

Referenced by fill_stat().

◆ isCdromPath()

static int isCdromPath ( const char *  path)
static

Definition at line 296 of file ps2sdkapi.c.

297 {
298  return !strncmp(path, "cdrom0:", 7) || !strncmp(path, "cdrom:", 6);
299 }

Referenced by _open().

◆ lseek64()

off64_t lseek64 ( int  fd,
off64_t  offset,
int  whence 
)

Definition at line 453 of file ps2sdkapi.c.

454 {
455  if (_ps2sdk_lseek64 == NULL)
456  return EOVERFLOW;
457 
458  return _ps2sdk_lseek64(fd, offset, whence);
459 }
#define EOVERFLOW
Definition: errno.h:257
int64_t(* _ps2sdk_lseek64)(int, int64_t, int)
Definition: ps2sdkapi.c:175

References _ps2sdk_lseek64, EOVERFLOW, and NULL.

◆ mkdir()

int mkdir ( const char *  path,
mode_t  mode 
)

Definition at line 466 of file ps2sdkapi.c.

466  {
467  return _ps2sdk_mkdir(path, mode);
468 }
int(* _ps2sdk_mkdir)(const char *, int)
Definition: ps2sdkapi.c:180

References _ps2sdk_mkdir, and mode.

Referenced by CreateSave().

◆ normalize_path()

static char* normalize_path ( const char *  path_name)
static

Definition at line 237 of file ps2sdkapi.c.

238 {
239  int i, j;
240  int first, next;
241  static char out[255];
242 
243  /* First copy the path into our temp buffer */
244  strcpy(out, path_name);
245  /* Then append "/" to make the rest easier */
246  strcat(out,"/");
247 
248  /* Convert "//" to "/" */
249  for(i=0; out[i+1]; i++) {
250  if(out[i]=='/' && out[i+1]=='/') {
251  for(j=i+1; out[j]; j++)
252  out[j] = out[j+1];
253  i--;
254  ;}
255  }
256 
257  /* Convert "/./" to "/" */
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++)
261  out[j] = out[j+2];
262  i--;
263  }
264  }
265 
266  /* Convert "/path/../" to "/" until we can't anymore. Also convert leading
267  * "/../" to "/" */
268  first = next = 0;
269  while(1) {
270  /* If a "../" follows, remove it and the parent */
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];
276  first = next = 0;
277  continue;
278  }
279 
280  /* Find next slash */
281  first = next;
282  for(next=first+1; out[next] && out[next] != '/'; next++)
283  continue;
284  if(!out[next]) break;
285  }
286 
287  /* Remove trailing "/" */
288  for(i=1; out[i]; i++)
289  continue;
290  if(i >= 1 && out[i-1] == '/')
291  out[i-1] = 0;
292 
293  return (char*)out;
294 }

Referenced by _open().

◆ opendir()

DIR* opendir ( const char *  path)

Definition at line 415 of file ps2sdkapi.c.

416 {
417  return _ps2sdk_opendir(path);
418 }
DIR *(* _ps2sdk_opendir)(const char *path)
Definition: ps2sdkapi.c:185

References _ps2sdk_opendir.

◆ ps2_sbrk()

void* ps2_sbrk ( size_t  increment)

Definition at line 22 of file sbrk.c.

23 {
24  static void * _heap_ptr = &_end;
25  void *mp, *ret = (void *)-1;
26 
27  if (increment == 0)
28  return _heap_ptr;
29 
30  /* If the area we want to allocated is past the end of our heap, we have a problem. */
31  mp = _heap_ptr + increment;
32  if (mp <= EndOfHeap()) {
33  ret = _heap_ptr;
34  _heap_ptr = mp;
35  }
36 
37  return ret;
38 }
void * EndOfHeap(void)
void * _end

References _end, and EndOfHeap().

Referenced by _sbrk().

◆ random()

long int random ( void  )

Definition at line 557 of file ps2sdkapi.c.

558 {
559  return rand();
560 }

◆ readdir()

struct dirent* readdir ( DIR *  dir)

Definition at line 420 of file ps2sdkapi.c.

421 {
422  return _ps2sdk_readdir(dir);
423 }
struct dirent *(* _ps2sdk_readdir)(DIR *dir)
Definition: ps2sdkapi.c:186

References _ps2sdk_readdir.

◆ rewinddir()

void rewinddir ( DIR *  dir)

Definition at line 425 of file ps2sdkapi.c.

426 {
427  return _ps2sdk_rewinddir(dir);
428 }
void(* _ps2sdk_rewinddir)(DIR *dir)
Definition: ps2sdkapi.c:187

References _ps2sdk_rewinddir.

◆ rmdir()

int rmdir ( const char *  path)

Definition at line 470 of file ps2sdkapi.c.

470  {
471  return _ps2sdk_rmdir(path);
472 }
int(* _ps2sdk_rmdir)(const char *)
Definition: ps2sdkapi.c:181

References _ps2sdk_rmdir.

◆ srandom()

void srandom ( unsigned int  seed)

Definition at line 562 of file ps2sdkapi.c.

563 {
564  srand(seed);
565 }

◆ time()

time_t time ( time_t *  t)

Definition at line 518 of file ps2sdkapi.c.

519 {
520  printf("ERROR: include libcdvd when using the time function\n");
521 
522  if(t != NULL)
523  *t = -1;
524  return -1;
525 }

References NULL.

Referenced by _gettimeofday().

Variable Documentation

◆ __direct_pwd

char __direct_pwd[256] = ""

Definition at line 45 of file ps2sdkapi.c.

Referenced by _open(), chdir(), and getcwd().

◆ _ps2sdk_close

int(* _ps2sdk_close) (int) ( int  ) = fioClose

Inter-library helpers

Definition at line 171 of file ps2sdkapi.c.

Referenced by _close(), and fileXioInit().

◆ _ps2sdk_closedir

int(* _ps2sdk_closedir) (DIR *dir) ( DIR *  dir) = fioClosedirHelper

Definition at line 188 of file ps2sdkapi.c.

Referenced by closedir(), and fileXioInit().

◆ _ps2sdk_ioctl

◆ _ps2sdk_lseek

int(* _ps2sdk_lseek) (int, int, int) ( int  ,
int  ,
int   
) = fioLseek

Definition at line 174 of file ps2sdkapi.c.

Referenced by _lseek(), and fileXioInit().

◆ _ps2sdk_lseek64

int64_t(* _ps2sdk_lseek64) (int, int64_t, int) ( int  ,
int64_t  ,
int   
) = NULL

Definition at line 175 of file ps2sdkapi.c.

Referenced by fileXioInit(), and lseek64().

◆ _ps2sdk_mkdir

int(* _ps2sdk_mkdir) (const char *, int) ( const char *  ,
int   
) = fioMkdirHelper

Definition at line 180 of file ps2sdkapi.c.

Referenced by fileXioInit(), and mkdir().

◆ _ps2sdk_open

int(* _ps2sdk_open) (const char *, int,...) ( const char *  ,
int  ,
  ... 
) = (void *)fioOpen

Definition at line 172 of file ps2sdkapi.c.

Referenced by _open(), and fileXioInit().

◆ _ps2sdk_opendir

DIR*(* _ps2sdk_opendir) (const char *path) ( const char *  path) = fioOpendirHelper

Definition at line 185 of file ps2sdkapi.c.

Referenced by fileXioInit(), and opendir().

◆ _ps2sdk_read

int(* _ps2sdk_read) (int, void *, int) ( int  ,
void *  ,
int   
) = fioRead

Definition at line 173 of file ps2sdkapi.c.

Referenced by _read(), and fileXioInit().

◆ _ps2sdk_readdir

struct dirent*(* _ps2sdk_readdir) (DIR *dir) ( DIR *  dir) = fioReaddirHelper

Definition at line 185 of file ps2sdkapi.c.

Referenced by fileXioInit(), and readdir().

◆ _ps2sdk_remove

int(* _ps2sdk_remove) (const char *) ( const char *  ) = fioRemove

Definition at line 178 of file ps2sdkapi.c.

Referenced by _unlink(), and fileXioInit().

◆ _ps2sdk_rename

int(* _ps2sdk_rename) (const char *, const char *) ( const char *  ,
const char *   
) = fioRename

Definition at line 179 of file ps2sdkapi.c.

Referenced by _link(), and fileXioInit().

◆ _ps2sdk_rewinddir

void(* _ps2sdk_rewinddir) (DIR *dir) ( DIR *  dir) = fioRewinddirHelper

Definition at line 187 of file ps2sdkapi.c.

Referenced by fileXioInit(), and rewinddir().

◆ _ps2sdk_rmdir

int(* _ps2sdk_rmdir) (const char *) ( const char *  ) = fioRmdir

Definition at line 181 of file ps2sdkapi.c.

Referenced by fileXioInit(), and rmdir().

◆ _ps2sdk_stat

int(* _ps2sdk_stat) (const char *path, struct stat *buf) ( const char *  path,
struct stat *  buf 
) = fioGetstatHelper

Definition at line 183 of file ps2sdkapi.c.

Referenced by _stat(), and fileXioInit().

◆ _ps2sdk_write

int(* _ps2sdk_write) (int, const void *, int) ( int  ,
const void *  ,
int   
) = fioWrite

Definition at line 176 of file ps2sdkapi.c.

Referenced by _write(), and fileXioInit().