3 /* This file contains the UNIX-specific parts of the "elvprsv" program. */
13 /* This variable is used to add extra error messages for mail sent to root */
16 /* This function returns the login name of the owner of a file */
17 char *ownername(filename
)
18 char *filename
; /* name of a file */
23 /* stat the file, to get its uid */
24 if (stat(filename
, &st
) < 0)
30 /* get the /etc/passwd entry for that user */
31 pw
= getpwuid(st
.st_uid
);
34 ps
= "uid not found in password file";
38 /* return the user's name */
43 /* This function sends a mail message to a given user, saying that a file
46 void mail(user
, file
, when
)
47 char *user
; /* name of user who should receive the mail */
48 char *file
; /* name of original text file that was preserved */
49 char *when
; /* description of why the file was preserved */
51 char cmd
[80];/* buffer used for constructing a "mail" command */
52 FILE *m
, *popen(); /* stream used for giving text to the "mail" program */
53 char *base
; /* basename of the file */
55 /* separate the directory name from the basename. */
56 for (base
= file
+ strlen(file
); --base
> file
&& *base
!= SLASH
; )
64 /* for anonymous buffers, pretend the name was "foo" */
65 if (!strcmp(base
, "*"))
70 /* open a pipe to the "mail" program */
72 sprintf(cmd
, "mail \"-s=%s preserved!\" %s", base
, user
);
74 sprintf(cmd
, "mail %s >/dev/null 2>/dev/null", user
);
79 /* Can't send mail! Hope the user figures it out. */
83 /* Tell the user that the file was preserved */
84 fprintf(m
, "A version of your file \"%s%c%s\"\n", file
, SLASH
, base
);
85 fprintf(m
, "was preserved when %s.\n", when
);
86 fprintf(m
, "To recover this file, do the following:\n");
89 fprintf(m
, " chd %s\n", file
);
91 fprintf(m
, " cd %s\n", file
);
93 fprintf(m
, " elvrec %s\n", base
);
95 fprintf(m
, "With fond wishes for a speedy recovery,\n");
96 fprintf(m
, " Elvis\n");
99 fprintf(m
, "\nP.S. %s\n", ps
);
103 /* close the stream */