Commit 206c4704 206c470477c8c28b2a253e3d6f18c24ebeba47e6 by Sergey Poznyakoff

Removed util_tempfile().

1 parent 26adedc2
...@@ -29,53 +29,6 @@ util_error (char *fmt, ...) ...@@ -29,53 +29,6 @@ util_error (char *fmt, ...)
29 va_end (ap); 29 va_end (ap);
30 } 30 }
31 31
32 int
33 util_tempfile (char **namep)
34 {
35 char *filename;
36 char *tmpdir;
37 int fd;
38
39 /* We have to be extra careful about opening temporary files, since we
40 may be running with extra privilege i.e setgid(). */
41 tmpdir = (getenv ("TMPDIR")) ? getenv ("TMPDIR") : "/tmp";
42
43 filename = malloc (strlen (tmpdir) + /*'/' */ 1 + /* "muXXXXXX" */ 8 + 1);
44 if (!filename)
45 return -1;
46 sprintf (filename, "%s/muXXXXXX", tmpdir);
47
48 #ifdef HAVE_MKSTEMP
49 {
50 int save_mask = umask (077);
51 fd = mkstemp (filename);
52 umask (save_mask);
53 }
54 #else
55 if (mktemp (filename))
56 fd = open (filename, O_CREAT | O_EXCL | O_RDWR, 0600);
57 else
58 fd = -1;
59 #endif
60
61 if (fd == -1)
62 {
63 util_error ("Can not open temporary file: %s", strerror (errno));
64 free (filename);
65 return -1;
66 }
67
68 if (namep)
69 *namep = filename;
70 else
71 {
72 unlink (filename);
73 free (filename);
74 }
75
76 return fd;
77 }
78
79 char * 32 char *
80 util_get_sender (int msgno) 33 util_get_sender (int msgno)
81 { 34 {
......
...@@ -824,53 +824,6 @@ util_help (const struct mail_command_entry *table, char *word) ...@@ -824,53 +824,6 @@ util_help (const struct mail_command_entry *table, char *word)
824 return 1; 824 return 1;
825 } 825 }
826 826
827 int
828 util_tempfile(char **namep)
829 {
830 char *filename;
831 const char *tmpdir;
832 int fd;
833
834 /* We have to be extra careful about opening temporary files, since we
835 may be running with extra privilege i.e setgid(). */
836 tmpdir = (getenv ("TMPDIR")) ? getenv ("TMPDIR") : "/tmp";
837
838 filename = malloc (strlen (tmpdir) + /*'/'*/1 + /* "muXXXXXX" */8 + 1);
839 if (!filename)
840 return -1;
841 sprintf (filename, "%s/muXXXXXX", tmpdir);
842
843 #ifdef HAVE_MKSTEMP
844 {
845 int save_mask = umask(077);
846 fd = mkstemp (filename);
847 umask(save_mask);
848 }
849 #else
850 if (mktemp (filename))
851 fd = open(filename, O_CREAT|O_EXCL|O_RDWR, 0600);
852 else
853 fd = -1;
854 #endif
855
856 if (fd == -1)
857 {
858 util_error("Can not open temporary file: %s", strerror(errno));
859 free(filename);
860 return -1;
861 }
862
863 if (namep)
864 *namep = filename;
865 else
866 {
867 unlink(filename);
868 free(filename);
869 }
870
871 return fd;
872 }
873
874 static int 827 static int
875 util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part) 828 util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
876 { 829 {
......