macros.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  6. All rights reserved.
  7. */
  8. // Standard Library function macros.
  9. // Microsoft has decided to brand these functions with their own set of
  10. // conventions, so I've included translations from the standard
  11. // functions to the MS functions below. The functions that should be
  12. // used in this project have been renamed to the all-caps version of
  13. // the standard names.
  14. //All these macros are not compliant with the wide character set!
  15. #ifndef MACROS_H
  16. #define MACROS_H
  17. #include "types.h"
  18. #include <stdio.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. //////////////////////////////////////////////////////////////////////////////////
  23. // Public Definitions
  24. //////////////////////////////////////////////////////////////////////////////////
  25. #if defined(_MSC_VER)
  26. #define FPRINTF fprintf_s
  27. #else
  28. #define FPRINTF fprintf
  29. #endif
  30. ////////////////////////////////////////////////////////////////////
  31. // Parameters:
  32. // FILE* pfFile_: file to write to
  33. // const char* pcFormat_: specifies how to format output
  34. // ... : arguments to write
  35. //
  36. // On success, returns number of bytes/characters written.
  37. // On failure, returns negative number.
  38. // NOTE: Returned value does not include NULL characters on end of
  39. // strings or at end of the string written to the file.
  40. ////////////////////////////////////////////////////////////////////
  41. //////////////////////////////////////////////////////////////////////////////////
  42. // Public Function Prototypes
  43. //////////////////////////////////////////////////////////////////////////////////
  44. int SNPRINTF(char* pcDst_, size_t uNum_, const char* pcFormat_, ...);
  45. ////////////////////////////////////////////////////////////////////
  46. // Parameters:
  47. // pcDst_: destination address.
  48. // uNum_: size of destination buffer.
  49. // pcFormat_: specifies how to format output
  50. // ... : arguments to write
  51. //
  52. // On success, returns the number of characters written not including the NULL character.
  53. // On failure, returns -1.
  54. // NOTE: If the buffer is too small, the output will be truncated.
  55. // NOTE: SNPRINTF uses functions not compatible with older libraries but are C99 standard.
  56. // NOTE: Guaranteed to have a NULL terminating character.
  57. // NOTE: Uses functions in the C99 standard but not included in the C89/C90 standards.
  58. ////////////////////////////////////////////////////////////////////
  59. size_t VSNPRINTF(char* pcDst_, size_t uNum_, const char* pcFormat_, va_list args);
  60. ////////////////////////////////////////////////////////////////////
  61. // Parameters:
  62. // pcDst_: destination address.
  63. // uNum_: size of destination buffer.
  64. // pcFormat_: specifies how to format output
  65. // args : arguments to write
  66. //
  67. // On success, returns the number of characters written not including the NULL character.
  68. // On failure, returns -1.
  69. // NOTE: If the buffer is too small, the output will be truncated.
  70. // NOTE: SNPRINTF uses functions not compatible with older libraries but are C99 standard.
  71. // NOTE: Guaranteed to have a NULL terminating character.
  72. // NOTE: Uses functions in the C99 standard but not included in the C89/C90 standards.
  73. ////////////////////////////////////////////////////////////////////
  74. BOOL STRNCPY(char* pcDst_, const char* pcSrc_, size_t num_);
  75. ////////////////////////////////////////////////////////////////////
  76. // Parameters:
  77. // pcDst_: destination address.
  78. // pcSrc_: source address.
  79. // uNum_: size of destination buffer.
  80. //
  81. // Returns TRUE when there has been a complete copy.
  82. // Returns FALSE when dst or src are NULL or when buffer size is too small to do a complete copy.
  83. // NOTE: Guaranteed to have a NULL terminating character.
  84. // NOTE: When unsuccessful, pcDst_ is not modified.
  85. ////////////////////////////////////////////////////////////////////
  86. BOOL STRNCAT(char* pcDst_, const char* pcSrc_, size_t num_);
  87. ////////////////////////////////////////////////////////////////////
  88. // Parameters:
  89. // pcDst_: destination address.
  90. // pcSrc_: source address.
  91. // uNum_: size of destination buffer.
  92. //
  93. // Returns TRUE when there has been a complete concatenation.
  94. // Returns FALSE when dst or src are NULL or when buffer size is too small to do a complete concatenation.
  95. // NOTE: Guaranteed to have a NULL terminating character.
  96. // NOTE: When unsuccessful, pcDst_ is not modified.
  97. ////////////////////////////////////////////////////////////////////
  98. FILE* FOPEN(const char* pcFilename_, const char* pcMode_);
  99. ////////////////////////////////////////////////////////////////////
  100. // Parameters:
  101. // pcFilename_: name of the file to open
  102. // pcMode_: the rights to the file needed
  103. //
  104. // On success, returns file pointer.
  105. // On failure, returns NULL.
  106. ////////////////////////////////////////////////////////////////////
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif // !defined(MACROS_H)