slac_debug.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. * Copyright (c) 2013 I2SE GmbH
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or
  9. * without modification, are permitted (subject to the limitations
  10. * in the disclaimer below) provided that the following conditions
  11. * are met:
  12. *
  13. * * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * * Redistributions in binary form must reproduce the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer in the documentation and/or other materials
  19. * provided with the distribution.
  20. *
  21. * * Neither the name of Qualcomm Atheros nor the names of
  22. * its contributors may be used to endorse or promote products
  23. * derived from this software without specific prior written
  24. * permission.
  25. *
  26. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  27. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  28. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  29. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  30. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  32. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  34. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  35. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  36. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  37. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  38. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  39. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. *--------------------------------------------------------------------*/
  42. /*====================================================================*
  43. *
  44. * signed slac_debug (struct session * session, signed status, char const * string, char const * format, ...);
  45. *
  46. * slac.h
  47. *
  48. * variation of the GNU error() function that accepts a message in
  49. * place of an error code and always returns -1;
  50. *
  51. *--------------------------------------------------------------------*/
  52. #ifndef SLAC_DEBUG_SOURCE
  53. #define SLAC_DEBUG_SOURCE
  54. #include <stdio.h>
  55. #include <stdlib.h>
  56. #include <stdarg.h>
  57. #include <string.h>
  58. #include "../slac/slac.h"
  59. #include "../tools/types.h"
  60. #include "../tools/error.h"
  61. #include "../tools/flags.h"
  62. #ifdef __GNUC__
  63. __attribute__ ((format (printf, 4, 5)))
  64. #endif
  65. signed slac_debug (struct session * session, signed status, char const * string, char const * format, ...)
  66. {
  67. extern char const * program_name;
  68. if (_allclr (session->flags, SLAC_SILENCE))
  69. {
  70. if ((program_name) && (* program_name))
  71. {
  72. fprintf (stderr, "%s: ", program_name);
  73. }
  74. if ((string) && (* string))
  75. {
  76. fprintf (stderr, "%s: ", string);
  77. }
  78. if ((format) && (*format))
  79. {
  80. va_list arglist;
  81. va_start (arglist, format);
  82. vfprintf (stderr, format, arglist);
  83. va_end (arglist);
  84. }
  85. fprintf (stderr, "\n");
  86. fflush (stderr);
  87. }
  88. if (status)
  89. {
  90. exit (status);
  91. }
  92. return (-1);
  93. }
  94. #endif