00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __CDIO_UTIL_H__
00023 #define __CDIO_UTIL_H__
00024
00031 #include <stdlib.h>
00032
00033 #undef MAX
00034 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
00035
00036 #undef MIN
00037 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
00038
00039 #undef IN
00040 #define IN(x, low, high) ((x) >= (low) && (x) <= (high))
00041
00042 #undef CLAMP
00043 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
00044
00045 static inline uint32_t
00046 _cdio_len2blocks (uint32_t i_len, uint16_t i_blocksize)
00047 {
00048 uint32_t i_blocks;
00049
00050 i_blocks = i_len / (uint32_t) i_blocksize;
00051 if (i_len % i_blocksize)
00052 i_blocks++;
00053
00054 return i_blocks;
00055 }
00056
00057
00058 static inline unsigned
00059 _cdio_ceil2block (unsigned offset, uint16_t i_blocksize)
00060 {
00061 return _cdio_len2blocks (offset, i_blocksize) * i_blocksize;
00062 }
00063
00064 static inline unsigned int
00065 _cdio_ofs_add (unsigned offset, unsigned length, uint16_t i_blocksize)
00066 {
00067 if (i_blocksize - (offset % i_blocksize) < length)
00068 offset = _cdio_ceil2block (offset, i_blocksize);
00069
00070 offset += length;
00071
00072 return offset;
00073 }
00074
00075 static inline const char *
00076 _cdio_bool_str (bool b)
00077 {
00078 return b ? "yes" : "no";
00079 }
00080
00081 #ifdef __cplusplus
00082 extern "C" {
00083 #endif
00084
00085 void *
00086 _cdio_memdup (const void *mem, size_t count);
00087
00088 char *
00089 _cdio_strdup_upper (const char str[]);
00090
00091 void
00092 _cdio_strfreev(char **strv);
00093
00094 size_t
00095 _cdio_strlenv(char **str_array);
00096
00097 char **
00098 _cdio_strsplit(const char str[], char delim);
00099
00100 uint8_t cdio_to_bcd8(uint8_t n);
00101 uint8_t cdio_from_bcd8(uint8_t p);
00102
00103 #ifdef __cplusplus
00104 }
00105 #endif
00106
00107 #endif
00108
00109
00110
00111
00112
00113
00114
00115
00116