/*************************************************************************** *cr *cr (C) Copyright 1995-2003 The Board of Trustees of the *cr University of Illinois *cr All Rights Reserved *cr ***************************************************************************/ /*************************************************************************** * RCS INFORMATION: * * $RCSfile: fastio.h,v $ * $Author: johns $ $Locker: $ $State: Exp $ * $Revision: 1.5 $ $Date: 2004/08/04 14:55:38 $ * *************************************************************************** * DESCRIPTION: * This is a simple abstraction layer for system-dependent I/O calls * that allow plugins to do binary I/O using the fastest possible method. * * This code is intended for use by binary trajectory reader plugins that * work with multi-gigabyte data sets, reading only binary data. * ***************************************************************************/ #if defined(_MSC_VER) /* Version for machines with plain old ANSI C */ #include typedef FILE * fio_fd; typedef size_t fio_size_t; typedef caddr_t fio_caddr_t; typedef struct { fio_caddr_t iov_base; int iov_len; } fio_iovec; #define FIO_READ 0x01 #define FIO_WRITE 0x02 #define FIO_SEEK_CUR SEEK_CUR #define FIO_SEEK_SET SEEK_SET #define FIO_SEEK_END SEEK_END static int fio_open(const char *filename, int mode, fio_fd *fd) { char * modestr; FILE *fp; if (mode == FIO_READ) modestr = "rb"; if (mode == FIO_WRITE) modestr = "wb"; fp = fopen(filename, modestr); if (fp == NULL) { return -1; } else { *fd = fp; return 0; } } static int fio_fclose(fio_fd fd) { return fclose(fd); } static fio_size_t fio_fread(void *ptr, fio_size_t size, fio_size_t nitems, fio_fd fd) { return fread(ptr, size, nitems, fd); } static fio_size_t fio_readv(fio_fd fd, const fio_iovec * iov, int iovcnt) { int i; ssize_t len = 0; for (i=0; i #include #include #include typedef int fio_fd; typedef ssize_t fio_size_t; /* enable use of kernel readv() if available */ #if defined(__sun) #define USE_KERNEL_READV 1 #endif typedef void * fio_caddr_t; #if defined(USE_KERNEL_READV) #include typedef struct iovec fio_iovec; #else typedef struct { fio_caddr_t iov_base; int iov_len; } fio_iovec; #endif #define FIO_READ 0x01 #define FIO_WRITE 0x02 #define FIO_SEEK_CUR SEEK_CUR #define FIO_SEEK_SET SEEK_SET #define FIO_SEEK_END SEEK_END static int fio_open(const char *filename, int mode, fio_fd *fd) { int nfd; int oflag = 0; if (mode == FIO_READ) oflag = O_RDONLY; if (mode == FIO_WRITE) oflag = O_WRONLY | O_CREAT; nfd = open(filename, oflag, 0700); if (nfd < 0) { return -1; } else { *fd = nfd; return 0; } } static int fio_fclose(fio_fd fd) { return close(fd); } static fio_size_t fio_fread(void *ptr, fio_size_t size, fio_size_t nitems, fio_fd fd) { int i; ssize_t len = 0; int cnt = 0; for (i=0; i