Source

lrc / src / Utils.hxx

Full commit
//      Utils.hxx
//
//      Copyright 2011 Andreas Tscharner <andy@vis.ethz.ch>
//
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU Lesser General Public License as
//      published by the Free Software Foundation; either version 3 of the
//      License, or (at your option) any later version.
//
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//
//      You should have received a copy of the GNU Lesser General Public
//      License along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.


/*! \file Utils.hxx
 *
 * This file contains the declaration of a few utility functions that are
 * used in the whole project
 *
 * \author Andreas Tscharner
 * \date 2011-09-11
 */


 #ifndef __UTILS_HXX__
 #define __UTILS_HXX__


/*! \brief Macro for debugging
 *
 * This macro expands to a printf if the __DEBUG__ define is set or to
 * nothing otherwise
 */
 #ifdef __DEBUG__
 #define DEBUG_PRINT(x) printf x;
 #else
 #define DEBUG_PRINT(x)
 #endif


/*! \brief Check if a file exists
 *
 * This function checks if a given file exists and returns true if it does
 * and false otherwise
 *
 * \param[in] p_filename Full or relative path to file
 *
 * \retval true File exists
 * \retval false File does not exist
 */
bool file_exists(const char *);

/*! \brief Returns the size of a file
 *
 * This function returns the size of a file
 *
 * \param[in] p_filename Filename
 *
 * \return Size of file
 *
 * \remarks If an error occurres, the function returns -1
 */
int file_size(const char *);

/*! \brief Returns the file extension
 *
 * This function returns the file extension of the given file
 *
 * \param[in] p_filename Filename
 *
 * \return File extension (if any)
 *
 * \remarks The returned string is a pointer to the file extension within
 * the given string! It is NULL, if the given filename has no extension.
 */
char *get_extension(char *);

/*! \brief Replace the file extension
 *
 * This function replaces the extension of the given file with the given new
 * extension. The extention is expected to have a dot ('.') as first
 * character. If the given filename has no extension, the new extension is
 * appended.
 *
 * \param[in] p_filename Filename
 * \param[in] p_newExt New file extension
 *
 * \return Filename with new extension
 *
 * \remarks The caller is responsible to free the allocated memory of the
 * returned string
 */
char *replace_extension(char *, char *);

/*! \brief Delete list of data
 *
 * This function deletes a list of data (double pointers to unsigned chars)
 *
 * \param[in] p_dataList List of data to delete
 * \param[in] p_listSize Size of data list
 */
void delete_list(unsigned char **, unsigned int);

/*! \brief Gets length of a password
 *
 * This function is used to get the length of a zero-terminated password.
 * It counts all \em unsigned characters until the first zero
 *
 * \param[in] p_password Zero-terminated password
 *
 * \return Length of zero-terminated password
 *
 * \remarks -1 will be returned if the given password was \c nullptr
 */
int password_len(const unsigned char *);


#endif /* __UTILS_HXX__ */