home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / libsmall / active.slow.c next >
C/C++ Source or Header  |  1993-03-09  |  1KB  |  65 lines

  1. /*
  2.  * active file access functions (small, slow, on-disk version)
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include "news.h"
  8. #include "fgetmfs.h"
  9.  
  10. /* private */
  11. static long fpos = -1;        /* set by actfind, read by actwrnum */
  12.  
  13. /* ARGSUSED */
  14. statust
  15. actfload(fp)
  16. FILE *fp;
  17. {
  18.     return ST_OKAY;
  19. }
  20.  
  21. /* ARGSUSED */
  22. statust
  23. actfsync(fp)
  24. FILE *fp;
  25. {
  26.     return ST_OKAY;
  27. }
  28.  
  29. /*
  30.  * search on stream "fp" for group "ng" and return a pointer
  31.  * to the active file line for it, or 0 if none.
  32.  * actload has previously been called.
  33.  */
  34. char *
  35. actfind(fp, ng, nglen)
  36. register FILE *fp;
  37. register char *ng;
  38. register int nglen;
  39. {
  40.     static char *line = NULL;
  41.  
  42.     if (line != NULL)
  43.         free(line);
  44.     rewind(fp);
  45.     for (fpos = ftell(fp); (line = fgetms(fp)) != NULL;
  46.          fpos = ftell(fp), free(line))
  47.         if (STREQN(line, ng, nglen) && line[nglen] == ' ')
  48.             return line;        /* free on next entry */
  49.     return NULL;
  50. }
  51.  
  52. statust
  53. actfwrnum(fp, line)        /* overwrite last line found with "line" */
  54. register FILE *fp;
  55. char *line;
  56. {
  57.     if (fseek(fp, fpos, 0) != EOF &&    /* back up */
  58.         fputs(line, fp) != EOF && fflush(fp) != EOF)
  59.         return ST_OKAY;
  60.     else {
  61.         persistent(NOART, '\0', "write failed to active", "");
  62.         return ST_DROPPED|ST_NEEDATTN;
  63.     }
  64. }
  65.