From: Paul Eggert Date: Tue, 3 Aug 2004 04:45:05 +0000 (+0000) Subject: (quote_n, quote): Remove these redundant functions. X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=f3da0c26b8fdfdd5db39e5fde8757ded273c2b51;p=chaz%2Ftar (quote_n, quote): Remove these redundant functions. (ptr_align): New function, from coreutils/src/system.h. (page_aligned_alloc): New function. --- diff --git a/src/misc.c b/src/misc.c index bae6cfc..73cb2c3 100644 --- a/src/misc.c +++ b/src/misc.c @@ -916,18 +916,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); }