1: /*
   2:  *      Program Name:   syserrlst.c
   3:  *      Date: March 6, 1996
   4:  *      Author: S.M. Schultz
   5:  *
   6:  *      -----------------   Modification History   ---------------
   7:  *      Version Date            Reason For Modification
   8:  *      1.0     06Mar96         1. Initial release into the public domain.
   9: */
  10: 
  11: /*
  12:  * syserrlst - reads an error message from _PATH_SYSERRLST to a static
  13:  *	       buffer.
  14:  *
  15:  * __errlst - same as above but the caller must specify an error list file.
  16: */
  17: 
  18: #include <stdio.h>
  19: #include <stdlib.h>
  20: #include <sys/types.h>
  21: #include <sys/file.h>
  22: #include <sys/uio.h>
  23: #include <fcntl.h>
  24: #include <errno.h>
  25: #include <errlst.h>
  26: 
  27: static  char    msgstr[64];
  28:     char    *__errlst();
  29: 
  30: char *
  31: syserrlst(err)
  32:     int err;
  33:     {
  34: 
  35:     return(__errlst(err, _PATH_SYSERRLST));
  36:     }
  37: 
  38: /*
  39:  * Returns NULL if an error is encountered.  It is the responsiblity of the
  40:  * caller (strerror(3) is most cases) to convert NULL into a "Error N".
  41: */
  42: 
  43: char *
  44: __errlst(err, path)
  45:     int err;
  46:     char    *path;
  47:     {
  48:     register int    f;
  49:     register char   *retval = NULL;
  50:     int saverrno;
  51:     struct  iovec   iov[2];
  52:     off_t   off;
  53:     struct  ERRLST  emsg;
  54:     struct  ERRLSTHDR ehdr;
  55: 
  56:     saverrno = errno;
  57:     f = open(path, O_RDONLY);
  58:     if  (f < 0 || !path)
  59:         goto oops;
  60: 
  61:     if  (read(f, &ehdr, sizeof (ehdr)) != sizeof (ehdr))
  62:         goto oops;
  63: 
  64:     if  (err < 0 || err > ehdr.maxmsgnum || ehdr.maxmsgnum <= 0 ||
  65:          ehdr.magic != ERRMAGIC)
  66:         goto    oops;
  67: 
  68:     off = sizeof (ehdr) + ((off_t)sizeof (struct ERRLST) * err);
  69:     if  (lseek(f, off, L_SET) == (off_t)-1)
  70:         goto oops;
  71: 
  72:     if  (read(f, &emsg, sizeof (emsg)) != sizeof (emsg))
  73:         goto oops;
  74: 
  75:     if  (emsg.lenmsg >= sizeof (msgstr))
  76:         emsg.lenmsg = sizeof (msgstr) - 1;
  77: 
  78:     if  (lseek(f, emsg.offmsg, L_SET) == (off_t)-1)
  79:         goto oops;
  80: 
  81:     if  (read(f, msgstr, emsg.lenmsg) != emsg.lenmsg)
  82:         goto oops;
  83: 
  84:     retval = msgstr;
  85:     retval[emsg.lenmsg] = '\0';
  86: oops:
  87:     if  (f >= 0)
  88:         close(f);
  89:     errno = saverrno;
  90:     return(retval);
  91:     }

Defined functions

__errlst defined in line 43; used 2 times

Defined variables

msgstr defined in line 27; used 4 times
Last modified: 1996-03-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 117
Valid CSS Valid XHTML 1.0 Strict