1 /*
2 $Id$
3
4 Copyright (C) 2000, 2005 Herbert Valerio Riedel <hvr@gnu.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef __VCD_UTIL_H__
22 #define __VCD_UTIL_H__
23
24 #include <stdlib.h>
25 #include <libvcd/types.h>
26
27 static inline unsigned
_vcd_len2blocks(unsigned len,int blocksize)28 _vcd_len2blocks (unsigned len, int blocksize)
29 {
30 unsigned blocks;
31
32 blocks = len / blocksize;
33 if (len % blocksize)
34 blocks++;
35
36 return blocks;
37 }
38
39 /* round up to next block boundary */
40 static inline unsigned
_vcd_ceil2block(unsigned offset,int blocksize)41 _vcd_ceil2block (unsigned offset, int blocksize)
42 {
43 return _vcd_len2blocks (offset, blocksize) * blocksize;
44 }
45
46 static inline unsigned
_vcd_ofs_add(unsigned offset,unsigned length,int blocksize)47 _vcd_ofs_add (unsigned offset, unsigned length, int blocksize)
48 {
49 if (blocksize - (offset % blocksize) < length)
50 offset = _vcd_ceil2block (offset, blocksize);
51
52 offset += length;
53
54 return offset;
55 }
56
57 size_t
58 _vcd_strlenv(char **str_array);
59
60 char *
61 _vcd_strjoin (char *strv[], unsigned count, const char delim[]);
62
63 char **
64 _vcd_strsplit(const char str[], char delim);
65
66 void
67 _vcd_strfreev(char **strv);
68
69 void *
70 _vcd_memdup (const void *mem, size_t count);
71
72 char *
73 _vcd_strdup_upper (const char str[]);
74
75 static inline const char *
_vcd_bool_str(bool b)76 _vcd_bool_str (bool b)
77 {
78 return b ? "yes" : "no";
79 }
80
81 #endif /* __VCD_UTIL_H__ */
82
83
84 /*
85 * Local variables:
86 * c-file-style: "gnu"
87 * tab-width: 8
88 * indent-tabs-mode: nil
89 * End:
90 */
91