Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
f5edbeda
...
f5edbeda25f0f79609a790d675c9c4dc5d07282d
authored
2002-01-17 22:29:30 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
New function mu_tempfile().
1 parent
fff7abb9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
include/mailutils/mutil.h
mailbox/mutil.c
include/mailutils/mutil.h
View file @
f5edbed
...
...
@@ -76,6 +76,7 @@ extern struct passwd * getpwnam_virtual __P((const char *u));
extern
char
*
mu_get_user_email
__P
((
char
*
name
));
extern
char
*
mu_normalize_path
__P
((
char
*
path
,
const
char
*
delim
));
extern
char
*
mu_normalize_maildir
__P
((
const
char
*
dir
));
extern
int
mu_tempfile
__P
((
const
char
*
tmpdir
,
char
**
namep
));
#ifdef __cplusplus
}
...
...
mailbox/mutil.c
View file @
f5edbed
...
...
@@ -32,6 +32,7 @@
#include <netdb.h>
#include <errno.h>
#include <mailutils/error.h>
#include <mailutils/mutil.h>
#include <mailutils/iterator.h>
...
...
@@ -529,3 +530,58 @@ mu_normalize_maildir (const char *dir)
}
}
/* Create and open a temporary file. Be vary careful about it, since we
may be running with extra privilege i.e setgid().
Returns file descriptor of the open file.
If namep is not NULL, the pointer to the malloced file name will
be stored there. Otherwise, the file is unlinked right after open,
i.e. it will disappear after close(fd). */
#ifndef P_tmpdir
# define P_tmpdir "/tmp"
#endif
int
mu_tempfile
(
const
char
*
tmpdir
,
char
**
namep
)
{
char
*
filename
;
int
fd
;
if
(
!
tmpdir
)
tmpdir
=
(
getenv
(
"TMPDIR"
))
?
getenv
(
"TMPDIR"
)
:
P_tmpdir
;
filename
=
malloc
(
strlen
(
tmpdir
)
+
/*'/'*/
1
+
/* "muXXXXXX" */
8
+
1
);
if
(
!
filename
)
return
-
1
;
sprintf
(
filename
,
"%s/muXXXXXX"
,
tmpdir
);
#ifdef HAVE_MKSTEMP
{
int
save_mask
=
umask
(
077
);
fd
=
mkstemp
(
filename
);
umask
(
save_mask
);
}
#else
if
(
mktemp
(
filename
))
fd
=
open
(
filename
,
O_CREAT
|
O_EXCL
|
O_RDWR
,
0600
);
else
fd
=
-
1
;
#endif
if
(
fd
==
-
1
)
{
mu_error
(
"Can not open temporary file: %s"
,
strerror
(
errno
));
free
(
filename
);
return
-
1
;
}
if
(
namep
)
*
namep
=
filename
;
else
{
unlink
(
filename
);
free
(
filename
);
}
return
fd
;
}
...
...
Please
register
or
sign in
to post a comment