util.h

Go to the documentation of this file.
00001 /*
00002     $Id: util_8h-source.html,v 1.19 2006/10/27 11:16:42 rocky Exp $
00003 
00004     Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
00005     Copyright (C) 2004, 2005, 2006 Rocky Bernstein <rocky@panix.com>
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 2 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, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 /* round up to next block boundary */
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 size_t
00095 _cdio_strlenv(char **str_array);
00096 
00097 char **
00098 _cdio_strsplit(const char str[], char delim);
00099 
00100 uint8_t cdio_to_bcd8(uint8_t n);
00101 uint8_t cdio_from_bcd8(uint8_t p);
00102 
00103 #ifdef __cplusplus
00104 }
00105 #endif
00106 
00107 #endif /* __CDIO_UTIL_H__ */
00108 
00109 
00110 /* 
00111  * Local variables:
00112  *  c-file-style: "gnu"
00113  *  tab-width: 8
00114  *  indent-tabs-mode: nil
00115  * End:
00116  */

Generated on Fri Oct 27 06:38:08 2006 for libcdio by  doxygen 1.4.6