libcdio 0.83
|
00001 /* 00002 Copyright (C) 2004, 2005, 2006, 2008, 2010 Rocky Bernstein <rocky@gnu.org> 00003 Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org> 00004 00005 This program is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. 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 /* round up to next block boundary */ 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 /* __CDIO_UTIL_H__ */ 00114 00115 00116 /* 00117 * Local variables: 00118 * c-file-style: "gnu" 00119 * tab-width: 8 00120 * indent-tabs-mode: nil 00121 * End: 00122 */