BSD 3 development
[unix-history] / .ref-BSD-2 / src / net / prmail.c
CommitLineData
60cd0afa
ES
1/* Copyright (c) 1979 Regents of the University of California */
2# include <stdio.h>
3# include "mach.h"
4# ifdef V7
5# define MAILDIR "/usr/spool/mail"
6# else
7# define MAILDIR "/usr/mail"
8# endif
9main(){ /* prmail - print mail for user */
10 /* should print of others too */
11 struct stat statbuf;
12 FILE *f;
13 char fn[100],buf[BUFSIZ],outbuf[BUFSIZ],*s;
14 int i;
15 setbuf(stdout,outbuf);
16 s = getun(getuid()); /* always returns a str */
17 if(strcmp(s,"UNKNOWN") == 0){
18 perror("Unknown user");
19 exit(1);
20 }
21 sprintf(fn,"%s/%s",MAILDIR,s);
22 if(stat(fn,&statbuf) < 0 || getsize(&statbuf) == 0L){
23 printf("No mail.\n");
24 exit(0);
25 }
26 f = fopen(fn,"r");
27 if(f == NULL){
28 perror(fn);
29 exit(1);
30 }
31 while((i = fread(buf,1,BUFSIZ,f)) > 0)
32 fwrite(buf,1,i,stdout);
33 fclose(f);
34 exit(0);
35 }