home *** CD-ROM | disk | FTP | other *** search
- /*
- * Common low level i/o routines for Lattice C
- *
- * This program is the CONFIDENTIAL and PROPRIETARY property
- * of FairCom(R) Corporation. Any unauthorized use, reproduction or
- * transfer of this program is strictly prohibited.
- *
- * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989 FairCom Corporation
- * (Subject to limited distribution and
- * restricted disclosure only.)
- * *** ALL RIGHTS RESERVED ***
- *
- * 4006 West Broadway
- * Columbia, MO 65203
- *
- *
- * c-tree(R) Version 4.3
- * Release C
- * February 7, 1989 17:30
- *
- */
-
- #include "ctstdr.h" /* standard i/o header */
- #include "ctoptn.h" /* c-tree configuration options */
- #include "cterrc.h" /* c-tree error codes */
- #include "ctstrc.h" /* c-tree data structures */
- #include "ctgvar.h" /* c-tree global variables */
-
- #ifdef CT_ANSI
- int fseek();
- #else
- LONG lseek();
- #endif
-
- COUNT uerr();
-
- COUNT ctseek(ctnum,recbyt)
- PFAST CTFILE *ctnum;
- POINTER recbyt;
- {
- #ifdef CT_ANSI
- if (fseek(ctnum->fd,ctnum->sekpos = recbyt,SEEK_SET))
- return(SEEK_ERR);
- else
- return(NO_ERROR);
- #else
- if (ctnum->sekpos == recbyt)
- return(NO_ERROR);
- else if (lseek(ctnum->fd,ctnum->sekpos = recbyt,0) < 0L)
- return(SEEK_ERR);
- else
- return(NO_ERROR);
- #endif
- }
-
- COUNT ctio(op_code,ctnum,recbyt,bufadr,iosize)
- COUNT op_code; /* CTREAD or CTWRITE */
- CTFILE *ctnum;
- LONG recbyt;
- TEXT *bufadr;
- #ifdef CT_ANSI
- size_t iosize;
- #else
- unsigned int iosize;
- #endif
- {
- #ifdef CT_ANSI
- size_t fread(),fwrite();
- #else
- int read(),write();
- #endif
-
- if (ctseek(ctnum,recbyt))
- return(uerr(SEEK_ERR));
-
- if (!iosize)
- iosize = ctnum->reclen;
- if (op_code == CTREAD) {
- #ifdef CT_ANSI
- if (fread(bufadr,iosize,1,ctnum->fd) != 1) {
- #else
- if (read(ctnum->fd,bufadr,iosize) != iosize) {
- #endif
- ctnum->sekpos = -1L;
- return(uerr(READ_ERR));
- }
- } else {
- #ifdef CT_ANSI
- if (fwrite(bufadr,iosize,1,ctnum->fd) != 1) {
- #else
- if (write(ctnum->fd,bufadr,iosize) != iosize) {
- #endif
- ctnum->sekpos = -1L;
- return(uerr(WRITE_ERR));
- }
- }
- ctnum->sekpos += iosize;
- return(NO_ERROR);
- }
-
- COUNT mbclos( ctnum,clmode)
- PFAST CTFILE *ctnum;
- COUNT clmode; /* COMPLETE or PARTIAL */
- {
- if (!(ctnum->flmode & PERMANENT))
- ct_numvfil--;
- #ifdef CT_ANSI
- return((COUNT) fclose(ctnum->fd));
- #else
- return((COUNT) close(ctnum->fd));
- #endif
- }
-
- COUNT dltfil(filnam)
- TEXT *filnam;
- {
- if (remove(filnam))
- return(uerr_cod = DLTF_ERR);
- else
- return(NO_ERROR);
- }
-
- /* end of ctclb3.c */
-