libcdio  0.83
util.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004, 2005, 2006, 2008, 2010 Rocky Bernstein <rocky@gnu.org>
3  Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef __CDIO_UTIL_H__
20 #define __CDIO_UTIL_H__
21 
28 #include <stdlib.h>
29 #include <cdio/types.h>
30 
31 #undef MAX
32 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
33 
34 #undef MIN
35 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
36 
37 #undef IN
38 #define IN(x, low, high) ((x) >= (low) && (x) <= (high))
39 
40 #undef CLAMP
41 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
42 
43 static inline uint32_t
44 _cdio_len2blocks (uint32_t i_len, uint16_t i_blocksize)
45 {
46  uint32_t i_blocks;
47 
48  i_blocks = i_len / (uint32_t) i_blocksize;
49  if (i_len % i_blocksize)
50  i_blocks++;
51 
52  return i_blocks;
53 }
54 
55 /* round up to next block boundary */
56 static inline unsigned
57 _cdio_ceil2block (unsigned offset, uint16_t i_blocksize)
58 {
59  return _cdio_len2blocks (offset, i_blocksize) * i_blocksize;
60 }
61 
62 static inline unsigned int
63 _cdio_ofs_add (unsigned offset, unsigned length, uint16_t i_blocksize)
64 {
65  if (i_blocksize - (offset % i_blocksize) < length)
66  offset = _cdio_ceil2block (offset, i_blocksize);
67 
68  offset += length;
69 
70  return offset;
71 }
72 
73 static inline const char *
74 _cdio_bool_str (bool b)
75 {
76  return b ? "yes" : "no";
77 }
78 
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 
83 void *
84 _cdio_memdup (const void *mem, size_t count);
85 
86 char *
87 _cdio_strdup_upper (const char str[]);
88 
89 void
90 _cdio_strfreev(char **strv);
91 
92 size_t
93 _cdio_strlenv(char **str_array);
94 
95 char **
96 _cdio_strsplit(const char str[], char delim);
97 
98 uint8_t cdio_to_bcd8(uint8_t n);
99 uint8_t cdio_from_bcd8(uint8_t p);
100 
103 char *cdio_realpath (const char *psz_src, char *psz_dst);
104 
105 #ifdef WANT_FOLLOW_SYMLINK_COMPATIBILITY
106 # define cdio_follow_symlink cdio_realpath
107 #endif
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* __CDIO_UTIL_H__ */
114 
115 
116 /*
117  * Local variables:
118  * c-file-style: "gnu"
119  * tab-width: 8
120  * indent-tabs-mode: nil
121  * End:
122  */

Generated for libcdio by doxygen 1.8.1.1