X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fmisc.c;h=bead6800c9113a2062bd3233f053b1b3c0d777b1;hb=2433f6813ec6a0c00e6c49b8f38725cd4a78c66c;hp=bae6cfc1ef0a092d83133d763d35512086048ef8;hpb=463d99453f51ac4ae875d9bae97418671e7a62bc;p=chaz%2Ftar diff --git a/src/misc.c b/src/misc.c index bae6cfc..bead680 100644 --- a/src/misc.c +++ b/src/misc.c @@ -17,8 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "system.h" -#include "rmt.h" +#include +#include #include "common.h" #include #include @@ -123,13 +123,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 +138,8 @@ unquote_string (char *string) source++; break; - case 'b': - *destination++ = '\b'; + case 'n': + *destination++ = '\n'; source++; break; @@ -148,6 +148,16 @@ unquote_string (char *string) source++; break; + case 't': + *destination++ = '\t'; + source++; + break; + + case 'v': + *destination++ = '\v'; + source++; + break; + case '?': *destination++ = 0177; source++; @@ -207,7 +217,7 @@ 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])) { @@ -307,7 +317,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); @@ -916,18 +927,29 @@ xpipe (int fd[2]) call_arg_fatal ("pipe", _("interprocess channel")); } -/* Return an unambiguous printable representation, allocated in slot N, - for NAME, suitable for diagnostics. */ -char const * -quote_n (int n, char const *name) +/* Return PTR, aligned upward to the next multiple of ALIGNMENT. + ALIGNMENT must be nonzero. The caller must arrange for ((char *) + PTR) through ((char *) PTR + ALIGNMENT - 1) to be addressable + locations. */ + +static inline void * +ptr_align (void *ptr, size_t alignment) { - return quotearg_n_style (n, locale_quoting_style, name); + char *p0 = ptr; + char *p1 = p0 + alignment - 1; + return p1 - (size_t) p1 % alignment; } -/* Return an unambiguous printable representation of NAME, suitable - for diagnostics. */ -char const * -quote (char const *name) +/* Return the address of a page-aligned buffer of at least SIZE bytes. + The caller should free *PTR when done with the buffer. */ + +void * +page_aligned_alloc (void **ptr, size_t size) { - return quote_n (0, name); + size_t alignment = getpagesize (); + size_t size1 = size + alignment; + if (size1 < size) + xalloc_die (); + *ptr = xmalloc (size1); + return ptr_align (*ptr, alignment); }