xine-lib 1.2.11
Data Structures | Macros | Functions | Variables
utils.c File Reference
#include <xine/xineutils.h>
#include <xine/xineintl.h>
#include "xine_private.h"
#include "../xine-engine/bswap.h"
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>

Data Structures

struct  lang_locale_t
 

Macros

#define _POSIX_PTHREAD_SEMANTICS   1 /* for 5-arg getpwuid_r on solaris */
 
#define O_CLOEXEC   0
 
#define BUFSIZ   256
 
#define XINE_MEM_ALIGN   32
 
#define XINE_MEM_ADD   (sizeof (size_t) + XINE_MEM_ALIGN)
 
#define XINE_MEM_MASK   ((uintptr_t)XINE_MEM_ALIGN - 1)
 
#define rr   128 /* repeat */
 
#define ss   64 /* stop */
 
#define rev32(n)   (((n) << 24) | (((n) << 8) & 0xff0000) | (((n) >> 8) & 0xff00) | ((n) >> 24))
 
#define rev16(n)   ((((n) << 8) | ((n) >> 8)) & 0xffff)
 

Functions

void * xine_xmalloc (size_t size)
 Allocate and clean memory size_t 'size', then return the pointer to the allocated memory. More...
 
void * xine_xcalloc (size_t nmemb, size_t size)
 Wrapper around calloc() function. More...
 
void * xine_memdup (const void *src, size_t length)
 
void * xine_memdup0 (const void *src, size_t length)
 
const char * xine_get_homedir (void)
 
char * xine_chomp (char *str)
 
void xine_usec_sleep (unsigned usec)
 
void xine_hexdump (const void *buf_gen, int length)
 
static const lang_locale_t_get_first_lang_locale (const char *lcal)
 
static char * _get_lang (void)
 
char * xine_get_system_encoding (void)
 
const char * xine_guess_spu_encoding (void)
 
int xine_monotonic_clock (struct timeval *tv, struct timezone *tz)
 
char * xine_strcat_realloc (char **dest, const char *append)
 
char * _x_asprintf (const char *format,...)
 
int _x_set_file_close_on_exec (int fd)
 Make file descriptors and sockets uninheritable. More...
 
int _x_set_socket_close_on_exec (int s)
 
int xine_open_cloexec (const char *name, int flags)
 
int xine_create_cloexec (const char *name, int flags, mode_t mode)
 
int xine_socket_cloexec (int domain, int type, int protocol)
 
void * xine_mallocz_aligned (size_t size)
 
void * xine_malloc_aligned (size_t size)
 
void xine_free_aligned (void *ptr)
 
void * xine_realloc_aligned (void *ptr, size_t size)
 
size_t xine_base64_encode (uint8_t *from, char *to, size_t size)
 
size_t xine_base64_decode (const char *from, uint8_t *to)
 
uint32_t xine_crc32_ieee (uint32_t crc, const uint8_t *data, size_t len)
 
uint32_t xine_crc16_ansi (uint32_t crc, const uint8_t *data, size_t len)
 

Variables

static const lang_locale_t lang_locales []
 
static uint32_t tab_crc32_ieee [1280] = {0, 0,}
 
static uint16_t tab_crc16_ansi [768] = {0, 0,}
 

Macro Definition Documentation

◆ _POSIX_PTHREAD_SEMANTICS

#define _POSIX_PTHREAD_SEMANTICS   1 /* for 5-arg getpwuid_r on solaris */

◆ BUFSIZ

#define BUFSIZ   256

◆ O_CLOEXEC

#define O_CLOEXEC   0

◆ rev16

#define rev16 (   n)    ((((n) << 8) | ((n) >> 8)) & 0xffff)

◆ rev32

#define rev32 (   n)    (((n) << 24) | (((n) << 8) & 0xff0000) | (((n) >> 8) & 0xff00) | ((n) >> 24))

◆ rr

#define rr   128 /* repeat */

◆ ss

#define ss   64 /* stop */

◆ XINE_MEM_ADD

#define XINE_MEM_ADD   (sizeof (size_t) + XINE_MEM_ALIGN)

◆ XINE_MEM_ALIGN

#define XINE_MEM_ALIGN   32

◆ XINE_MEM_MASK

#define XINE_MEM_MASK   ((uintptr_t)XINE_MEM_ALIGN - 1)

Function Documentation

◆ _get_first_lang_locale()

static const lang_locale_t * _get_first_lang_locale ( const char *  lcal)
static

◆ _get_lang()

static char * _get_lang ( void  )
static

◆ _x_asprintf()

char * _x_asprintf ( const char *  format,
  ... 
)

◆ _x_set_file_close_on_exec()

int _x_set_file_close_on_exec ( int  fd)

Make file descriptors and sockets uninheritable.

Referenced by xine_create_cloexec(), and xine_open_cloexec().

◆ _x_set_socket_close_on_exec()

int _x_set_socket_close_on_exec ( int  s)

◆ xine_base64_decode()

size_t xine_base64_decode ( const char *  from,
uint8_t *  to 
)

Base64 decoder. from: pointer to input string or line formatted / indented, null terminated text. to: pointer to output buffer. ret: length of output in bytes.

References rr, and ss.

Referenced by config_register_serialized_entry(), sdpplin_parse(), and sdpplin_parse_stream().

◆ xine_base64_encode()

size_t xine_base64_encode ( uint8_t *  from,
char *  to,
size_t  size 
)

Base64 encoder. from: pointer to binary input. to: pointer to output string buffer. size: byte length of input. ret: length of output string (without \0). Note that both buffers need 4 writable padding bytes.

References _X_BE_24.

Referenced by _cdda_cdindex(), config_get_serialized_entry(), http_plugin_basicauth(), and rtsp_basicauth().

◆ xine_chomp()

char * xine_chomp ( char *  str)

◆ xine_crc16_ansi()

uint32_t xine_crc16_ansi ( uint32_t  crc,
const uint8_t *  data,
size_t  len 
)

References rev16, and tab_crc16_ansi.

Referenced by xine_a52_parse_data().

◆ xine_crc32_ieee()

uint32_t xine_crc32_ieee ( uint32_t  crc,
const uint8_t *  data,
size_t  len 
)

Checksum calculator.

References rev32, and tab_crc32_ieee.

Referenced by demux_ts_parse_pat(), demux_ts_parse_pmt(), and ts_rewrite_packets().

◆ xine_create_cloexec()

int xine_create_cloexec ( const char *  name,
int  flags,
mode_t  mode 
)

creates a file, ensuring that the descriptor will be closed automatically after a fork/execute.

References _x_set_file_close_on_exec(), mode(), name, and O_CLOEXEC.

Referenced by ao_file_open(), do_record(), open_plugin(), and pvr_break_rec_page().

◆ xine_free_aligned()

void xine_free_aligned ( void *  ptr)

◆ xine_get_homedir()

const char * xine_get_homedir ( void  )

◆ xine_get_system_encoding()

char * xine_get_system_encoding ( void  )

get encoding of current locale

References _get_first_lang_locale(), _get_lang(), lang_locale_t::encoding, and NULL.

Referenced by _meta_info_set_encoding(), and osd_set_encoding().

◆ xine_guess_spu_encoding()

const char * xine_guess_spu_encoding ( void  )

◆ xine_hexdump()

void xine_hexdump ( const void *  buf_gen,
int  length 
)

◆ xine_malloc_aligned()

void * xine_malloc_aligned ( size_t  size)

◆ xine_mallocz_aligned()

void * xine_mallocz_aligned ( size_t  size)

◆ xine_memdup()

void * xine_memdup ( const void *  src,
size_t  length 
)

References NULL, and xine_fast_memcpy.

Referenced by rmff_new_mdpr(), and rmff_scan_mdpr().

◆ xine_memdup0()

void * xine_memdup0 ( const void *  src,
size_t  length 
)

References NULL, and xine_fast_memcpy.

Referenced by rmff_scan_cont(), and rmff_scan_mdpr().

◆ xine_monotonic_clock()

int xine_monotonic_clock ( struct timeval *  tv,
struct timezone *  tz 
)

◆ xine_open_cloexec()

int xine_open_cloexec ( const char *  name,
int  flags 
)

◆ xine_realloc_aligned()

void * xine_realloc_aligned ( void *  ptr,
size_t  size 
)

◆ xine_socket_cloexec()

int xine_socket_cloexec ( int  domain,
int  type,
int  protocol 
)

creates a socket, ensuring that the descriptor will be closed automatically after a fork/execute.

References _x_set_socket_close_on_exec().

Referenced by _x_init_broadcaster(), _x_io_tcp_handshake_connect(), host_connect_attempt(), and vdr_plugin_open_socket().

◆ xine_strcat_realloc()

char * xine_strcat_realloc ( char **  dest,
const char *  append 
)

append to a string, reallocating normally, updates & returns *dest on error, *dest is unchanged & NULL is returned.

◆ xine_usec_sleep()

void xine_usec_sleep ( unsigned  usec)

◆ xine_xcalloc()

void * xine_xcalloc ( size_t  nmemb,
size_t  size 
)

Wrapper around calloc() function.

Parameters
nmembNumber of elements to allocate
sizeSize of each element to allocate

This is a simple wrapper around calloc(), the only thing it does more than calloc() is outputting an error if the calloc fails (returning NULL).

References __XINE_FUNCTION__, and NULL.

Referenced by open_film_file(), open_mve_file(), open_tta_file(), and parse_vbri_header().

◆ xine_xmalloc()

void * xine_xmalloc ( size_t  size)

Allocate and clean memory size_t 'size', then return the pointer to the allocated memory.

Parameters
sizeSize of the memory area to allocate.
Returns
A pointer to the allocated memory area, or NULL in case of error.

The behaviour of this function differs from standard malloc() as xine_xmalloc(0) will not return a NULL pointer, but rather a pointer to a memory area of size 1 byte.

The NULL value is only ever returned in case of an error in malloc(), and is reported to stderr stream.

Deprecated:
This function has been deprecated, as the behaviour of allocating a 1 byte memory area on zero size is almost never desired, and the function is thus mostly misused.

References __XINE_FUNCTION__, and NULL.

Referenced by fooviz_init_plugin().

Variable Documentation

◆ lang_locales

const lang_locale_t lang_locales[]
static

Referenced by _get_first_lang_locale().

◆ tab_crc16_ansi

uint16_t tab_crc16_ansi[768] = {0, 0,}
static

Referenced by xine_crc16_ansi().

◆ tab_crc32_ieee

uint32_t tab_crc32_ieee[1280] = {0, 0,}
static

Referenced by xine_crc32_ieee().