home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c004 / 2.ddi / LC / CTCLB3.C next >
Encoding:
C/C++ Source or Header  |  1989-04-18  |  2.5 KB  |  124 lines

  1. /*
  2.  *    Common low level i/o routines for Lattice C
  3.  *
  4.  *    This program is the CONFIDENTIAL and PROPRIETARY property 
  5.  *    of FairCom(R) Corporation. Any unauthorized use, reproduction or
  6.  *    transfer of this program is strictly prohibited.
  7.  *
  8.  *      Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989 FairCom Corporation
  9.  *    (Subject to limited distribution and
  10.  *     restricted disclosure only.)
  11.  *    *** ALL RIGHTS RESERVED ***
  12.  *
  13.  *    4006 West Broadway
  14.  *    Columbia, MO 65203
  15.  *
  16.  *
  17.  *    c-tree(R)    Version 4.3
  18.  *            Release C
  19.  *            February 7, 1989 17:30
  20.  *
  21.  */
  22.  
  23. #include "ctstdr.h"        /* standard i/o header         */
  24. #include "ctoptn.h"        /* c-tree configuration options */
  25. #include "cterrc.h"        /* c-tree error codes        */
  26. #include "ctstrc.h"        /* c-tree data structures    */
  27. #include "ctgvar.h"        /* c-tree global variables    */
  28.  
  29. #ifdef CT_ANSI
  30. int fseek();
  31. #else
  32. LONG  lseek();
  33. #endif
  34.  
  35. COUNT uerr();
  36.  
  37. COUNT ctseek(ctnum,recbyt)
  38. PFAST CTFILE *ctnum;
  39. POINTER           recbyt;
  40. {
  41. #ifdef CT_ANSI
  42.     if (fseek(ctnum->fd,ctnum->sekpos = recbyt,SEEK_SET))
  43.         return(SEEK_ERR);
  44.     else
  45.         return(NO_ERROR);
  46. #else
  47.     if (ctnum->sekpos == recbyt)
  48.         return(NO_ERROR);
  49.     else if (lseek(ctnum->fd,ctnum->sekpos = recbyt,0) < 0L)
  50.            return(SEEK_ERR);
  51.     else
  52.         return(NO_ERROR);
  53. #endif
  54. }
  55.  
  56. COUNT ctio(op_code,ctnum,recbyt,bufadr,iosize)
  57. COUNT       op_code;    /* CTREAD or CTWRITE */
  58. CTFILE          *ctnum;
  59. LONG             recbyt;
  60. TEXT                   *bufadr;
  61. #ifdef CT_ANSI
  62. size_t                       iosize;
  63. #else
  64. unsigned int                   iosize;
  65. #endif
  66. {
  67. #ifdef CT_ANSI
  68.     size_t fread(),fwrite();
  69. #else
  70.     int read(),write();
  71. #endif
  72.  
  73.     if (ctseek(ctnum,recbyt))
  74.         return(uerr(SEEK_ERR));
  75.  
  76.     if (!iosize)
  77.         iosize = ctnum->reclen;
  78.     if (op_code == CTREAD) {
  79. #ifdef CT_ANSI
  80.         if (fread(bufadr,iosize,1,ctnum->fd) != 1) {
  81. #else
  82.         if (read(ctnum->fd,bufadr,iosize) != iosize) {
  83. #endif
  84.             ctnum->sekpos = -1L;
  85.             return(uerr(READ_ERR));
  86.         }
  87.     } else {
  88. #ifdef CT_ANSI
  89.         if (fwrite(bufadr,iosize,1,ctnum->fd) != 1) {
  90. #else
  91.         if (write(ctnum->fd,bufadr,iosize) != iosize) {
  92. #endif
  93.             ctnum->sekpos = -1L;
  94.             return(uerr(WRITE_ERR));
  95.         }
  96.     }
  97.     ctnum->sekpos += iosize;
  98.     return(NO_ERROR);
  99. }
  100.  
  101. COUNT mbclos( ctnum,clmode)
  102. PFAST CTFILE *ctnum;
  103. COUNT            clmode;    /* COMPLETE or PARTIAL */
  104. {
  105.     if (!(ctnum->flmode & PERMANENT))
  106.         ct_numvfil--;
  107. #ifdef CT_ANSI
  108.     return((COUNT) fclose(ctnum->fd));
  109. #else
  110.     return((COUNT) close(ctnum->fd));
  111. #endif
  112. }
  113.  
  114. COUNT dltfil(filnam)
  115. TEXT        *filnam;
  116. {
  117.     if (remove(filnam))
  118.         return(uerr_cod = DLTF_ERR);
  119.     else
  120.         return(NO_ERROR);
  121. }
  122.  
  123. /* end of ctclb3.c */
  124.