2007-12-13 20:02:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Vreixo Formoso
|
|
|
|
*
|
|
|
|
* This file is part of the libisofs project; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation. See COPYING file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LIBISO_UTIL_H_
|
|
|
|
#define LIBISO_UTIL_H_
|
|
|
|
|
2007-12-18 20:51:33 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#ifndef MAX
|
|
|
|
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
2007-12-13 20:02:36 +00:00
|
|
|
extern inline int div_up(int n, int div);
|
|
|
|
|
|
|
|
extern inline int round_up(int n, int mul);
|
|
|
|
|
2007-12-16 16:32:05 +00:00
|
|
|
int int_pow(int base, int power);
|
|
|
|
|
2007-12-14 21:13:00 +00:00
|
|
|
/**
|
|
|
|
* Convert a given string from any input charset to ASCII
|
|
|
|
*
|
|
|
|
* @param icharset
|
|
|
|
* Input charset. Must be supported by iconv
|
|
|
|
* @param input
|
|
|
|
* Input string
|
|
|
|
* @param ouput
|
|
|
|
* Location where the pointer to the ouput string will be stored
|
|
|
|
* @return
|
|
|
|
* 1 on success, < 0 on error
|
|
|
|
*/
|
2007-12-14 20:42:55 +00:00
|
|
|
int str2ascii(const char *icharset, const char *input, char **output);
|
2007-12-13 20:02:36 +00:00
|
|
|
|
2007-12-14 21:13:00 +00:00
|
|
|
/**
|
|
|
|
* Ensure a given string is a valid ISO directory identifier, modifying
|
|
|
|
* it if needed.
|
|
|
|
*
|
|
|
|
* @param src
|
|
|
|
* The identifier, in ASCII encoding. It may be modified by the function.
|
|
|
|
* @param maxlen
|
|
|
|
* Maximum length supported by current iso level.
|
|
|
|
*/
|
|
|
|
void iso_dirid(char *src, int maxlen);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure a given string is a valid ISO level 1 file identifier, in 8.3
|
|
|
|
* format, modifying it if needed.
|
|
|
|
* Note that version number is not added to the file name
|
|
|
|
*
|
|
|
|
* @param src
|
|
|
|
* The identifier, in ASCII encoding. It may be modified by the function.
|
|
|
|
*/
|
|
|
|
void iso_1_fileid(char *src);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure a given string is a valid ISO level 2 file identifier, modifying it
|
|
|
|
* if needed.
|
|
|
|
* Note that version number is not added to the file name
|
|
|
|
*
|
|
|
|
* @param src
|
|
|
|
* The identifier, in ASCII encoding. It may be modified by the function.
|
|
|
|
*/
|
|
|
|
void iso_2_fileid(char *src);
|
|
|
|
|
2007-12-18 20:51:33 +00:00
|
|
|
/**
|
|
|
|
* Convert a given input string to d-chars.
|
|
|
|
* @return
|
|
|
|
* 1 on succes, < 0 error, 0 if input was null (output is set to null)
|
|
|
|
*/
|
|
|
|
int str2d_char(const char *icharset, const char *input, char **output);
|
|
|
|
int str2a_char(const char *icharset, const char *input, char **output);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/** Records the date/time into a 7 byte buffer (ECMA-119, 9.1.5) */
|
|
|
|
void iso_datetime_7(uint8_t *buf, time_t t);
|
|
|
|
|
|
|
|
/** Records the date/time into a 17 byte buffer (ECMA-119, 8.4.26.1) */
|
|
|
|
void iso_datetime_17(uint8_t *buf, time_t t);
|
|
|
|
|
2007-12-13 20:02:36 +00:00
|
|
|
#endif /*LIBISO_UTIL_H_*/
|