aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Schwab2012-10-13 10:55:26 +0200
committerAndreas Schwab2012-10-13 10:55:26 +0200
commitce2fe65ae1abf53f5408e636a8bbee7b40ce3f2a (patch)
tree7b4fd924679a5a9d00ecb68de6c329816e369e99 /src
parent88ded8accac910447a8b5411f6e37443b1fd6be8 (diff)
downloademacs-ce2fe65ae1abf53f5408e636a8bbee7b40ce3f2a.tar.gz
emacs-ce2fe65ae1abf53f5408e636a8bbee7b40ce3f2a.zip
* fileio.c: Formatting fixes.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog4
-rw-r--r--src/fileio.c55
2 files changed, 30 insertions, 29 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 6c03ef0ba0a..f5b5bbdc7b1 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
12012-10-13 Andreas Schwab <schwab@linux-m68k.org>
2
3 * fileio.c: Formatting fixes.
4
12012-10-13 Paul Eggert <eggert@cs.ucla.edu> 52012-10-13 Paul Eggert <eggert@cs.ucla.edu>
2 6
3 Fix some stat-related races. 7 Fix some stat-related races.
diff --git a/src/fileio.c b/src/fileio.c
index 460eaf1e0b0..e3a91c2c9da 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1370,8 +1370,7 @@ See also the function `substitute-in-file-name'.")
1370 p = nm; 1370 p = nm;
1371 while (*p) 1371 while (*p)
1372 { 1372 {
1373 if (p[0] == '/' && p[1] == '/' 1373 if (p[0] == '/' && p[1] == '/')
1374 )
1375 nm = p + 1; 1374 nm = p + 1;
1376 if (p[0] == '/' && p[1] == '~') 1375 if (p[0] == '/' && p[1] == '~')
1377 nm = p + 1, lose = 1; 1376 nm = p + 1, lose = 1;
@@ -1510,17 +1509,16 @@ search_embedded_absfilename (char *nm, char *endp)
1510 1509
1511 for (p = nm + 1; p < endp; p++) 1510 for (p = nm + 1; p < endp; p++)
1512 { 1511 {
1513 if ((0 1512 if (IS_DIRECTORY_SEP (p[-1])
1514 || IS_DIRECTORY_SEP (p[-1]))
1515 && file_name_absolute_p (p) 1513 && file_name_absolute_p (p)
1516#if defined (WINDOWSNT) || defined (CYGWIN) 1514#if defined (WINDOWSNT) || defined (CYGWIN)
1517 /* // at start of file name is meaningful in Apollo, 1515 /* // at start of file name is meaningful in Apollo,
1518 WindowsNT and Cygwin systems. */ 1516 WindowsNT and Cygwin systems. */
1519 && !(IS_DIRECTORY_SEP (p[0]) && p - 1 == nm) 1517 && !(IS_DIRECTORY_SEP (p[0]) && p - 1 == nm)
1520#endif /* not (WINDOWSNT || CYGWIN) */ 1518#endif /* not (WINDOWSNT || CYGWIN) */
1521 ) 1519 )
1522 { 1520 {
1523 for (s = p; *s && (!IS_DIRECTORY_SEP (*s)); s++); 1521 for (s = p; *s && !IS_DIRECTORY_SEP (*s); s++);
1524 if (p[0] == '~' && s > p + 1) /* We've got "/~something/". */ 1522 if (p[0] == '~' && s > p + 1) /* We've got "/~something/". */
1525 { 1523 {
1526 char *o = alloca (s - p + 1); 1524 char *o = alloca (s - p + 1);
@@ -1735,7 +1733,7 @@ those `/' is discarded. */)
1735 *x = 0; 1733 *x = 0;
1736 1734
1737 /* If /~ or // appears, discard everything through first slash. */ 1735 /* If /~ or // appears, discard everything through first slash. */
1738 while ((p = search_embedded_absfilename (xnm, x))) 1736 while ((p = search_embedded_absfilename (xnm, x)) != NULL)
1739 /* This time we do not start over because we've already expanded envvars 1737 /* This time we do not start over because we've already expanded envvars
1740 and replaced $$ with $. Maybe we should start over as well, but we'd 1738 and replaced $$ with $. Maybe we should start over as well, but we'd
1741 need to quote some $ to $$ first. */ 1739 need to quote some $ to $$ first. */
@@ -2169,7 +2167,7 @@ With a prefix argument, TRASH is nil. */)
2169 2167
2170 encoded_file = ENCODE_FILE (filename); 2168 encoded_file = ENCODE_FILE (filename);
2171 2169
2172 if (0 > unlink (SSDATA (encoded_file))) 2170 if (unlink (SSDATA (encoded_file)) < 0)
2173 report_file_error ("Removing old name", list1 (filename)); 2171 report_file_error ("Removing old name", list1 (filename));
2174 return Qnil; 2172 return Qnil;
2175} 2173}
@@ -2218,8 +2216,8 @@ This is what happens in interactive use with M-x. */)
2218#endif 2216#endif
2219 ) 2217 )
2220 { 2218 {
2221 Lisp_Object fname = NILP (Ffile_directory_p (file)) 2219 Lisp_Object fname = (NILP (Ffile_directory_p (file))
2222 ? file : Fdirectory_file_name (file); 2220 ? file : Fdirectory_file_name (file));
2223 newname = Fexpand_file_name (Ffile_name_nondirectory (fname), newname); 2221 newname = Fexpand_file_name (Ffile_name_nondirectory (fname), newname);
2224 } 2222 }
2225 else 2223 else
@@ -2247,7 +2245,7 @@ This is what happens in interactive use with M-x. */)
2247 || INTEGERP (ok_if_already_exists)) 2245 || INTEGERP (ok_if_already_exists))
2248 barf_or_query_if_file_exists (newname, "rename to it", 2246 barf_or_query_if_file_exists (newname, "rename to it",
2249 INTEGERP (ok_if_already_exists), 0, 0); 2247 INTEGERP (ok_if_already_exists), 0, 0);
2250 if (0 > rename (SSDATA (encoded_file), SSDATA (encoded_newname))) 2248 if (rename (SSDATA (encoded_file), SSDATA (encoded_newname)) < 0)
2251 { 2249 {
2252 if (errno == EXDEV) 2250 if (errno == EXDEV)
2253 { 2251 {
@@ -2328,7 +2326,7 @@ This is what happens in interactive use with M-x. */)
2328 INTEGERP (ok_if_already_exists), 0, 0); 2326 INTEGERP (ok_if_already_exists), 0, 0);
2329 2327
2330 unlink (SSDATA (newname)); 2328 unlink (SSDATA (newname));
2331 if (0 > link (SSDATA (encoded_file), SSDATA (encoded_newname))) 2329 if (link (SSDATA (encoded_file), SSDATA (encoded_newname)) < 0)
2332 report_file_error ("Adding new name", list2 (file, newname)); 2330 report_file_error ("Adding new name", list2 (file, newname));
2333 2331
2334 UNGCPRO; 2332 UNGCPRO;
@@ -2385,15 +2383,14 @@ This happens for interactive use with M-x. */)
2385 || INTEGERP (ok_if_already_exists)) 2383 || INTEGERP (ok_if_already_exists))
2386 barf_or_query_if_file_exists (linkname, "make it a link", 2384 barf_or_query_if_file_exists (linkname, "make it a link",
2387 INTEGERP (ok_if_already_exists), 0, 0); 2385 INTEGERP (ok_if_already_exists), 0, 0);
2388 if (0 > symlink (SSDATA (encoded_filename), 2386 if (symlink (SSDATA (encoded_filename), SSDATA (encoded_linkname)) < 0)
2389 SSDATA (encoded_linkname)))
2390 { 2387 {
2391 /* If we didn't complain already, silently delete existing file. */ 2388 /* If we didn't complain already, silently delete existing file. */
2392 if (errno == EEXIST) 2389 if (errno == EEXIST)
2393 { 2390 {
2394 unlink (SSDATA (encoded_linkname)); 2391 unlink (SSDATA (encoded_linkname));
2395 if (0 <= symlink (SSDATA (encoded_filename), 2392 if (symlink (SSDATA (encoded_filename), SSDATA (encoded_linkname))
2396 SSDATA (encoded_linkname))) 2393 >= 0)
2397 { 2394 {
2398 UNGCPRO; 2395 UNGCPRO;
2399 return Qnil; 2396 return Qnil;
@@ -3203,7 +3200,7 @@ emacs_lseek (int fd, EMACS_INT offset, int whence)
3203{ 3200{
3204 /* Use "&" rather than "&&" to suppress a bogus GCC warning; see 3201 /* Use "&" rather than "&&" to suppress a bogus GCC warning; see
3205 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43772>. */ 3202 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43772>. */
3206 if (! ((TYPE_MINIMUM (off_t) <= offset) & (offset <= TYPE_MAXIMUM (off_t)))) 3203 if (! ((offset >= TYPE_MINIMUM (off_t)) & (offset <= TYPE_MAXIMUM (off_t))))
3207 { 3204 {
3208 errno = EINVAL; 3205 errno = EINVAL;
3209 return -1; 3206 return -1;
@@ -3376,7 +3373,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3376 3373
3377 if (!NILP (beg)) 3374 if (!NILP (beg))
3378 { 3375 {
3379 if (! (RANGED_INTEGERP (0, beg, TYPE_MAXIMUM (off_t)))) 3376 if (! RANGED_INTEGERP (0, beg, TYPE_MAXIMUM (off_t)))
3380 wrong_type_argument (intern ("file-offset"), beg); 3377 wrong_type_argument (intern ("file-offset"), beg);
3381 beg_offset = XFASTINT (beg); 3378 beg_offset = XFASTINT (beg);
3382 } 3379 }
@@ -3385,7 +3382,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
3385 3382
3386 if (!NILP (end)) 3383 if (!NILP (end))
3387 { 3384 {
3388 if (! (RANGED_INTEGERP (0, end, TYPE_MAXIMUM (off_t)))) 3385 if (! RANGED_INTEGERP (0, end, TYPE_MAXIMUM (off_t)))
3389 wrong_type_argument (intern ("file-offset"), end); 3386 wrong_type_argument (intern ("file-offset"), end);
3390 end_offset = XFASTINT (end); 3387 end_offset = XFASTINT (end);
3391 } 3388 }
@@ -3421,8 +3418,8 @@ variable `last-coding-system-used' to the coding system actually used. */)
3421 3418
3422 if (beg_offset < likely_end) 3419 if (beg_offset < likely_end)
3423 { 3420 {
3424 ptrdiff_t buf_bytes = 3421 ptrdiff_t buf_bytes
3425 Z_BYTE - (!NILP (replace) ? ZV_BYTE - BEGV_BYTE : 0); 3422 = Z_BYTE - (!NILP (replace) ? ZV_BYTE - BEGV_BYTE : 0);
3426 ptrdiff_t buf_growth_max = BUF_BYTES_MAX - buf_bytes; 3423 ptrdiff_t buf_growth_max = BUF_BYTES_MAX - buf_bytes;
3427 off_t likely_growth = likely_end - beg_offset; 3424 off_t likely_growth = likely_end - beg_offset;
3428 if (buf_growth_max < likely_growth) 3425 if (buf_growth_max < likely_growth)
@@ -5050,12 +5047,12 @@ e_write (int desc, Lisp_Object string, ptrdiff_t start, ptrdiff_t end,
5050 5047
5051 if (coding->produced > 0) 5048 if (coding->produced > 0)
5052 { 5049 {
5053 coding->produced -= 5050 coding->produced
5054 emacs_write (desc, 5051 -= emacs_write (desc,
5055 STRINGP (coding->dst_object) 5052 STRINGP (coding->dst_object)
5056 ? SSDATA (coding->dst_object) 5053 ? SSDATA (coding->dst_object)
5057 : (char *) BYTE_POS_ADDR (coding->dst_pos_byte), 5054 : (char *) BYTE_POS_ADDR (coding->dst_pos_byte),
5058 coding->produced); 5055 coding->produced);
5059 5056
5060 if (coding->produced) 5057 if (coding->produced)
5061 return 0; 5058 return 0;
@@ -5234,8 +5231,8 @@ auto_save_1 (void)
5234 if (stat (SSDATA (BVAR (current_buffer, filename)), &st) >= 0) 5231 if (stat (SSDATA (BVAR (current_buffer, filename)), &st) >= 0)
5235 /* But make sure we can overwrite it later! */ 5232 /* But make sure we can overwrite it later! */
5236 auto_save_mode_bits = (st.st_mode | 0600) & 0777; 5233 auto_save_mode_bits = (st.st_mode | 0600) & 0777;
5237 else if ((modes = Ffile_modes (BVAR (current_buffer, filename)), 5234 else if (modes = Ffile_modes (BVAR (current_buffer, filename)),
5238 INTEGERP (modes))) 5235 INTEGERP (modes))
5239 /* Remote files don't cooperate with stat. */ 5236 /* Remote files don't cooperate with stat. */
5240 auto_save_mode_bits = (XINT (modes) | 0600) & 0777; 5237 auto_save_mode_bits = (XINT (modes) | 0600) & 0777;
5241 } 5238 }