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