xine-lib 1.2.12
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
 
struct  xine_fast_text_s
 

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)
 
#define XFST_ALIGN   (16)
 
#define XFST_MIN_SIZE   ((XFST_ALIGN + 2 + XFST_ALIGN - 1) & ~(XFST_ALIGN - 1))
 

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)
 
size_t xine_fast_string_need (size_t max_strlen)
 
char * xine_fast_string_init (char *buf, size_t bsize)
 
size_t xine_fast_string_max (char *fast_string)
 
char * xine_fast_string_set (char *fast_string, const char *text, size_t tsize)
 
int xine_fast_string_cmp (char *fast_string1, char *fast_string2)
 
void xine_fast_string_free (char **fast_string)
 
xine_fast_text_txine_fast_text_load (const char *filename, size_t max_size)
 
char * xine_fast_text_line (xine_fast_text_t *xft, size_t *linesize)
 
void xine_fast_text_unload (xine_fast_text_t **xft)
 

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,}
 
union {
   uint8_t   z [4]
 
   uint32_t   v
 
_xine_fast_string_mask [8]
 

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 */

◆ XFST_ALIGN

#define XFST_ALIGN   (16)

◆ XFST_MIN_SIZE

#define XFST_MIN_SIZE   ((XFST_ALIGN + 2 + XFST_ALIGN - 1) & ~(XFST_ALIGN - 1))

◆ 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, ss, and v.

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, and v.

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, tab_crc16_ansi, and v.

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, tab_crc32_ieee, and v.

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_fast_string_cmp()

int xine_fast_string_cmp ( char *  fast_string1,
char *  fast_string2 
)

fast strcmp (). BTW: XINE_PROTECTED does not link on some systems when doing xine_sarray_new (size, (xine_sarray_comparator_t)xine_fast_string_cmp);.

References _xine_fast_string_mask, and v.

Referenced by _config_fat_entry_cmp(), and _fat_node_file_cmp().

◆ xine_fast_string_free()

void xine_fast_string_free ( char **  fast_string)

free a fast string if it is not application supplied.

References NULL.

◆ xine_fast_string_init()

char * xine_fast_string_init ( char *  buf,
size_t  bsize 
)

set up a fast string inside an application supplied buffer.

References NULL, XFST_ALIGN, and XFST_MIN_SIZE.

Referenced by _config_fat_entry_cmp(), _x_scan_plugins(), config_insert(), and load_plugin_list().

◆ xine_fast_string_max()

size_t xine_fast_string_max ( char *  fast_string)

return the actual max strlen.

◆ xine_fast_string_need()

size_t xine_fast_string_need ( size_t  max_strlen)

return the byte size needed for an application supplied buffer.

References XFST_ALIGN.

◆ xine_fast_string_set()

char * xine_fast_string_set ( char *  fast_string,
const char *  text,
size_t  tsize 
)

set or change the contents of a fast string. fast_text may be NULL, to allocate a new one. you can even edit the string manually, then apply the new size with text == NULL.

References _xine_fast_string_mask, NULL, v, and XFST_ALIGN.

Referenced by _config_fat_entry_cmp(), collect_plugins(), config_insert(), and load_plugin_list().

◆ xine_fast_text_line()

char * xine_fast_text_line ( xine_fast_text_t xft,
size_t *  linesize 
)

get next line. you may modify return[0] ... return[filesize]. it all stays valid until xine_fast_text_unload ().

References xine_fast_text_s::dummy, xine_fast_text_s::flags, xine_fast_text_s::line_start, NULL, xine_fast_text_s::scan_here, xine_fast_text_s::text_len, and v.

Referenced by load_plugin_list(), and xine_config_load().

◆ xine_fast_text_load()

xine_fast_text_t * xine_fast_text_load ( const char *  filename,
size_t  max_size 
)

◆ xine_fast_text_unload()

void xine_fast_text_unload ( xine_fast_text_t **  xft)

free the text.

References NULL.

Referenced by load_plugin_list(), and xine_config_load().

◆ 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().

◆ xine_memdup0()

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

References NULL, and xine_fast_memcpy.

◆ 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(), and type.

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

◆ 

const union { ... } _xine_fast_string_mask[8]
Initial value:
= {
{{0xff, 0xff, 0xff, 0xff}},
{{0x00, 0xff, 0xff, 0xff}},
{{0x00, 0x00, 0xff, 0xff}},
{{0x00, 0x00, 0x00, 0xff}},
{{0x00, 0x00, 0x00, 0x00}},
{{0xff, 0x00, 0x00, 0x00}},
{{0xff, 0xff, 0x00, 0x00}},
{{0xff, 0xff, 0xff, 0x00}}
}

Referenced by xine_fast_string_cmp(), and xine_fast_string_set().

◆ 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().

◆ v

uint32_t v

Referenced by _get_hex(), _mad_fixed_2_db(), _mad_scale(), _vdec_hw_h264_unescape(), _x_clut_yuv2rgb(), _x_url_parse2(), _xine_str2secs(), _xine_stree_load_json(), _xine_stree_load_xml(), XineOpenGLView::acceptsFirstResponder, ao_esd_set_property(), ao_oss_get_property(), ao_oss_set_property(), asmrp_set_id(), audio_filter_equalize(), bebf_get(), bebf_skip(), bebf_sniff(), bebf_sync(), bits_read(), bits_set_buf(), bits_valid_left(), build_frame_table(), config_update_string_e(), convert_yv12(), create_lut(), demux_qt_load_fragment_index(), demux_ts_parse_pat(), demux_ts_parse_pes_header(), demux_ts_parse_pmt(), detect_ts(), downmix_lfe_2(), draw_ifs(), dvd_parse_mrl(), faad_decode_audio(), fade(), fade_out_yuv(), ff_aac_mode_parse(), ff_audio_decode(), ff_audio_decode_data(), find_embedded_atoms(), flac_get_frame(), flac_init_frame_head(), flac_parse_frame_head(), flac_test_frame_head(), float_to_int(), frametype_h264(), frametype_h265(), frametype_mpeg(), frametype_vc1(), hexstr2uint32(), hls_bump_find(), hscale_chroma_line(), iatan(), ifs_update(), init_plugin(), isqr(), lineNoise_C(), load_plugin_list(), mad_decode_data(), mpd_input_open(), mpd_str2time(), mpeg1_read_pts(), mpeg2_read_pts(), mpeg_get_pts(), opengl2_open_plugin(), pgx64_overlay_key_blend(), put32le(), recalculate_trans(), rgb2yuy2_palette(), rgb2yuy2_slice(), saturate(), scale_int_do(), sha160_final(), simplify(), str2uint32(), str2uint64(), str2usec(), tdaan_downmix16_4(), tdaan_levels_get(), test_make(), uint64_2str(), uint_sqrt(), unescape(), unixscr_adjust(), unixscr_get_current(), unixscr_init(), unixscr_set_pivot(), unixscr_set_speed(), unixscr_start(), vdec_hw_h264_put_frame(), vo_get_property(), vo_set_property(), vobsub_parse_palette(), w32v_decode_data(), x11osd_blend(), xcbosd_blend(), xine_base64_decode(), xine_base64_encode(), xine_crc16_ansi(), xine_crc32_ieee(), xine_fast_string_cmp(), xine_fast_string_set(), xine_fast_text_line(), xine_init(), xine_int32_2str(), xine_refs_add(), xine_refs_get(), xine_refs_sub(), xine_str2int32(), xine_str2uint32(), xine_str2uint64(), xine_stree_find(), xine_string_unampersand(), xine_string_unbackslash(), xine_string_unpercent(), xine_uint32_2str(), xine_uint64_2str(), xml_parser_get_property_bool(), xml_parser_get_property_int(), yuv2rgb_single_pixel_16(), yuv2rgb_single_pixel_24_bgr(), yuv2rgb_single_pixel_24_rgb(), yuv2rgb_single_pixel_32(), yuv2rgb_single_pixel_8(), yuv2rgb_single_pixel_gray(), yuv2rgb_single_pixel_palette(), and yuv444_to_yuy2_c().

◆ z

uint8_t z[4]