core/metamod_util.h
author Nicholas Hastings <skamonkey@gmail.com>
Wed May 21 00:09:33 2014 -0400 (2014-05-21)
changeset 916 f280cbd99586
parent 658 8353605c1d97
permissions -rw-r--r--
Update for hl2sdk-l4d changes.
     1 /**
     2  * vim: set ts=4 :
     3  * ======================================================
     4  * Metamod:Source
     5  * Copyright (C) 2004-2008 AlliedModders LLC and authors.
     6  * All rights reserved.
     7  * ======================================================
     8  *
     9  * This software is provided 'as-is', without any express or implied warranty.
    10  * In no event will the authors be held liable for any damages arising from 
    11  * the use of this software.
    12  * 
    13  * Permission is granted to anyone to use this software for any purpose, 
    14  * including commercial applications, and to alter it and redistribute it 
    15  * freely, subject to the following restrictions:
    16  *
    17  * 1. The origin of this software must not be misrepresented; you must not 
    18  * claim that you wrote the original software. If you use this software in a 
    19  * product, an acknowledgment in the product documentation would be 
    20  * appreciated but is not required.
    21  * 2. Altered source versions must be plainly marked as such, and must not be
    22  * misrepresented as being the original software.
    23  * 3. This notice may not be removed or altered from any source distribution.
    24  *
    25  * Version: $Id$
    26  */
    27 
    28 #ifndef _INCLUDE_UTIL_H
    29 #define _INCLUDE_UTIL_H
    30 
    31 #include <stdarg.h>
    32 
    33 /**
    34  * @brief Utility functions
    35  * @file util.h
    36  */
    37 
    38 /**
    39  * @brief Returns true is string is not blank, false otherwise.
    40  */
    41 #define IS_STR_FILLED(var) (var != NULL && var[0] != '\0')
    42 
    43 /**
    44  * @brief Returns a pointer to the extension in a file name.
    45  */
    46 const char *UTIL_GetExtension(const char *file);
    47 
    48 /**
    49  * @brief Removes whitespace characters from left side of string.
    50  */
    51 void UTIL_TrimLeft(char *buffer);
    52 
    53 /**
    54  * @brief Removes whitespace characters from right side of string.
    55  */
    56 void UTIL_TrimRight(char *buffer);
    57 
    58 /**
    59  * @brief Compares two file paths.
    60  */
    61 bool UTIL_PathCmp(const char *path1, const char *path2);
    62 
    63 /**
    64  * @brief Same as snprintf except that it ensures the string buffer is null terminated.
    65  */
    66 size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
    67 
    68 /**
    69  * @brief Same as vsnprintf except that it ensures the string buffer is null terminated.
    70  */
    71 size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list params);
    72 
    73 /**
    74  * @brief Forms a relative path given two absolute paths.
    75  *
    76  * @param buffer		Buffer to store relative path in.
    77  * @param maxlength		Maximum length of the output buffer.
    78  * @param relTo			Destination folder to use as a working directory.
    79  *						Final folder name should not be pathchar-terminated.
    80  * @param relFrom		Source file or folder to use as a target.
    81  * @return				True on success, false on failure.
    82  */
    83 bool UTIL_Relatize(char buffer[],
    84 				   size_t maxlength,
    85 				   const char *relTo,
    86 				   const char *relFrom);
    87 
    88 /**
    89  * @brief Compares memory address against a signature.
    90  *
    91  * @param addr			Memory address to check.
    92  * @param sig			Signature used to check against memory address. Accept 0x2A as wildcard.
    93  * @param len			Length of signature.
    94  * @return				True if signature was verified, false otherwise.
    95  */
    96 bool UTIL_VerifySignature(const void *addr, const char *sig, size_t len);
    97 
    98 #endif //_INCLUDE_UTIL_H
    99