# lrc / src / Utils.hxx

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 // Utils.hxx // // Copyright 2011 Andreas Tscharner // // 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__ */