#include "portable.h"
#include <stdio.h>
+#include <sys/stat.h>
#include <ac/stdlib.h>
#include <ac/wait.h>
#include <ac/unistd.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
static int ovalues( char *attr );
static void write_entry( void );
-static char *entry_temp_file;
+static char entry_temp_file[L_tmpnam];
void
{
FILE *fp;
char *cp, *editor = UD_DEFAULT_EDITOR;
- static char template[MED_BUF_SIZE];
+ int tmpfd;
#ifndef HAVE_SPAWNLP
int pid;
int status;
#endif
/* write the entry into a temp file */
- (void) strcpy(template, "/tmp/udEdit.XXXXXX");
- if ((entry_temp_file = mktemp(template)) == NULL) {
- perror("mktemp");
- return(-1);
+ if (tmpnam(entry_temp_file) == NULL) {
+ perror("tmpnam");
+ return -1;
}
- if ((fp = fopen(entry_temp_file, "w")) == NULL) {
- perror("fopen");
+ if ((tmpfd = open(entry_temp_file, O_WRONLY|O_CREAT|O_EXCL, 0600)) == -1) {
+ perror(entry_temp_file);
+ return -1;
+ }
+ if ((fp = fdopen(tmpfd, "w")) == NULL) {
+ perror("fdopen");
return(-1);
}
fprintf(fp, "## Directory entry of %s\n", Entry.name);