dropt_string.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /** dropt_string.h
  2. *
  3. * String routines for dropt.
  4. *
  5. * Copyright (c) 2006-2010 James D. Lin <jameslin@cal.berkeley.edu>
  6. *
  7. * The latest version of this file can be downloaded from:
  8. * <http://www.taenarum.com/software/dropt/>
  9. *
  10. * This software is provided 'as-is', without any express or implied
  11. * warranty. In no event will the authors be held liable for any damages
  12. * arising from the use of this software.
  13. *
  14. * Permission is granted to anyone to use this software for any purpose,
  15. * including commercial applications, and to alter it and redistribute it
  16. * freely, subject to the following restrictions:
  17. *
  18. * 1. The origin of this software must not be misrepresented; you must not
  19. * claim that you wrote the original software. If you use this software
  20. * in a product, an acknowledgment in the product documentation would be
  21. * appreciated but is not required.
  22. *
  23. * 2. Altered source versions must be plainly marked as such, and must not be
  24. * misrepresented as being the original software.
  25. *
  26. * 3. This notice may not be removed or altered from any source distribution.
  27. */
  28. #ifndef DROPT_STRING_H
  29. #define DROPT_STRING_H
  30. #include <stdarg.h>
  31. #include "dropt.h"
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. #ifdef DROPT_USE_WCHAR
  36. #define dropt_strlen wcslen
  37. #define dropt_strcmp wcscmp
  38. #define dropt_strncmp wcsncmp
  39. #define dropt_strchr wcschr
  40. #define dropt_strtol wcstol
  41. #define dropt_strtoul wcstoul
  42. #define dropt_strtod wcstod
  43. #define dropt_tolower towlower
  44. #define dropt_fputs fputws
  45. #else
  46. #define dropt_strlen strlen
  47. #define dropt_strcmp strcmp
  48. #define dropt_strncmp strncmp
  49. #define dropt_strchr strchr
  50. #define dropt_strtol strtol
  51. #define dropt_strtoul strtoul
  52. #define dropt_strtod strtod
  53. #define dropt_tolower tolower
  54. #define dropt_fputs fputs
  55. #endif
  56. void* dropt_safe_malloc(size_t numElements, size_t elementSize);
  57. void* dropt_safe_realloc(void* p, size_t numElements, size_t elementSize);
  58. dropt_char* dropt_strdup(const dropt_char* s);
  59. dropt_char* dropt_strndup(const dropt_char* s, size_t n);
  60. int dropt_stricmp(const dropt_char* s, const dropt_char* t);
  61. int dropt_strnicmp(const dropt_char* s, const dropt_char* t, size_t n);
  62. #ifndef DROPT_NO_STRING_BUFFERS
  63. typedef struct dropt_stringstream dropt_stringstream;
  64. int dropt_vsnprintf(dropt_char* s, size_t n, const dropt_char* format, va_list args);
  65. int dropt_snprintf(dropt_char* s, size_t n, const dropt_char* format, ...);
  66. dropt_char* dropt_vasprintf(const dropt_char* format, va_list args);
  67. dropt_char* dropt_asprintf(const dropt_char* format, ...);
  68. dropt_stringstream* dropt_ssopen(void);
  69. void dropt_ssclose(dropt_stringstream* ss);
  70. void dropt_ssclear(dropt_stringstream* ss);
  71. dropt_char* dropt_ssfinalize(dropt_stringstream* ss);
  72. const dropt_char* dropt_ssgetstring(const dropt_stringstream* ss);
  73. int dropt_vssprintf(dropt_stringstream* ss, const dropt_char* format, va_list args);
  74. int dropt_ssprintf(dropt_stringstream* ss, const dropt_char* format, ...);
  75. #endif /* DROPT_NO_STRING_BUFFERS */
  76. #ifdef __cplusplus
  77. } /* extern "C" */
  78. #endif
  79. #endif /* DROPT_STRING_H */