2006-08-15 20:37:04 +00:00
|
|
|
/* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */
|
2006-08-24 19:23:37 +00:00
|
|
|
/* vim: set noet ts=8 sts=8 sw=8 : */
|
2006-08-15 20:37:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility functions for the Libisofs library.
|
|
|
|
*/
|
|
|
|
|
2006-08-24 19:23:37 +00:00
|
|
|
#ifndef LIBISO_UTIL_H
|
|
|
|
#define LIBISO_UTIL_H
|
2006-08-15 20:37:04 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2006-08-24 19:23:37 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <wchar.h>
|
2006-08-15 20:37:04 +00:00
|
|
|
|
2006-08-24 19:23:37 +00:00
|
|
|
#ifndef MAX
|
|
|
|
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#endif
|
2006-08-15 20:37:04 +00:00
|
|
|
|
2006-08-24 19:23:37 +00:00
|
|
|
#ifndef MIN
|
|
|
|
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#endif
|
2006-08-15 20:37:04 +00:00
|
|
|
|
2006-08-24 19:23:37 +00:00
|
|
|
extern inline int div_up(int n, int div)
|
|
|
|
{
|
|
|
|
return (n + div - 1) / div;
|
|
|
|
}
|
2006-08-15 20:37:04 +00:00
|
|
|
|
2006-08-24 19:23:37 +00:00
|
|
|
extern inline int round_up(int n, int mul)
|
|
|
|
{
|
|
|
|
return div_up(n, mul) * mul;
|
|
|
|
}
|
2006-08-15 20:37:04 +00:00
|
|
|
|
2007-05-31 04:25:39 +00:00
|
|
|
char *convert_str(const char *str, const char *icharset, const char *ocharset);
|
|
|
|
|
2006-08-24 19:23:37 +00:00
|
|
|
wchar_t *towcs(const char *);
|
2007-05-31 04:25:39 +00:00
|
|
|
char *str2ascii(const char*, const char *);
|
|
|
|
uint16_t *str2ucs(const char *, const char *);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
2007-05-31 04:25:39 +00:00
|
|
|
char *str2d_char(const char*, const char *);
|
|
|
|
char *str2a_char(const char*, const char *);
|
2007-05-15 10:35:42 +00:00
|
|
|
|
2006-08-15 20:37:04 +00:00
|
|
|
/**
|
2006-08-24 19:23:37 +00:00
|
|
|
* Create a level 1 directory identifier.
|
2006-08-15 20:37:04 +00:00
|
|
|
*/
|
2007-05-31 04:25:39 +00:00
|
|
|
char *iso_1_dirid(const char *src, const char *);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
|
|
|
/**
|
2006-08-24 19:23:37 +00:00
|
|
|
* Create a level 2 directory identifier.
|
2006-08-15 20:37:04 +00:00
|
|
|
*/
|
2007-05-31 04:25:39 +00:00
|
|
|
char *iso_2_dirid(const char *src, const char *);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
2007-06-21 11:19:11 +00:00
|
|
|
/**
|
|
|
|
* Create a directory identifier with relaxed constraints
|
|
|
|
*/
|
|
|
|
char *iso_r_dirid(const char *src, const char *icharset, int flags);
|
|
|
|
|
2006-08-15 20:37:04 +00:00
|
|
|
/**
|
2006-08-24 19:23:37 +00:00
|
|
|
* Create a level 1 file identifier that consists of a name, extension and
|
|
|
|
* version number. The resulting string will have a file name of maximum
|
|
|
|
* length 8, followed by a separator (.), an optional extension of maximum
|
|
|
|
* length 3, followed by a separator (;) and a version number (digit 1).
|
2006-08-15 20:37:04 +00:00
|
|
|
* @return NULL if the original name and extension both are of length 0.
|
|
|
|
*/
|
2007-05-31 04:25:39 +00:00
|
|
|
char *iso_1_fileid(const char *src, const char *);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
|
|
|
/**
|
2006-08-24 19:23:37 +00:00
|
|
|
* Create a level 2 file identifier that consists of a name, extension and
|
|
|
|
* version number. The combined file name and extension length will not exceed
|
|
|
|
* 30, the name and extension will be separated (.), and the extension will be
|
|
|
|
* followed by a separator (;) and a version number (digit 1).
|
2006-08-15 20:37:04 +00:00
|
|
|
* @return NULL if the original name and extension both are of length 0.
|
|
|
|
*/
|
2007-05-31 04:25:39 +00:00
|
|
|
char *iso_2_fileid(const char *src, const char *);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
2007-06-21 11:19:11 +00:00
|
|
|
/**
|
|
|
|
* Create a file identifier with relaxed constraints.
|
|
|
|
*/
|
|
|
|
char *iso_r_fileid(const char *src, const char *icharset, int flags);
|
|
|
|
|
2006-08-15 20:37:04 +00:00
|
|
|
/**
|
2006-08-24 19:23:37 +00:00
|
|
|
* Create a Joliet file or directory identifier that consists of a name,
|
|
|
|
* extension and version number. The combined name and extension length will
|
|
|
|
* not exceed 128 bytes, the name and extension will be separated (.),
|
|
|
|
* and the extension will be followed by a separator (;) and a version number
|
|
|
|
* (digit 1). All characters consist of 2 bytes and the resulting string is
|
|
|
|
* NULL-terminated by a 2-byte NULL. Requires the locale to be set correctly.
|
|
|
|
*
|
2006-08-15 20:37:04 +00:00
|
|
|
* @param size will be set to the size (in bytes) of the identifier.
|
|
|
|
* @return NULL if the original name and extension both are of length 0 or the conversion from the current codeset to UCS-2BE is not available.
|
|
|
|
*/
|
2007-05-31 04:25:39 +00:00
|
|
|
uint16_t *iso_j_id(const char *src, const char *icharset);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
|
|
|
/**
|
2006-08-24 19:23:37 +00:00
|
|
|
* FIXME: what are the requirements for these next two? Is this for RR?
|
|
|
|
*
|
2006-08-15 20:37:04 +00:00
|
|
|
* Create a POSIX portable file name that consists of a name and extension.
|
|
|
|
* The resulting file name will not exceed 250 characters.
|
|
|
|
* @return NULL if the original name and extension both are of length 0.
|
|
|
|
*/
|
2007-05-31 04:25:39 +00:00
|
|
|
char *iso_p_fileid(const char *src, const char *);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a POSIX portable directory name.
|
|
|
|
* The resulting directory name will not exceed 250 characters.
|
|
|
|
* @return NULL if the original name is of length 0.
|
|
|
|
*/
|
2006-09-19 17:06:40 +00:00
|
|
|
char *iso_p_dirid(const char *src);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
|
|
|
void iso_lsb(uint8_t *buf, uint32_t num, int bytes);
|
|
|
|
void iso_msb(uint8_t *buf, uint32_t num, int bytes);
|
|
|
|
void iso_bb(uint8_t *buf, uint32_t num, int bytes);
|
|
|
|
|
|
|
|
uint32_t iso_read_lsb(const uint8_t *buf, int bytes);
|
|
|
|
uint32_t iso_read_msb(const uint8_t *buf, int bytes);
|
2007-08-10 09:35:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* if error != NULL it will be set to 1 if LSB and MSB integers
|
|
|
|
* don't match
|
|
|
|
*/
|
|
|
|
uint32_t iso_read_bb(const uint8_t *buf, int bytes, int *error);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
|
|
|
/** Records the date/time into a 7 byte buffer (9.1.5) */
|
2006-08-24 19:23:37 +00:00
|
|
|
void iso_datetime_7(uint8_t *buf, time_t t);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
|
|
|
/** Records the date/time into a 17 byte buffer (8.4.26.1) */
|
2006-08-24 19:23:37 +00:00
|
|
|
void iso_datetime_17(uint8_t *buf, time_t t);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
|
|
|
time_t iso_datetime_read_7(const uint8_t *buf);
|
|
|
|
time_t iso_datetime_read_17(const uint8_t *buf);
|
|
|
|
|
2006-08-24 19:23:37 +00:00
|
|
|
/**
|
|
|
|
* Like strlen, but for Joliet strings.
|
|
|
|
*/
|
|
|
|
size_t ucslen(const uint16_t *str);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
2006-08-24 19:23:37 +00:00
|
|
|
/**
|
|
|
|
* Like strcmp, but for Joliet strings.
|
|
|
|
*/
|
|
|
|
int ucscmp(const uint16_t *s1, const uint16_t *s2);
|
2006-08-15 20:37:04 +00:00
|
|
|
|
2007-08-10 09:35:10 +00:00
|
|
|
/**
|
|
|
|
* Copy up to \p len chars from \p buf and return this newly allocated
|
|
|
|
* string. The new string is null-terminated.
|
|
|
|
*/
|
|
|
|
char *strcopy(const char *buf, size_t len);
|
|
|
|
|
2007-08-27 22:51:48 +00:00
|
|
|
/**
|
|
|
|
* Convert a Joliet string with a length of \p len bytes to a new string
|
|
|
|
* in local charset.
|
|
|
|
*/
|
|
|
|
char *ucs2str(const char *buf, size_t len);
|
|
|
|
|
2006-08-24 19:23:37 +00:00
|
|
|
#endif /* LIBISO_UTIL_H */
|