Search
lxdream.org :: lxdream/src/dcload.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/dcload.c
changeset 736:a02d1475ccfd
prev671:a530ea88eebd
next1065:bc1cc0c54917
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
1.1 --- a/src/dcload.c Thu May 15 10:22:39 2008 +0000
1.2 +++ b/src/dcload.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -69,9 +69,9 @@
1.4 {
1.5 int i;
1.6 for( i=0; i<MAX_OPEN_FDS; i++ ) {
1.7 - if( open_fds[i] == -1 ) {
1.8 - return i;
1.9 - }
1.10 + if( open_fds[i] == -1 ) {
1.11 + return i;
1.12 + }
1.13 }
1.14 return -1;
1.15 }
1.16 @@ -82,76 +82,76 @@
1.17 int fd;
1.18 switch( sh4r.r[4] ) {
1.19 case SYS_READ:
1.20 - fd = sh4r.r[5];
1.21 - if( fd < 0 || fd >= MAX_OPEN_FDS || open_fds[fd] == -1 ) {
1.22 - sh4r.r[0] = -1;
1.23 - } else {
1.24 - sh4ptr_t buf = mem_get_region( sh4r.r[6] );
1.25 - int length = sh4r.r[7];
1.26 - sh4r.r[0] = read( open_fds[fd], buf, length );
1.27 - }
1.28 - break;
1.29 + fd = sh4r.r[5];
1.30 + if( fd < 0 || fd >= MAX_OPEN_FDS || open_fds[fd] == -1 ) {
1.31 + sh4r.r[0] = -1;
1.32 + } else {
1.33 + sh4ptr_t buf = mem_get_region( sh4r.r[6] );
1.34 + int length = sh4r.r[7];
1.35 + sh4r.r[0] = read( open_fds[fd], buf, length );
1.36 + }
1.37 + break;
1.38 case SYS_WRITE:
1.39 - fd = sh4r.r[5];
1.40 - if( fd < 0 || fd >= MAX_OPEN_FDS || open_fds[fd] == -1 ) {
1.41 - sh4r.r[0] = -1;
1.42 - } else {
1.43 - sh4ptr_t buf = mem_get_region( sh4r.r[6] );
1.44 - int length = sh4r.r[7];
1.45 - sh4r.r[0] = write( open_fds[fd], buf, length );
1.46 - }
1.47 - break;
1.48 + fd = sh4r.r[5];
1.49 + if( fd < 0 || fd >= MAX_OPEN_FDS || open_fds[fd] == -1 ) {
1.50 + sh4r.r[0] = -1;
1.51 + } else {
1.52 + sh4ptr_t buf = mem_get_region( sh4r.r[6] );
1.53 + int length = sh4r.r[7];
1.54 + sh4r.r[0] = write( open_fds[fd], buf, length );
1.55 + }
1.56 + break;
1.57 case SYS_LSEEK:
1.58 - fd = sh4r.r[5];
1.59 - if( fd < 0 || fd >= MAX_OPEN_FDS || open_fds[fd] == -1 ) {
1.60 - sh4r.r[0] = -1;
1.61 - } else {
1.62 - sh4r.r[0] = lseek( open_fds[fd], sh4r.r[6], sh4r.r[7] );
1.63 - }
1.64 - break;
1.65 + fd = sh4r.r[5];
1.66 + if( fd < 0 || fd >= MAX_OPEN_FDS || open_fds[fd] == -1 ) {
1.67 + sh4r.r[0] = -1;
1.68 + } else {
1.69 + sh4r.r[0] = lseek( open_fds[fd], sh4r.r[6], sh4r.r[7] );
1.70 + }
1.71 + break;
1.72
1.73 -/* Secure access only */
1.74 + /* Secure access only */
1.75 case SYS_OPEN:
1.76 - if( dcload_allow_unsafe ) {
1.77 - fd = dcload_alloc_fd();
1.78 - if( fd == -1 ) {
1.79 - sh4r.r[0] = -1;
1.80 - } else {
1.81 - char *filename = (char *)mem_get_region( sh4r.r[5] );
1.82 - int realfd = open( filename, sh4r.r[6] );
1.83 - open_fds[fd] = realfd;
1.84 - sh4r.r[0] = realfd;
1.85 - }
1.86 - } else {
1.87 - ERROR( "Denying access to local filesystem" );
1.88 - sh4r.r[0] = -1;
1.89 - }
1.90 - break;
1.91 + if( dcload_allow_unsafe ) {
1.92 + fd = dcload_alloc_fd();
1.93 + if( fd == -1 ) {
1.94 + sh4r.r[0] = -1;
1.95 + } else {
1.96 + char *filename = (char *)mem_get_region( sh4r.r[5] );
1.97 + int realfd = open( filename, sh4r.r[6] );
1.98 + open_fds[fd] = realfd;
1.99 + sh4r.r[0] = realfd;
1.100 + }
1.101 + } else {
1.102 + ERROR( "Denying access to local filesystem" );
1.103 + sh4r.r[0] = -1;
1.104 + }
1.105 + break;
1.106 case SYS_CLOSE:
1.107 - if( dcload_allow_unsafe ) {
1.108 - fd = sh4r.r[5];
1.109 - if( fd < 0 || fd >= MAX_OPEN_FDS || open_fds[fd] == -1 ) {
1.110 - sh4r.r[0] = -1;
1.111 - } else {
1.112 - if( open_fds[fd] > 2 ) {
1.113 - sh4r.r[0] = close( open_fds[fd] );
1.114 - } else {
1.115 - /* Don't actually close real fds 0-2 */
1.116 - sh4r.r[0] = 0;
1.117 - }
1.118 - open_fds[fd] = -1;
1.119 - }
1.120 - }
1.121 - break;
1.122 + if( dcload_allow_unsafe ) {
1.123 + fd = sh4r.r[5];
1.124 + if( fd < 0 || fd >= MAX_OPEN_FDS || open_fds[fd] == -1 ) {
1.125 + sh4r.r[0] = -1;
1.126 + } else {
1.127 + if( open_fds[fd] > 2 ) {
1.128 + sh4r.r[0] = close( open_fds[fd] );
1.129 + } else {
1.130 + /* Don't actually close real fds 0-2 */
1.131 + sh4r.r[0] = 0;
1.132 + }
1.133 + open_fds[fd] = -1;
1.134 + }
1.135 + }
1.136 + break;
1.137 case SYS_EXIT:
1.138 - if( dcload_allow_unsafe ) {
1.139 - dreamcast_shutdown();
1.140 - exit( sh4r.r[5] );
1.141 - } else {
1.142 - dreamcast_stop();
1.143 - }
1.144 + if( dcload_allow_unsafe ) {
1.145 + dreamcast_shutdown();
1.146 + exit( sh4r.r[5] );
1.147 + } else {
1.148 + dreamcast_stop();
1.149 + }
1.150 default:
1.151 - sh4r.r[0] = -1;
1.152 + sh4r.r[0] = -1;
1.153 }
1.154
1.155 }
.