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