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