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 char *
00095 _cdio_strjoin (char *strv[], unsigned count, const char delim[]);
00096
00097 size_t
00098 _cdio_strlenv(char **str_array);
00099
00100 char **
00101 _cdio_strsplit(const char str[], char delim);
00102
00103 uint8_t cdio_to_bcd8(uint8_t n);
00104 uint8_t cdio_from_bcd8(uint8_t p);
00105
00106 #if defined(__GNUC__) && __GNUC__ >= 3
00107 static inline __attribute__((deprecated))
00108 uint8_t to_bcd8(uint8_t n) {
00109 return cdio_to_bcd8(n);
00110 }
00111 static inline __attribute__((deprecated))
00112 uint8_t from_bcd8(uint8_t p) {
00113 return cdio_from_bcd8(p);
00114 }
00115 #else
00116 #define to_bcd8 cdio_to_bcd8
00117 #define from_bcd8 cdio_from_bcd8
00118 #endif
00119
00120 #ifdef __cplusplus
00121 }
00122 #endif
00123
00124 #endif
00125
00126
00127
00128
00129
00130
00131
00132
00133