macros.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 in compliance
  4. with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2014
  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. BOOL STRNCPY(char* pcDst_, const char* pcSrc_, size_t num_);
  60. ////////////////////////////////////////////////////////////////////
  61. // Parameters:
  62. // pcDst_: destination address.
  63. // pcSrc_: source address.
  64. // uNum_: size of destination buffer.
  65. //
  66. // Returns TRUE when there has been a complete copy.
  67. // Returns FALSE when dst or src are NULL or when buffer size is too small to do a complete copy.
  68. // NOTE: Guaranteed to have a NULL terminating character.
  69. // NOTE: When unsuccessful, pcDst_ is not modified.
  70. ////////////////////////////////////////////////////////////////////
  71. BOOL STRNCAT(char* pcDst_, const char* pcSrc_, size_t num_);
  72. ////////////////////////////////////////////////////////////////////
  73. // Parameters:
  74. // pcDst_: destination address.
  75. // pcSrc_: source address.
  76. // uNum_: size of destination buffer.
  77. //
  78. // Returns TRUE when there has been a complete concatenation.
  79. // Returns FALSE when dst or src are NULL or when buffer size is too small to do a complete concatenation.
  80. // NOTE: Guaranteed to have a NULL terminating character.
  81. // NOTE: When unsuccessful, pcDst_ is not modified.
  82. ////////////////////////////////////////////////////////////////////
  83. FILE* FOPEN(const char* pcFilename_, const char* pcMode_);
  84. ////////////////////////////////////////////////////////////////////
  85. // Parameters:
  86. // pcFilename_: name of the file to open
  87. // pcMode_: the rights to the file needed
  88. //
  89. // On success, returns file pointer.
  90. // On failure, returns NULL.
  91. ////////////////////////////////////////////////////////////////////
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif // !defined(MACROS_H)