1: #
   2: # include   "../../ingres.h"
   3: # include   "../../pipes.h"
   4: # include   "IIglobals.h"
   5: 
   6: /*
   7: **  IIGETC.C -- File input routines
   8: **
   9: **	Defines:
  10: **		IIfopen()
  11: **		IIgetc()
  12: **		IIclose()
  13: **
  14: **	Requires:
  15: **		read()
  16: **		open()
  17: **
  18: **	Required By:
  19: **		IIp_err() -- to get text from error files
  20: **		IIgetpath();
  21: **		USER -- as Input routines
  22: **
  23: **	History:
  24: **		11/21/78 -- (marc) written to free IIp_err() [IIp_err.c] from
  25: **		depending on a single I/O package
  26: */
  27: 
  28: 
  29: 
  30: /*
  31: **  IIFOPEN -- Buffered input file open
  32: **
  33: **	Entirely analogous to fopen(III).
  34: **
  35: **	Parameters:
  36: **		file - file name to open for READ only
  37: **		iobuf - iob struct to use for this file
  38: **
  39: **	Returns:
  40: **		0  success
  41: **		-1 failure (errno set by open(II) call)
  42: **
  43: **	Side Effects:
  44: **		file activity
  45: **		sets up iobuf
  46: **
  47: **	Requires:
  48: **		open()
  49: **
  50: **	Called By:
  51: **		IIp_err() [IIp_err.c]
  52: **		USER
  53: **
  54: **	History:
  55: **		11/21/78 -- (marc) written
  56: */
  57: 
  58: IIfopen(file, iobuf)
  59: char        *file;
  60: struct iob  *iobuf;
  61: {
  62:     register struct iob *b;
  63: 
  64:     b = iobuf;
  65:     if ((b->fildes = open(file, 0)) < 0)
  66:         return (-1);
  67:     b->nleft = 0;
  68:     return (0);
  69: }
  70: 
  71: /*
  72: **  IIGETC -- Get a character from a file using buffered input
  73: **
  74: **	Entirely analogous to getc(III).
  75: **
  76: **	Parameters:
  77: **		iobuf -- iob struct for the file from which the character
  78: **			is to be taken
  79: **
  80: **	Returns:
  81: **		next character from file (16-bit no sign extension)
  82: **		-1 -- EOF or error (errno set by read)
  83: **
  84: **	Side Effects:
  85: **		file activity - may do a read ()
  86: **		fuddles iobuf to reflect number of characters left after call
  87: **
  88: **	Requires:
  89: **		read()
  90: **		an fopen(III) or IIfopen() [IIgetc.c] call on iobuf before
  91: **			being called. (It is unwise to call fopen(), the
  92: **			IIgetc(), because fopen() and getc(III) are both
  93: **			in /usr/source/s4/getc.c so the code will be
  94: **			duplicated).
  95: **
  96: **	Called By:
  97: **		IIp_err() [IIp_err.c]
  98: **		USER
  99: **
 100: **	History:
 101: **		11/21/78 -- (marc) written
 102: */
 103: 
 104: IIgetc(iobuf)
 105: struct iob  *iobuf;
 106: {
 107:     register struct iob *b;
 108:     register        i;
 109:     register        c;
 110: 
 111:     b = iobuf;
 112:     if (--b->nleft >= 0)
 113:     {
 114:         c = *b->nextp++ & 0377;
 115:         return (c);
 116:     }
 117: 
 118:     /* else fill the buffer */
 119:     i = read(b->fildes, b->buff, sizeof b->buff);
 120:     if (i > 0)
 121:     {
 122:         b->nextp = b->buff;
 123:         b->nleft = --i;
 124:         c = *b->nextp++ & 0377;
 125:         return (c);
 126:     }
 127:     /* EOF or error */
 128:     return (-1);
 129: }
 130: 
 131: /*
 132: **  IICLOSE -- Close a file opened with IIfopen
 133: **
 134: **	Parameters:
 135: **		buf -- io buffer
 136: **
 137: **	Returns:
 138: **		< 0 one error (errno set)
 139: **
 140: **	Side Effects:
 141: **		closes file
 142: **
 143: **	Requires:
 144: **		close(II)
 145: **
 146: **	Called By:
 147: **		USER
 148: */
 149: 
 150: IIclose(buf)
 151: struct iob  *buf;
 152: {
 153: 
 154:     return (close(buf->fildes));
 155: }
Last modified: 1980-12-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2162
Valid CSS Valid XHTML 1.0 Strict