/build/buildd/xz-utils-4.999.9beta+20091116/src/xz/util.c File Reference

Miscellaneous utility functions. More...

#include "private.h"

Functions

void * xrealloc (void *ptr, size_t size)
 Safe realloc() that never returns NULL.
char * xstrdup (const char *src)
 Safe strdup() that never returns NULL.
uint64_t str_to_uint64 (const char *name, const char *value, uint64_t min, uint64_t max)
 Fancy version of strtoull().
const char * uint64_to_str (uint64_t value, uint32_t slot)
 Convert uint64_t to a string.
const char * double_to_str (double value)
 Convert double to a string with one decimal place.
bool is_empty_filename (const char *filename)
 Check if filename is empty and print an error message.
bool is_tty_stdin (void)
 Test if stdin is a terminal.
bool is_tty_stdout (void)
 Test if stdout is a terminal.

Detailed Description

Miscellaneous utility functions.


Function Documentation

void* xrealloc ( void *  ptr,
size_t  size 
)

Safe realloc() that never returns NULL.

References message_fatal().

char* xstrdup ( const char *  src  ) 

Safe strdup() that never returns NULL.

References xmalloc.

Referenced by parse_options(), and suffix_set().

uint64_t str_to_uint64 ( const char *  name,
const char *  value,
uint64_t  min,
uint64_t  max 
)

Fancy version of strtoull().

Parameters:
name Name of the option to show in case of an error
value String containing the number to be parsed; may contain suffixes "k", "M", "G", "Ki", "Mi", or "Gi"
min Minimum valid value
max Maximum valid value
Returns:
Parsed value that is in the range [min, max]. Does not return if an error occurs.

References message(), message_fatal(), and V_ERROR.

Referenced by parse_options().

const char* uint64_to_str ( uint64_t  value,
uint32_t  slot 
)

Convert uint64_t to a string.

Convert the given value to a string with locale-specific thousand separators, if supported by the snprintf() implementation. The string is stored into an internal static buffer indicated by the slot argument. A pointer to the selected buffer is returned.

This function exists, because non-POSIX systems don't support thousand separator in format strings. Solving the problem in a simple way doesn't work, because it breaks gettext (specifically, the xgettext tool).

Referenced by coder_normal(), message_help(), and message_memlimit().

const char* double_to_str ( double  value  ) 

Convert double to a string with one decimal place.

This is like uint64_to_str() except that this converts a double and uses exactly one decimal place.

bool is_empty_filename ( const char *  filename  ) 

Check if filename is empty and print an error message.

References message_error().

Referenced by io_open().

bool is_tty_stdin ( void   ) 

Test if stdin is a terminal.

If stdin is a terminal, an error message is printed and exit status set to EXIT_ERROR.

References message_error().

bool is_tty_stdout ( void   ) 

Test if stdout is a terminal.

If stdout is a terminal, an error message is printed and exit status set to EXIT_ERROR.

References message_error().


Generated on Mon Dec 21 22:54:41 2009 for XZ Utils by  doxygen 1.6.1