Mercurial > vim
comparison src/fileio.c @ 1303:da0991871b02 v7.1.017
updated for version 7.1-017
author | vimboss |
---|---|
date | Thu, 28 Jun 2007 20:02:32 +0000 |
parents | 4d2585cf5950 |
children | dbd226be80b1 |
comparison
equal
deleted
inserted
replaced
1302:7281a86ae640 | 1303:da0991871b02 |
---|---|
422 * MS-Windows allows opening a device, but we will probably get stuck | 422 * MS-Windows allows opening a device, but we will probably get stuck |
423 * trying to read it. | 423 * trying to read it. |
424 */ | 424 */ |
425 if (!p_odev && mch_nodetype(fname) == NODE_WRITABLE) | 425 if (!p_odev && mch_nodetype(fname) == NODE_WRITABLE) |
426 { | 426 { |
427 filemess(curbuf, fname, (char_u *)_("is a device (disabled with 'opendevice' option"), 0); | 427 filemess(curbuf, fname, (char_u *)_("is a device (disabled with 'opendevice' option)"), 0); |
428 msg_end(); | 428 msg_end(); |
429 msg_scroll = msg_save; | 429 msg_scroll = msg_save; |
430 return FAIL; | 430 return FAIL; |
431 } | 431 } |
432 # endif | 432 # endif |
2732 /* Older DECC compiler for VAX doesn't define MIN() */ | 2732 /* Older DECC compiler for VAX doesn't define MIN() */ |
2733 # define MIN(a, b) ((a) < (b) ? (a) : (b)) | 2733 # define MIN(a, b) ((a) < (b) ? (a) : (b)) |
2734 #endif | 2734 #endif |
2735 | 2735 |
2736 /* | 2736 /* |
2737 * Return TRUE if a file appears to be read-only from the file permissions. | |
2738 */ | |
2739 int | |
2740 check_file_readonly(fname, perm) | |
2741 char_u *fname; /* full path to file */ | |
2742 int perm; /* known permissions on file */ | |
2743 { | |
2744 #ifndef USE_MCH_ACCESS | |
2745 int fd = 0; | |
2746 #endif | |
2747 | |
2748 return ( | |
2749 #ifdef USE_MCH_ACCESS | |
2750 # ifdef UNIX | |
2751 (perm & 0222) == 0 || | |
2752 # endif | |
2753 mch_access((char *)fname, W_OK) | |
2754 #else | |
2755 (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0 | |
2756 ? TRUE : (close(fd), FALSE) | |
2757 #endif | |
2758 ); | |
2759 } | |
2760 | |
2761 | |
2762 /* | |
2737 * buf_write() - write to file "fname" lines "start" through "end" | 2763 * buf_write() - write to file "fname" lines "start" through "end" |
2738 * | 2764 * |
2739 * We do our own buffering here because fwrite() is so slow. | 2765 * We do our own buffering here because fwrite() is so slow. |
2740 * | 2766 * |
2741 * If "forceit" is true, we don't care for errors when attempting backups. | 2767 * If "forceit" is true, we don't care for errors when attempting backups. |
3217 { | 3243 { |
3218 /* | 3244 /* |
3219 * Check if the file is really writable (when renaming the file to | 3245 * Check if the file is really writable (when renaming the file to |
3220 * make a backup we won't discover it later). | 3246 * make a backup we won't discover it later). |
3221 */ | 3247 */ |
3222 file_readonly = ( | 3248 file_readonly = check_file_readonly(fname, (int)perm); |
3223 # ifdef USE_MCH_ACCESS | 3249 |
3224 # ifdef UNIX | |
3225 (perm & 0222) == 0 || | |
3226 # endif | |
3227 mch_access((char *)fname, W_OK) | |
3228 # else | |
3229 (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0 | |
3230 ? TRUE : (close(fd), FALSE) | |
3231 # endif | |
3232 ); | |
3233 if (!forceit && file_readonly) | 3250 if (!forceit && file_readonly) |
3234 { | 3251 { |
3235 if (vim_strchr(p_cpo, CPO_FWRITE) != NULL) | 3252 if (vim_strchr(p_cpo, CPO_FWRITE) != NULL) |
3236 { | 3253 { |
3237 errnum = (char_u *)"E504: "; | 3254 errnum = (char_u *)"E504: "; |