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