Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / remove.c
blob3df7ba134e0c4d808fbeaf8fdc866b609f93269d
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* REMOVE 3
6 /* SUMMARY
7 /* remove or stash away file
8 /* SYNOPSIS
9 /* \fBint REMOVE(path)\fR
10 /* \fBconst char *path;\fR
11 /* DESCRIPTION
12 /* \fBREMOVE()\fR removes a file, or renames it to a unique name,
13 /* depending on the setting of the boolean \fBvar_dont_remove\fR
14 /* flag.
15 /* DIAGNOSTICS
16 /* The result is 0 in case of success, -1 in case of trouble.
17 /* The global \fBerrno\fR variable reflects the nature of the
18 /* problem.
19 /* FILES
20 /* saved/*, stashed-away files.
21 /* SEE ALSO
22 /* remove(3)
23 /* LICENSE
24 /* .ad
25 /* .fi
26 /* The Secure Mailer license must be distributed with this software.
27 /* AUTHOR(S)
28 /* Wietse Venema
29 /* IBM T.J. Watson Research
30 /* P.O. Box 704
31 /* Yorktown Heights, NY 10598, USA
32 /*--*/
34 /* System library. */
36 #include <sys_defs.h>
37 #include <sys/stat.h>
38 #include <stdio.h>
39 #include <string.h>
40 #include <stdlib.h>
41 #include <unistd.h>
43 /* Utility library. */
45 #include <vstring.h>
47 /* Global library. */
49 #include <mail_params.h>
51 /* REMOVE - squirrel away a file instead of removing it */
53 int REMOVE(const char *path)
55 static VSTRING *dest;
56 char *slash;
57 struct stat st;
59 if (var_dont_remove == 0) {
60 return (remove(path));
61 } else {
62 if (dest == 0)
63 dest = vstring_alloc(10);
64 vstring_sprintf(dest, "saved/%s", ((slash = strrchr(path, '/')) != 0) ?
65 slash + 1 : path);
66 for (;;) {
67 if (stat(vstring_str(dest), &st) < 0)
68 break;
69 vstring_strcat(dest, "+");
71 return (rename(path, vstring_str(dest)));