openbsd-ports/editors/ee/patches/patch-ee_c
brad adfc78ceb2 fix temp file issue.
From FreeBSD
2006-01-27 22:45:52 +00:00

128 lines
3.0 KiB
Plaintext

$OpenBSD: patch-ee_c,v 1.3 2006/01/27 22:45:52 brad Exp $
--- ee.c.orig Fri Sep 20 20:46:16 2002
+++ ee.c Sat Jan 14 19:59:25 2006
@@ -300,7 +300,7 @@ void finish P_((void));
int quit P_((int noverify));
void edit_abort P_((int arg));
void delete_text P_((void));
-int write_file P_((char *file_name));
+int write_file P_((char *file_name, int warn_if_exists));
int search P_((int display_message));
void search_prompt P_((void));
void del_char P_((void));
@@ -931,7 +931,7 @@ int temp_int;
int
out_char(window, character, column) /* output non-printing character */
WINDOW *window;
-char character;
+int character;
int column;
{
int i1, i2;
@@ -979,7 +979,7 @@ int column;
int
len_char(character, column) /* return the length of the character */
-char character;
+int character;
int column; /* the column must be known to provide spacing for tabs */
{
int length;
@@ -1694,7 +1694,7 @@ char *cmd_str1;
cmd_str = cmd_str2 = get_string(file_write_prompt_str, TRUE);
}
tmp_file = resolve_name(cmd_str);
- write_file(tmp_file);
+ write_file(tmp_file, 1);
if (tmp_file != cmd_str)
free(tmp_file);
}
@@ -2401,7 +2401,7 @@ finish() /* prepare to exit edit session
file_name = tmp_file;
}
- if (write_file(file_name))
+ if (write_file(file_name, 1))
{
text_changes = FALSE;
quit(0);
@@ -2477,8 +2477,9 @@ delete_text()
}
int
-write_file(file_name)
+write_file(file_name, warn_if_exists)
char *file_name;
+int warn_if_exists;
{
char cr;
char *tmp_point;
@@ -2488,7 +2489,8 @@ char *file_name;
int write_flag = TRUE;
charac = lines = 0;
- if ((in_file_name == NULL) || strcmp(in_file_name, file_name))
+ if (warn_if_exists &&
+ ((in_file_name == NULL) || strcmp(in_file_name, file_name)))
{
if ((temp_fp = fopen(file_name, "r")))
{
@@ -3734,7 +3736,7 @@ int arg;
{
string = get_string(file_write_prompt_str, TRUE);
tmp_file = resolve_name(string);
- write_file(tmp_file);
+ write_file(tmp_file, 1);
if (tmp_file != string)
free(tmp_file);
free(string);
@@ -3771,7 +3773,7 @@ int arg;
string = tmp_file;
}
}
- if (write_file(string))
+ if (write_file(string, 1))
{
in_file_name = string;
text_changes = FALSE;
@@ -4080,7 +4082,7 @@ Format() /* format the paragraph accordi
}
unsigned char *init_name[3] = {
- "/usr/local/lib/init.ee",
+ SYSCONFDIR "/init.ee",
NULL,
".init.ee"
};
@@ -4382,17 +4384,25 @@ spell_op() /* check spelling of words in
void
ispell_op()
{
- char name[128];
+ char template[128], *name;
char string[256];
- int pid;
+ int fd;
if (restrict_mode())
{
return;
}
- pid = getpid();
- sprintf(name, "/tmp/ee.%d", pid);
- if (write_file(name))
+ (void)sprintf(template, "/tmp/ee.XXXXXXXX");
+ name = mktemp(&template[0]);
+ fd = open(name, O_CREAT | O_EXCL | O_RDWR, 0600);
+ if (fd < 0) {
+ wmove(com_win, 0, 0);
+ wprintw(com_win, create_file_fail_msg, name);
+ wrefresh(com_win);
+ return;
+ }
+ close(fd);
+ if (write_file(name, 0))
{
sprintf(string, "ispell %s", name);
sh_command(string);