summaryrefslogtreecommitdiffstats
path: root/board/MAI/bios_emulator/scitech/src/pm/vxd/fileio.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/MAI/bios_emulator/scitech/src/pm/vxd/fileio.c')
-rw-r--r--board/MAI/bios_emulator/scitech/src/pm/vxd/fileio.c213
1 files changed, 106 insertions, 107 deletions
diff --git a/board/MAI/bios_emulator/scitech/src/pm/vxd/fileio.c b/board/MAI/bios_emulator/scitech/src/pm/vxd/fileio.c
index e2ff585839..3c6ce99208 100644
--- a/board/MAI/bios_emulator/scitech/src/pm/vxd/fileio.c
+++ b/board/MAI/bios_emulator/scitech/src/pm/vxd/fileio.c
@@ -47,62 +47,62 @@ FILE * fopen(
long oldpos;
if (f) {
- f->offset = 0;
- f->text = (mode[1] == 't' || mode[2] == 't');
- f->writemode = (mode[0] == 'w') || (mode[0] == 'a');
- if (initComplete) {
- WORD omode,error;
- BYTE action;
+ f->offset = 0;
+ f->text = (mode[1] == 't' || mode[2] == 't');
+ f->writemode = (mode[0] == 'w') || (mode[0] == 'a');
+ if (initComplete) {
+ WORD omode,error;
+ BYTE action;
- if (mode[0] == 'r') {
- omode = OPEN_ACCESS_READONLY | OPEN_SHARE_COMPATIBLE;
- action = ACTION_IFEXISTS_OPEN | ACTION_IFNOTEXISTS_FAIL;
- }
- else if (mode[0] == 'w') {
- omode = OPEN_ACCESS_WRITEONLY | OPEN_SHARE_COMPATIBLE;
- action = ACTION_IFEXISTS_TRUNCATE | ACTION_IFNOTEXISTS_CREATE;
- }
- else {
- omode = OPEN_ACCESS_READWRITE | OPEN_SHARE_COMPATIBLE;
- action = ACTION_IFEXISTS_OPEN | ACTION_IFNOTEXISTS_CREATE;
- }
- f->handle = (int)R0_OpenCreateFile(false,(char*)filename,omode,ATTR_NORMAL,action,0,&error,&action);
- if (f->handle == 0) {
- PM_free(f);
- return NULL;
- }
- f->filesize = R0_GetFileSize((HANDLE)f->handle,&error);
- if (mode[0] == 'a')
- fseek(f,0,2);
- }
- else {
- int oflag,pmode;
+ if (mode[0] == 'r') {
+ omode = OPEN_ACCESS_READONLY | OPEN_SHARE_COMPATIBLE;
+ action = ACTION_IFEXISTS_OPEN | ACTION_IFNOTEXISTS_FAIL;
+ }
+ else if (mode[0] == 'w') {
+ omode = OPEN_ACCESS_WRITEONLY | OPEN_SHARE_COMPATIBLE;
+ action = ACTION_IFEXISTS_TRUNCATE | ACTION_IFNOTEXISTS_CREATE;
+ }
+ else {
+ omode = OPEN_ACCESS_READWRITE | OPEN_SHARE_COMPATIBLE;
+ action = ACTION_IFEXISTS_OPEN | ACTION_IFNOTEXISTS_CREATE;
+ }
+ f->handle = (int)R0_OpenCreateFile(false,(char*)filename,omode,ATTR_NORMAL,action,0,&error,&action);
+ if (f->handle == 0) {
+ PM_free(f);
+ return NULL;
+ }
+ f->filesize = R0_GetFileSize((HANDLE)f->handle,&error);
+ if (mode[0] == 'a')
+ fseek(f,0,2);
+ }
+ else {
+ int oflag,pmode;
- if (mode[0] == 'r') {
- pmode = _S_IREAD;
- oflag = _O_RDONLY;
- }
- else if (mode[0] == 'w') {
- pmode = _S_IWRITE;
- oflag = _O_WRONLY | _O_CREAT | _O_TRUNC;
- }
- else {
- pmode = _S_IWRITE;
- oflag = _O_RDWR | _O_CREAT | _O_APPEND;
- }
- if (f->text)
- oflag |= _O_TEXT;
- else
- oflag |= _O_BINARY;
- if ((f->handle = i_open(filename,oflag,pmode)) == -1) {
- PM_free(f);
- return NULL;
- }
- oldpos = i_lseek(f->handle,0,1);
- f->filesize = i_lseek(f->handle,0,2);
- i_lseek(f->handle,oldpos,0);
- }
- }
+ if (mode[0] == 'r') {
+ pmode = _S_IREAD;
+ oflag = _O_RDONLY;
+ }
+ else if (mode[0] == 'w') {
+ pmode = _S_IWRITE;
+ oflag = _O_WRONLY | _O_CREAT | _O_TRUNC;
+ }
+ else {
+ pmode = _S_IWRITE;
+ oflag = _O_RDWR | _O_CREAT | _O_APPEND;
+ }
+ if (f->text)
+ oflag |= _O_TEXT;
+ else
+ oflag |= _O_BINARY;
+ if ((f->handle = i_open(filename,oflag,pmode)) == -1) {
+ PM_free(f);
+ return NULL;
+ }
+ oldpos = i_lseek(f->handle,0,1);
+ f->filesize = i_lseek(f->handle,0,2);
+ i_lseek(f->handle,oldpos,0);
+ }
+ }
return f;
}
@@ -125,27 +125,27 @@ size_t fread(
int readbytes,totalbytes = 0;
while (bytes > 0x10000) {
- if (initComplete) {
- readbytes = R0_ReadFile(false,(HANDLE)f->handle,buf,0x8000,f->offset,&error);
- readbytes += R0_ReadFile(false,(HANDLE)f->handle,buf+0x8000,0x8000,f->offset+0x8000,&error);
- }
- else {
- readbytes = i_read(f->handle,buf,0x8000);
- readbytes += i_read(f->handle,buf+0x8000,0x8000);
- }
- totalbytes += readbytes;
- f->offset += readbytes;
- buf += 0x10000;
- bytes -= 0x10000;
- }
+ if (initComplete) {
+ readbytes = R0_ReadFile(false,(HANDLE)f->handle,buf,0x8000,f->offset,&error);
+ readbytes += R0_ReadFile(false,(HANDLE)f->handle,buf+0x8000,0x8000,f->offset+0x8000,&error);
+ }
+ else {
+ readbytes = i_read(f->handle,buf,0x8000);
+ readbytes += i_read(f->handle,buf+0x8000,0x8000);
+ }
+ totalbytes += readbytes;
+ f->offset += readbytes;
+ buf += 0x10000;
+ bytes -= 0x10000;
+ }
if (bytes) {
- if (initComplete)
- readbytes = R0_ReadFile(false,(HANDLE)f->handle,buf,bytes,f->offset,&error);
- else
- readbytes = i_read(f->handle,buf,bytes);
- totalbytes += readbytes;
- f->offset += readbytes;
- }
+ if (initComplete)
+ readbytes = R0_ReadFile(false,(HANDLE)f->handle,buf,bytes,f->offset,&error);
+ else
+ readbytes = i_read(f->handle,buf,bytes);
+ totalbytes += readbytes;
+ f->offset += readbytes;
+ }
return totalbytes / size;
}
@@ -168,29 +168,29 @@ size_t fwrite(
int writtenbytes,totalbytes = 0;
if (!f->writemode)
- return 0;
+ return 0;
while (bytes > 0x10000) {
- if (initComplete) {
- writtenbytes = R0_WriteFile(false,(HANDLE)f->handle,buf,0x8000,f->offset,&error);
- writtenbytes += R0_WriteFile(false,(HANDLE)f->handle,buf+0x8000,0x8000,f->offset+0x8000,&error);
- }
- else {
- writtenbytes = i_write(f->handle,buf,0x8000);
- writtenbytes += i_write(f->handle,buf+0x8000,0x8000);
- }
- totalbytes += writtenbytes;
- f->offset += writtenbytes;
- buf += 0x10000;
- bytes -= 0x10000;
- }
+ if (initComplete) {
+ writtenbytes = R0_WriteFile(false,(HANDLE)f->handle,buf,0x8000,f->offset,&error);
+ writtenbytes += R0_WriteFile(false,(HANDLE)f->handle,buf+0x8000,0x8000,f->offset+0x8000,&error);
+ }
+ else {
+ writtenbytes = i_write(f->handle,buf,0x8000);
+ writtenbytes += i_write(f->handle,buf+0x8000,0x8000);
+ }
+ totalbytes += writtenbytes;
+ f->offset += writtenbytes;
+ buf += 0x10000;
+ bytes -= 0x10000;
+ }
if (initComplete)
- writtenbytes = R0_WriteFile(false,(HANDLE)f->handle,buf,bytes,f->offset,&error);
+ writtenbytes = R0_WriteFile(false,(HANDLE)f->handle,buf,bytes,f->offset,&error);
else
- writtenbytes = i_write(f->handle,buf,bytes);
+ writtenbytes = i_write(f->handle,buf,bytes);
totalbytes += writtenbytes;
f->offset += writtenbytes;
if (f->offset > f->filesize)
- f->filesize = f->offset;
+ f->filesize = f->offset;
return totalbytes / size;
}
@@ -201,7 +201,7 @@ VxD implementation of the ANSI C fflush function.
int fflush(
FILE *f)
{
- // Nothing to do since we are not doing buffered file I/O
+ /* Nothing to do since we are not doing buffered file I/O */
(void)f;
return 0;
}
@@ -216,13 +216,13 @@ int fseek(
int whence)
{
if (whence == 0)
- f->offset = offset;
+ f->offset = offset;
else if (whence == 1)
- f->offset += offset;
+ f->offset += offset;
else if (whence == 2)
- f->offset = f->filesize + offset;
+ f->offset = f->filesize + offset;
if (!initComplete)
- i_lseek(f->handle,f->offset,0);
+ i_lseek(f->handle,f->offset,0);
return 0;
}
@@ -258,19 +258,19 @@ char *fgets(
int len;
char *cs;
- // Read the entire buffer into memory (our functions are unbuffered!)
+ /* Read the entire buffer into memory (our functions are unbuffered!) */
if ((len = fread(s,1,n,f)) == 0)
- return NULL;
+ return NULL;
- // Search for '\n' or end of string
+ /* Search for '\n' or end of string */
if (n > len)
- n = len;
+ n = len;
cs = s;
while (--n > 0) {
- if (*cs == '\n')
- break;
- cs++;
- }
+ if (*cs == '\n')
+ break;
+ cs++;
+ }
*cs = '\0';
return s;
}
@@ -296,10 +296,9 @@ int fclose(
WORD error;
if (initComplete)
- R0_CloseFile((HANDLE)f->handle,&error);
+ R0_CloseFile((HANDLE)f->handle,&error);
else
- i_close(f->handle);
+ i_close(f->handle);
PM_free(f);
return 0;
}
-
OpenPOWER on IntegriCloud