New function _dirskip that allows to skip an amount of bytes from the

directory with error check.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5668 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2012-06-01 19:23:34 +00:00
parent 8087959e18
commit eab5f250ad
5 changed files with 117 additions and 10 deletions

View File

@@ -1,3 +1,7 @@
/*
* Ullrich von Bassewitz, 2012-05-30. Based on code by Groepaz.
*/
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
@@ -10,10 +14,8 @@
DIR* __fastcall__ opendir (const char*)
{
unsigned char buffer[8+16+1+7];
int count;
DIR d;
DIR* dir = 0;
DIR d;
/* Setup file name and offset */
d.name[0] = '$';
@@ -25,8 +27,7 @@ DIR* __fastcall__ opendir (const char*)
if (d.fd >= 0) {
/* Skip the disk header */
count = read (d.fd, buffer, sizeof (buffer));
if (count == sizeof (buffer)) {
if (_dirskip (32, &d)) {
/* Allocate memory for the DIR structure returned */
dir = malloc (sizeof (*dir));
@@ -38,9 +39,6 @@ DIR* __fastcall__ opendir (const char*)
/* Set an appropriate error code */
errno = ENOMEM;
}
} else if (count >= 0) {
/* Short read - need to set an error code */
errno = EIO;
}
}