/** * @file fmt/str.c String format functions * * Copyright (C) 2010 Creytiv.com */ #undef __STRICT_ANSI__ /* for mingw32 */ #include #ifdef HAVE_STRINGS_H #include #endif #include #include #include /** * Convert a ascii hex string to binary format * * @param hex Destinatin binary buffer * @param len Length of binary buffer * @param str Source ascii string * * @return 0 if success, otherwise errorcode */ int str_hex(uint8_t *hex, size_t len, const char *str) { size_t i; if (!hex || !str || (strlen(str) != (2 * len))) return EINVAL; for (i=0; i equal */ if (s1 == s2) return 0; if (!s1 || !s2) return 1; #ifdef WIN32 return _stricmp(s1, s2); #else return strcasecmp(s1, s2); #endif } /** * Calculate the length of a string, safe version. * * @param s String * * @return Length of the string */ size_t str_len(const char *s) { return s ? strlen(s) : 0; }