From db31e4b3c4a27cd945c38259a72c3a09bd963e2f Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Fri, 1 Nov 2002 20:24:07 +0000 Subject: [PATCH] * main.c (main): Use O_TRUNC when opening the file to write the last working directory. Fix segmentation fault when exiting while on VFS. * util.c (mc_mkstemps): Use O_TRUNC to open temporary files. --- src/ChangeLog | 7 +++++++ src/main.c | 9 +++++---- src/util.c | 14 ++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index ce114ece8..d023f0542 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2002-11-01 Pavel Roskin + + * main.c (main): Use O_TRUNC when opening the file to write the + last working directory. Fix segmentation fault when exiting + while on VFS. + * util.c (mc_mkstemps): Use O_TRUNC to open temporary files. + 2002-10-31 Andrew V. Samoilov * view.c (normal_search) [HAVE_CHARSET]: Fix segmentation fault diff --git a/src/main.c b/src/main.c index 8ff20ba97..489e01010 100644 --- a/src/main.c +++ b/src/main.c @@ -2527,10 +2527,11 @@ main (int argc, char *argv[]) /* On NT, home_dir is malloced */ g_free (home_dir); #endif - if (last_wd_file && !print_last_revert && !edit_one_file - && !view_one_file) { - int last_wd_fd = open (last_wd_file, O_WRONLY | O_CREAT | O_EXCL, - S_IRUSR | S_IWUSR); + if (last_wd_file && last_wd_string && !print_last_revert + && !edit_one_file && !view_one_file) { + int last_wd_fd = + open (last_wd_file, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, + S_IRUSR | S_IWUSR); if (last_wd_fd != -1) { write (last_wd_fd, last_wd_string, strlen (last_wd_string)); diff --git a/src/util.c b/src/util.c index c2ad18e2b..921ceb10e 100644 --- a/src/util.c +++ b/src/util.c @@ -1193,7 +1193,8 @@ concat_dir_and_file (const char *dir, const char *file) * Result: * handle of the open file or -1 if couldn't open any. */ -int mc_mkstemps(char **pname, const char *prefix, const char *suffix) +int +mc_mkstemps (char **pname, const char *prefix, const char *suffix) { static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; @@ -1204,7 +1205,7 @@ int mc_mkstemps(char **pname, const char *prefix, const char *suffix) char *XXXXXX; int count; - if (strchr(prefix, PATH_SEP) == NULL) { + if (strchr (prefix, PATH_SEP) == NULL) { /* Add prefix first to find the position of XXXXXX */ tmpbase = concat_dir_and_file (mc_tmpdir (), prefix); } else { @@ -1214,7 +1215,7 @@ int mc_mkstemps(char **pname, const char *prefix, const char *suffix) tmpname = g_strconcat (tmpbase, "XXXXXX", suffix, NULL); *pname = tmpname; XXXXXX = &tmpname[strlen (tmpbase)]; - g_free(tmpbase); + g_free (tmpbase); /* Get some more or less random data. */ gettimeofday (&tv, NULL); @@ -1237,15 +1238,16 @@ int mc_mkstemps(char **pname, const char *prefix, const char *suffix) v /= 62; XXXXXX[5] = letters[v % 62]; - fd = open (tmpname, O_RDWR|O_CREAT|O_EXCL, 0600); + fd = open (tmpname, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, + S_IRUSR | S_IWUSR); if (fd >= 0) { /* Successfully created. */ return fd; } /* This is a random value. It is only necessary that the next - TMP_MAX values generated by adding 7777 to VALUE are different - with (module 2^32). */ + TMP_MAX values generated by adding 7777 to VALUE are different + with (module 2^32). */ value += 7777; }