home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / Watcher / open_hf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-14  |  947 b   |  47 lines

  1. /*
  2.    open_hf: open the history file for reading, taking care of the errors
  3.    that can occur.
  4.  
  5.    Note that a missing history file is not an error.  We just don't do
  6.    anything that uses previous values.
  7.  
  8.    Copyright (C) the University of New Mexico
  9. */
  10.  
  11. #include "defs.h"
  12. #include <errno.h>
  13.  
  14. FILE *
  15. open_hf()
  16. {
  17.     extern int vflag;
  18.     extern char *histfilename;
  19.     extern int errno;
  20.     extern char *sys_errlist[];
  21.     extern struct old_cmd_st *chead;
  22.  
  23.     FILE *hf;
  24.  
  25.     if (vflag)
  26.         printf("Using %s for historyfile\n", histfilename);
  27.  
  28.     hf = fopen(histfilename, "r");
  29.     if (hf == NULL) {
  30.         if (errno == ENOENT) {
  31.             if (vflag)
  32.                 printf("This is a first run.\n");
  33.         }
  34.         else { /* some other error */
  35.             fprintf(stderr, "Warning: ");
  36.             fprintf(stderr, "unable to open history file.\n");
  37.             fprintf(stderr, "%s: %s\n", histfilename,
  38.                 sys_errlist[errno]);
  39.             fprintf(stderr, "Ignoring history file.\n\n");
  40.         }
  41.         chead = NULL;
  42.         return NULL;
  43.     }
  44.  
  45.     return hf;
  46. }
  47.