Mercurial > vim
comparison src/ex_cmds.c @ 557:862863033fdd v7.0158
updated for version 7.0158
author | vimboss |
---|---|
date | Wed, 23 Nov 2005 21:25:05 +0000 |
parents | c8b6b7e1005d |
children | 8b84fe17e147 |
comparison
equal
deleted
inserted
replaced
556:f9eaf0a9872d | 557:862863033fdd |
---|---|
10 /* | 10 /* |
11 * ex_cmds.c: some functions for command line commands | 11 * ex_cmds.c: some functions for command line commands |
12 */ | 12 */ |
13 | 13 |
14 #include "vim.h" | 14 #include "vim.h" |
15 #ifdef HAVE_FCNTL_H | |
16 # include <fcntl.h> | |
17 #endif | |
15 #include "version.h" | 18 #include "version.h" |
16 | 19 |
17 #ifdef FEAT_EX_EXTRA | 20 #ifdef FEAT_EX_EXTRA |
18 static int linelen __ARGS((int *has_tab)); | 21 static int linelen __ARGS((int *has_tab)); |
19 #endif | 22 #endif |
1795 break; | 1798 break; |
1796 } | 1799 } |
1797 | 1800 |
1798 if (tempname != NULL) | 1801 if (tempname != NULL) |
1799 { | 1802 { |
1800 fp_out = mch_fopen((char *)tempname, WRITEBIN); | 1803 int fd; |
1804 | |
1805 /* Use mch_open() to be able to use O_NOFOLLOW and set file | |
1806 * protection same as original file, but strip s-bit. */ | |
1807 fd = mch_open((char *)tempname, | |
1808 O_CREAT|O_EXTRA|O_EXCL|O_WRONLY|O_NOFOLLOW, | |
1809 (int)((st_old.st_mode & 0777) | 0600)); | |
1810 if (fd < 0) | |
1811 fp_out = NULL; | |
1812 else | |
1813 fp_out = fdopen(fd, WRITEBIN); | |
1801 | 1814 |
1802 /* | 1815 /* |
1803 * If we can't create in the same directory, try creating a | 1816 * If we can't create in the same directory, try creating a |
1804 * "normal" temp file. | 1817 * "normal" temp file. |
1805 */ | 1818 */ |
1807 { | 1820 { |
1808 vim_free(tempname); | 1821 vim_free(tempname); |
1809 if ((tempname = vim_tempname('o')) != NULL) | 1822 if ((tempname = vim_tempname('o')) != NULL) |
1810 fp_out = mch_fopen((char *)tempname, WRITEBIN); | 1823 fp_out = mch_fopen((char *)tempname, WRITEBIN); |
1811 } | 1824 } |
1812 #ifdef UNIX | 1825 |
1826 #if defined(UNIX) && defined(HAVE_FCHOWN) | |
1813 /* | 1827 /* |
1814 * Set file protection same as original file, but strip s-bit | 1828 * Make sure the owner can read/write it. This only works for |
1815 * and make sure the owner can read/write it. | 1829 * root. |
1816 */ | 1830 */ |
1817 if (fp_out != NULL) | 1831 if (fp_out != NULL) |
1818 { | 1832 (void)fchown(fileno(fp_out), st_old.st_uid, st_old.st_gid); |
1819 (void)mch_setperm(tempname, | |
1820 (long)((st_old.st_mode & 0777) | 0600)); | |
1821 /* this only works for root: */ | |
1822 (void)chown((char *)tempname, st_old.st_uid, st_old.st_gid); | |
1823 } | |
1824 #endif | 1833 #endif |
1825 } | 1834 } |
1826 } | 1835 } |
1827 | 1836 |
1828 /* | 1837 /* |