home *** CD-ROM | disk | FTP | other *** search
- /* tamprint version 1.0, 4/23/90. */
-
- #include <stdio.h>
- #include <sys/file.h>
- #ifdef BSD
- #include <limits.h>
- #endif
- #include <pwd.h>
-
- #ifndef TAMDIR
- #define TAMDIR "/usr/spool/tam"
- #endif
-
- #ifndef BUFSIZ
- #define BUFSIZ 1024
- #endif
-
- main()
- {
- struct passwd *pw;
- char path[sizeof(TAMDIR) + 11];
- int fd;
- char buf[BUFSIZ];
- int r;
-
- if (!(pw = getpwuid(getuid())))
- {
- fprintf(stderr,"tamprint: fatal: who are you?\n");
- exit(1);
- }
- (void) sprintf(path,"%s/%s",TAMDIR,pw->pw_name);
- if ((fd = open(path,O_RDONLY)) == -1)
- {
- perror("tamprint: fatal: can't read tam spool file");
- exit(2);
- }
- if (flock(fd,LOCK_EX) == -1)
- {
- perror("tamprint: fatal: can't lock tam spool file");
- exit(3);
- }
- while ((r = read(fd,buf,sizeof(buf))) > 0)
- if (write(1,buf,r) < r)
- {
- /* This may happen, incorrectly, if the output is nonblocking. */
- /* We assume the usual convention that you never pass nonblocking fds. */
- perror("tamprint: fatal: write error");
- exit(5);
- }
- if (r < 0)
- {
- perror("tamprint: fatal: read error");
- exit(4);
- }
- exit(0);
- }
-