FD_t fd = c2f(cookie);
ssize_t rc;
- if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
+ if (fd == NULL || fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
fdstat_enter(fd, FDSTAT_READ);
rc = read(fdFileno(fd), buf, (count > fd->bytesRemain ? fd->bytesRemain : count));
int fdno = fdFileno(fd);
ssize_t rc;
- if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
+ if (fd == NULL || fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
if (fd->digests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
FD_t fd = c2f(cookie);
off_t rc;
+ if (fd == NULL)
+ return -2;
+
assert(fd->bytesRemain == -1); /* XXX FIXME fadio only for now */
fdstat_enter(fd, FDSTAT_SEEK);
rc = lseek(fdFileno(fd), p, whence);
*/
static int fdClose( void * cookie)
{
- FD_t fd;
+ FD_t fd = c2f(cookie);
int fdno;
int rc;
- if (cookie == NULL) return -2;
- fd = c2f(cookie);
+ if (fd == NULL) return -2;
fdno = fdFileno(fd);
fdSetFdno(fd, -1);
int fdno;
gzFile gzfile;
- if (fmode == NULL) return NULL;
+ if (fd == NULL || fmode == NULL) return NULL;
fdno = fdFileno(fd);
fdSetFdno(fd, -1); /* XXX skip the fdio close */
if (fdno < 0) return NULL;
int fdno;
BZFILE *bzfile;
- if (fmode == NULL) return NULL;
+ if (fd == NULL || fmode == NULL) return NULL;
fdno = fdFileno(fd);
fdSetFdno(fd, -1); /* XXX skip the fdio close */
if (fdno < 0) return NULL;
BZFILE *bzfile;
ssize_t rc = 0;
- if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
+ if (fd == NULL || fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
bzfile = bzdFileno(fd);
fdstat_enter(fd, FDSTAT_READ);
if (bzfile)
BZFILE *bzfile;
ssize_t rc;
- if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
+ if (fd == NULL || fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
if (fd->digests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
int fdno;
LZFILE *lzfile;
- if (fmode == NULL) return NULL;
+ if (fd == NULL || fmode == NULL) return NULL;
fdno = fdFileno(fd);
fdSetFdno(fd, -1); /* XXX skip the fdio close */
if (fdno < 0) return NULL;
int fdno;
LZFILE *lzfile;
- if (fmode == NULL) return NULL;
+ if (fd == NULL || fmode == NULL) return NULL;
fdno = fdFileno(fd);
fdSetFdno(fd, -1); /* XXX skip the fdio close */
if (fdno < 0) return NULL;
LZFILE *lzfile;
ssize_t rc = 0;
- if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
+ if (fd == NULL || fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
lzfile = lzdFileno(fd);
fdstat_enter(fd, FDSTAT_READ);
if (lzfile)
fdio_read_function_t _read;
int rc;
- FDSANE(fd);
-DBGIO(fd, (stderr, "==> Fread(%p,%u,%u,%p) %s\n", buf, (unsigned)size, (unsigned)nmemb, (fd ? fd : NULL), fdbg(fd)));
+ if (fd == NULL)
+ return 0;
if (fdGetIo(fd) == fpio) {
rc = fread(buf, size, nmemb, fdGetFILE(fd));
fdio_write_function_t _write;
int rc;
- FDSANE(fd);
-DBGIO(fd, (stderr, "==> Fwrite(%p,%u,%u,%p) %s\n", buf, (unsigned)size, (unsigned)nmemb, (fd ? fd : NULL), fdbg(fd)));
+ if (fd == NULL)
+ return 0;
if (fdGetIo(fd) == fpio) {
rc = fwrite(buf, size, nmemb, fdGetFILE(fd));
long int rc;
- FDSANE(fd);
-DBGIO(fd, (stderr, "==> Fseek(%p,%ld,%d) %s\n", fd, (long)offset, whence, fdbg(fd)));
+ if (fd == NULL)
+ return -1;
if (fdGetIo(fd) == fpio) {
FILE *fp;
{
int rc = 0, ec = 0;
- FDSANE(fd);
-DBGIO(fd, (stderr, "==> Fclose(%p) %s\n", (fd ? fd : NULL), fdbg(fd)));
+ if (fd == NULL)
+ return -1;
fd = fdLink(fd);
while (fd->nfps >= 0) {