X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fmisc.c;h=95934d17c196feb24a358385e2c2a8eff9ec215a;hb=46f09016e8219719179da09ee499981911054b5a;hp=73cb2c3deeea8432c2f7a77beaa897f3d0b30c12;hpb=f3da0c26b8fdfdd5db39e5fde8757ded273c2b51;p=chaz%2Ftar diff --git a/src/misc.c b/src/misc.c index 73cb2c3..95934d1 100644 --- a/src/misc.c +++ b/src/misc.c @@ -15,13 +15,14 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "system.h" -#include "rmt.h" +#include +#include #include "common.h" #include #include +#include static void call_arg_fatal (char const *, char const *) __attribute__ ((noreturn)); @@ -123,13 +124,13 @@ unquote_string (char *string) source++; break; - case 'n': - *destination++ = '\n'; + case 'a': + *destination++ = '\a'; source++; break; - case 't': - *destination++ = '\t'; + case 'b': + *destination++ = '\b'; source++; break; @@ -138,8 +139,8 @@ unquote_string (char *string) source++; break; - case 'b': - *destination++ = '\b'; + case 'n': + *destination++ = '\n'; source++; break; @@ -148,6 +149,16 @@ unquote_string (char *string) source++; break; + case 't': + *destination++ = '\t'; + source++; + break; + + case 'v': + *destination++ = '\v'; + source++; + break; + case '?': *destination++ = 0177; source++; @@ -207,14 +218,14 @@ static char *after_backup_name; static bool must_be_dot_or_slash (char const *file_name) { - file_name += FILESYSTEM_PREFIX_LEN (file_name); + file_name += FILE_SYSTEM_PREFIX_LEN (file_name); if (ISSLASH (file_name[0])) { for (;;) if (ISSLASH (file_name[1])) file_name++; - else if (file_name[1] == '.' + else if (file_name[1] == '.' && ISSLASH (file_name[2 + (file_name[2] == '.')])) file_name += 2 + (file_name[2] == '.'); else @@ -248,7 +259,7 @@ safer_rmdir (const char *file_name) return rmdir (file_name); } -/* Remove FILE_NAME, returning 1 on success. If FILE_NAME is a directory, +/* Remove FILE_NAME, returning 1 on success. If FILE_NAME is a directory, then if OPTION is RECURSIVE_REMOVE_OPTION is set remove FILE_NAME recursively; otherwise, remove it only if it is empty. If FILE_NAME is a directory that cannot be removed (e.g., because it is nonempty) @@ -258,9 +269,10 @@ safer_rmdir (const char *file_name) int remove_any_file (const char *file_name, enum remove_option option) { - /* Try unlink first if we are not root, as this saves us a system - call in the common case where we're removing a non-directory. */ - if (! we_are_root) + /* Try unlink first if we cannot unlink directories, as this saves + us a system call in the common case where we're removing a + non-directory. */ + if (cannot_unlink_dir ()) { if (unlink (file_name) == 0) return 1; @@ -278,7 +290,7 @@ remove_any_file (const char *file_name, enum remove_option option) switch (errno) { case ENOTDIR: - return we_are_root && unlink (file_name) == 0; + return cannot_unlink_dir () && unlink (file_name) == 0; case 0: case EEXIST: @@ -307,7 +319,8 @@ remove_any_file (const char *file_name, enum remove_option option) entry += entrylen + 1) { char *file_name_buffer = new_name (file_name, entry); - int r = remove_any_file (file_name_buffer, 1); + int r = remove_any_file (file_name_buffer, + RECURSIVE_REMOVE_OPTION); int e = errno; free (file_name_buffer); @@ -538,6 +551,10 @@ static void call_arg_error (char const *call, char const *name) { int e = errno; + /* TRANSLATORS: %s after `Cannot' is a function name, e.g. `Cannot open'. + Directly translating this to another language will not work, first because + %s itself is not translated. + Translate it as `%s: Function %s failed'. */ ERROR ((0, e, _("%s: Cannot %s"), quotearg_colon (name), call)); } @@ -547,6 +564,10 @@ static void call_arg_fatal (char const *call, char const *name) { int e = errno; + /* TRANSLATORS: %s after `Cannot' is a function name, e.g. `Cannot open'. + Directly translating this to another language will not work, first because + %s itself is not translated. + Translate it as `%s: Function %s failed'. */ FATAL_ERROR ((0, e, _("%s: Cannot %s"), quotearg_colon (name), call)); } @@ -556,6 +577,10 @@ static void call_arg_warn (char const *call, char const *name) { int e = errno; + /* TRANSLATORS: %s after `Cannot' is a function name, e.g. `Cannot open'. + Directly translating this to another language will not work, first because + %s itself is not translated. + Translate it as `%s: Function %s failed'. */ WARN ((0, e, _("%s: Warning: Cannot %s"), quotearg_colon (name), call)); } @@ -675,8 +700,8 @@ read_error_details (char const *name, off_t offset, size_t size) char buf[UINTMAX_STRSIZE_BOUND]; int e = errno; ERROR ((0, e, - ngettext ("%s: Read error at byte %s, reading %lu byte", - "%s: Read error at byte %s, reading %lu bytes", + ngettext ("%s: Read error at byte %s, while reading %lu byte", + "%s: Read error at byte %s, while reading %lu bytes", size), quotearg_colon (name), STRINGIFY_BIGINT (offset, buf), (unsigned long) size)); @@ -688,8 +713,8 @@ read_warn_details (char const *name, off_t offset, size_t size) char buf[UINTMAX_STRSIZE_BOUND]; int e = errno; WARN ((0, e, - ngettext ("%s: Warning: Read error at byte %s, reading %lu byte", - "%s: Warning: Read error at byte %s, reading %lu bytes", + ngettext ("%s: Warning: Read error at byte %s, while reading %lu byte", + "%s: Warning: Read error at byte %s, while reading %lu bytes", size), quotearg_colon (name), STRINGIFY_BIGINT (offset, buf), (unsigned long) size)); @@ -814,6 +839,12 @@ symlink_error (char const *contents, char const *name) quotearg_colon (name), quote_n (1, contents))); } +void +stat_fatal (char const *name) +{ + call_arg_fatal ("stat", name); +} + void stat_error (char const *name) {