upnputil.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef UTIL_H
  2. #define UTIL_H
  3. /*******************************************************************************
  4. *
  5. * Copyright (c) 2000-2003 Intel Corporation
  6. * All rights reserved.
  7. * Copyright (c) 2012 France Telecom All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * - Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * - Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * - Neither name of Intel Corporation nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
  25. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  29. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************/
  34. /*!
  35. * \file
  36. */
  37. #include "upnp.h"
  38. #include <errno.h>
  39. /* usually used to specify direction of parameters in functions */
  40. #ifndef IN
  41. #define IN
  42. #endif
  43. #ifndef OUT
  44. #define OUT
  45. #endif
  46. #ifndef INOUT
  47. #define INOUT
  48. #endif
  49. #define GEMD_OUT_OF_MEMORY -1
  50. #define EVENT_TIMEDOUT -2
  51. #define EVENT_TERMINATE -3
  52. /*! boolean type in C. */
  53. #ifndef TRUE
  54. #define TRUE 1
  55. #endif
  56. #ifndef FALSE
  57. #define FALSE 0
  58. #endif
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. /*!
  63. * \brief Copy no of bytes spcified by the LINE_SIZE constant, from the
  64. * source buffer. Null terminate the destination buffer.
  65. */
  66. void linecopy(
  67. /*! [out] output buffer. */
  68. char dest[LINE_SIZE],
  69. /*! [in] input buffer. */
  70. const char *src);
  71. /*!
  72. * \brief Copy no of bytes spcified by the NAME_SIZE constant, from the
  73. * source buffer. Null terminate the destination buffer
  74. */
  75. void namecopy(
  76. /*! [out] output buffer. */
  77. char dest[NAME_SIZE],
  78. /*! [in] input buffer. */
  79. const char *src);
  80. /*!
  81. * \brief Determine if the srclen passed in paramter is less than the
  82. * permitted LINE_SIZE. If it is use the passed parameter, if not
  83. * use the permitted LINE_SIZE as the length parameter.
  84. *
  85. * Copy no of bytes spcified by the LINE_SIZE constant, from the source
  86. * buffer. Null terminate the destination buffer.
  87. */
  88. void linecopylen(
  89. /*! [out] output buffer. */
  90. char dest[LINE_SIZE],
  91. /*! [in] input buffer. */
  92. const char *src,
  93. /*! [in] bytes to be copied. */
  94. size_t srclen);
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. /* Size of the errorBuffer variable, passed to the strerror_r() function */
  99. #define ERROR_BUFFER_LEN (size_t)256
  100. /* C specific */
  101. /* VC needs these in C++ mode too (do other compilers?) */
  102. #if !defined(__cplusplus) || defined(UPNP_USE_MSVCPP)
  103. #ifdef WIN32
  104. #ifndef S_ISREG
  105. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  106. #endif
  107. #ifndef S_ISDIR
  108. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  109. #endif
  110. #ifndef EADDRINUSE /* VS2010 has this defined */
  111. #define EADDRINUSE WSAEADDRINUSE
  112. #endif
  113. #define strcasecmp stricmp
  114. #define strncasecmp strnicmp
  115. #define sleep(a) Sleep((a)*1000)
  116. #define usleep(a) Sleep((a)/1000)
  117. #define strerror_r(a,b,c) (strerror_s((b),(c),(a)))
  118. #else
  119. #define max(a, b) (((a)>(b))? (a):(b))
  120. #define min(a, b) (((a)<(b))? (a):(b))
  121. #endif /* WIN32 */
  122. #endif /* !defined(__cplusplus) || defined(UPNP_USE_MSVCPP) */
  123. #endif /* UTIL_H */