home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume22 / auth-utils / part01 / tam / tamprint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-29  |  1.1 KB  |  57 lines

  1. /* tamprint version 1.0, 4/23/90. */
  2.  
  3. #include <stdio.h>
  4. #include <sys/file.h>
  5. #ifdef BSD
  6. #include <limits.h>
  7. #endif
  8. #include <pwd.h>
  9.  
  10. #ifndef TAMDIR
  11. #define TAMDIR "/usr/spool/tam"
  12. #endif
  13.  
  14. #ifndef BUFSIZ
  15. #define BUFSIZ 1024
  16. #endif
  17.  
  18. main()
  19. {
  20.  struct passwd *pw;
  21.  char path[sizeof(TAMDIR) + 11];
  22.  int fd;
  23.  char buf[BUFSIZ];
  24.  int r;
  25.  
  26.  if (!(pw = getpwuid(getuid())))
  27.   {
  28.    fprintf(stderr,"tamprint: fatal: who are you?\n");
  29.    exit(1);
  30.   }
  31.  (void) sprintf(path,"%s/%s",TAMDIR,pw->pw_name);
  32.  if ((fd = open(path,O_RDONLY)) == -1)
  33.   {
  34.    perror("tamprint: fatal: can't read tam spool file");
  35.    exit(2);
  36.   }
  37.  if (flock(fd,LOCK_EX) == -1)
  38.   {
  39.    perror("tamprint: fatal: can't lock tam spool file");
  40.    exit(3);
  41.   }
  42.  while ((r = read(fd,buf,sizeof(buf))) > 0)
  43.    if (write(1,buf,r) < r)
  44.     {
  45.      /* This may happen, incorrectly, if the output is nonblocking. */
  46.      /* We assume the usual convention that you never pass nonblocking fds. */
  47.      perror("tamprint: fatal: write error");
  48.      exit(5);
  49.     }
  50.  if (r < 0)
  51.   {
  52.    perror("tamprint: fatal: read error");
  53.    exit(4);
  54.   }
  55.  exit(0);
  56. }
  57.