forked from z88dk/z88dk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
217 changed files
with
22,755 additions
and
22,745 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
/* | ||
* Close a file | ||
* Stefano Bodrato - 2013 | ||
* | ||
* int close(int handle) | ||
* (write the current block and the control block amd free memory) | ||
* | ||
* $Id: close.c,v 1.2 2014-01-20 09:15:31 stefano Exp $ | ||
*/ | ||
|
||
#include <fcntl.h> | ||
#include <malloc.h> | ||
|
||
int close(int handle) | ||
{ | ||
struct RND_FILE *myfile; | ||
|
||
myfile = (char *) handle; | ||
//if (!(myfile)->blockptr) return -1; | ||
|
||
if ((myfile)->mode!=O_RDONLY) { | ||
|
||
if ((myfile)->name_prefix=='_') | ||
return (-1); | ||
|
||
rnd_saveblock(&(myfile)->name_prefix, (myfile)->blockptr, (myfile)->blocksize); | ||
// We could check the result for rnd_saveblock, but perhaps it'd be too late | ||
// Let's just save the control block (hoping we won't run out of space :S) | ||
(myfile)->name_prefix='_'; | ||
rnd_saveblock(&(myfile)->name_prefix, myfile, sizeof(struct RND_FILE)); | ||
} | ||
|
||
free((myfile)->blockptr); | ||
//(myfile)->blockptr=0; | ||
free(myfile); | ||
|
||
return 0; | ||
|
||
} | ||
/* | ||
* Close a file | ||
* Stefano Bodrato - 2013 | ||
* | ||
* int close(int handle) | ||
* (write the current block and the control block amd free memory) | ||
* | ||
* $Id: close.c,v 1.2 2014-01-20 09:15:31 stefano Exp $ | ||
*/ | ||
|
||
#include <fcntl.h> | ||
#include <malloc.h> | ||
|
||
int close(int handle) | ||
{ | ||
struct RND_FILE *myfile; | ||
|
||
myfile = (char *) handle; | ||
//if (!(myfile)->blockptr) return -1; | ||
|
||
if ((myfile)->mode!=O_RDONLY) { | ||
|
||
if ((myfile)->name_prefix=='_') | ||
return (-1); | ||
|
||
rnd_saveblock(&(myfile)->name_prefix, (myfile)->blockptr, (myfile)->blocksize); | ||
// We could check the result for rnd_saveblock, but perhaps it'd be too late | ||
// Let's just save the control block (hoping we won't run out of space :S) | ||
(myfile)->name_prefix='_'; | ||
rnd_saveblock(&(myfile)->name_prefix, myfile, sizeof(struct RND_FILE)); | ||
} | ||
|
||
free((myfile)->blockptr); | ||
//(myfile)->blockptr=0; | ||
free(myfile); | ||
|
||
return 0; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,110 @@ | ||
/* | ||
* Open a file - create the control block in a memory structure, | ||
* allocate its temporary buffer and eventually write a first empty | ||
* block on disk. A file holding the control block plus | ||
* other files will form the virtual sectors of the same rnd_file | ||
* | ||
* Stefano Bodrato - 2013 | ||
* | ||
* int open(char *name, int flags, mode_t mode) | ||
* returns handle to file | ||
* | ||
* | ||
* Access is either | ||
* | ||
* O_RDONLY = 0 | ||
* (O_RDWR .. does not mean much at the) | ||
* O_WRONLY = 1 Starts afresh?!?!? | ||
* O_APPEND = 256 | ||
* | ||
* $Id: open.c,v 1.3 2016-06-13 19:55:47 dom Exp $ | ||
*/ | ||
|
||
#include <fcntl.h> | ||
// "stdio.h" contains definition for EOF | ||
#define __HAVESEED | ||
#include <stdio.h> | ||
|
||
#include <string.h> | ||
#include <malloc.h> | ||
|
||
|
||
int open(char *name, int flags, mode_t mode) | ||
{ | ||
struct RND_FILE *myfile; | ||
int myfile_missing; | ||
|
||
myfile = malloc(sizeof(struct RND_FILE)); | ||
strcpy(myfile->name,name); | ||
(myfile)->name_prefix='_'; | ||
|
||
myfile_missing = rnd_loadblock(&(myfile)->name_prefix, myfile, sizeof(struct RND_FILE)); | ||
|
||
if (myfile_missing) { | ||
(myfile)->size=0L; | ||
(myfile)->blocksize=RND_BLOCKSIZE; | ||
} | ||
|
||
(myfile)->position=0L; | ||
(myfile)->blockptr=malloc((myfile)->blocksize+1); | ||
//(myfile)->flags=flags; | ||
(myfile)->mode=flags; | ||
(myfile)->name_prefix='0'; | ||
(myfile)->pos_in_block=0; | ||
|
||
|
||
switch (flags) { | ||
case O_RDONLY: | ||
if (myfile_missing) { | ||
// FILE NOT FOUND | ||
free((myfile)->blockptr); | ||
free(myfile); | ||
return(-1); | ||
} | ||
if (!rnd_loadblock(&(myfile)->name_prefix, (myfile)->blockptr, (myfile)->blocksize)) { | ||
return(myfile); } | ||
else | ||
return(-1); | ||
break; | ||
|
||
case O_APPEND: | ||
if (myfile_missing) { | ||
// FILE NOT FOUND | ||
free((myfile)->blockptr); | ||
free(myfile); | ||
return(-1); | ||
} | ||
if (lseek(myfile,0L,SEEK_END)==EOF) { | ||
free((myfile)->blockptr); | ||
free(myfile); | ||
return(-1); | ||
} | ||
return(myfile); | ||
break; | ||
|
||
|
||
case O_WRONLY: | ||
// TODO: delete file to overwrite | ||
case O_RDWR: | ||
if (myfile_missing) { | ||
// create the first datablock: "0<filename>" to verify | ||
// we have space on disk and disk can be written | ||
if (rnd_saveblock(&(myfile)->name_prefix, (myfile)->blockptr, (myfile)->blocksize)) { | ||
// FILE CREATION ERROR | ||
free((myfile)->blockptr); | ||
free(myfile); | ||
return(-1); | ||
} | ||
// The control block creation ("_<filename>) is in "close.c" | ||
} else if (lseek(myfile,0L,SEEK_SET)==EOF) { | ||
free((myfile)->blockptr); | ||
free(myfile); | ||
return(-1); | ||
} | ||
return(myfile); | ||
break; | ||
|
||
} | ||
return(-1); | ||
} | ||
/* | ||
* Open a file - create the control block in a memory structure, | ||
* allocate its temporary buffer and eventually write a first empty | ||
* block on disk. A file holding the control block plus | ||
* other files will form the virtual sectors of the same rnd_file | ||
* | ||
* Stefano Bodrato - 2013 | ||
* | ||
* int open(char *name, int flags, mode_t mode) | ||
* returns handle to file | ||
* | ||
* | ||
* Access is either | ||
* | ||
* O_RDONLY = 0 | ||
* (O_RDWR .. does not mean much at the) | ||
* O_WRONLY = 1 Starts afresh?!?!? | ||
* O_APPEND = 256 | ||
* | ||
* $Id: open.c,v 1.3 2016-06-13 19:55:47 dom Exp $ | ||
*/ | ||
|
||
#include <fcntl.h> | ||
// "stdio.h" contains definition for EOF | ||
#define __HAVESEED | ||
#include <stdio.h> | ||
|
||
#include <string.h> | ||
#include <malloc.h> | ||
|
||
|
||
int open(char *name, int flags, mode_t mode) | ||
{ | ||
struct RND_FILE *myfile; | ||
int myfile_missing; | ||
|
||
myfile = malloc(sizeof(struct RND_FILE)); | ||
strcpy(myfile->name,name); | ||
(myfile)->name_prefix='_'; | ||
|
||
myfile_missing = rnd_loadblock(&(myfile)->name_prefix, myfile, sizeof(struct RND_FILE)); | ||
|
||
if (myfile_missing) { | ||
(myfile)->size=0L; | ||
(myfile)->blocksize=RND_BLOCKSIZE; | ||
} | ||
|
||
(myfile)->position=0L; | ||
(myfile)->blockptr=malloc((myfile)->blocksize+1); | ||
//(myfile)->flags=flags; | ||
(myfile)->mode=flags; | ||
(myfile)->name_prefix='0'; | ||
(myfile)->pos_in_block=0; | ||
|
||
|
||
switch (flags) { | ||
case O_RDONLY: | ||
if (myfile_missing) { | ||
// FILE NOT FOUND | ||
free((myfile)->blockptr); | ||
free(myfile); | ||
return(-1); | ||
} | ||
if (!rnd_loadblock(&(myfile)->name_prefix, (myfile)->blockptr, (myfile)->blocksize)) { | ||
return(myfile); } | ||
else | ||
return(-1); | ||
break; | ||
|
||
case O_APPEND: | ||
if (myfile_missing) { | ||
// FILE NOT FOUND | ||
free((myfile)->blockptr); | ||
free(myfile); | ||
return(-1); | ||
} | ||
if (lseek(myfile,0L,SEEK_END)==EOF) { | ||
free((myfile)->blockptr); | ||
free(myfile); | ||
return(-1); | ||
} | ||
return(myfile); | ||
break; | ||
|
||
|
||
case O_WRONLY: | ||
// TODO: delete file to overwrite | ||
case O_RDWR: | ||
if (myfile_missing) { | ||
// create the first datablock: "0<filename>" to verify | ||
// we have space on disk and disk can be written | ||
if (rnd_saveblock(&(myfile)->name_prefix, (myfile)->blockptr, (myfile)->blocksize)) { | ||
// FILE CREATION ERROR | ||
free((myfile)->blockptr); | ||
free(myfile); | ||
return(-1); | ||
} | ||
// The control block creation ("_<filename>) is in "close.c" | ||
} else if (lseek(myfile,0L,SEEK_SET)==EOF) { | ||
free((myfile)->blockptr); | ||
free(myfile); | ||
return(-1); | ||
} | ||
return(myfile); | ||
break; | ||
|
||
} | ||
return(-1); | ||
} | ||
|
Oops, something went wrong.