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

Defined functions

IIgetc defined in line 106; used 6 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 899
Valid CSS Valid XHTML 1.0 Strict