My build of nnn with minor changes
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

89 lignes
2.5 KiB

  1. /*
  2. * BSD 2-Clause License
  3. *
  4. * Copyright (C) 2014-2016, Lazaros Koromilas <lostd@2f30.org>
  5. * Copyright (C) 2014-2016, Dimitris Papastamos <sin@2f30.org>
  6. * Copyright (C) 2016-2019, Arun Prakash Jana <engineerarun@gmail.com>
  7. * 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, this
  13. * list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  25. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  26. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #pragma once
  31. #ifdef DBGMODE
  32. static int DEBUG_FD;
  33. static int xprintf(int fd, const char *fmt, ...)
  34. {
  35. char buf[BUFSIZ];
  36. int r;
  37. va_list ap;
  38. va_start(ap, fmt);
  39. r = vsnprintf(buf, sizeof(buf), fmt, ap);
  40. if (r > 0)
  41. r = write(fd, buf, r);
  42. va_end(ap);
  43. return r;
  44. }
  45. static int enabledbg(void)
  46. {
  47. FILE *fp = fopen("/tmp/nnndbg", "w");
  48. if (!fp) {
  49. perror("dbg(1)");
  50. fp = fopen("./nnndbg", "w");
  51. if (!fp) {
  52. perror("dbg(2)");
  53. return -1;
  54. }
  55. }
  56. DEBUG_FD = dup(fileno(fp));
  57. fclose(fp);
  58. if (DEBUG_FD == -1) {
  59. perror("dbg(3)");
  60. return -1;
  61. }
  62. return 0;
  63. }
  64. static void disabledbg(void)
  65. {
  66. close(DEBUG_FD);
  67. }
  68. #define DPRINTF_D(x) xprintf(DEBUG_FD, #x "=%d\n", x)
  69. #define DPRINTF_U(x) xprintf(DEBUG_FD, #x "=%u\n", x)
  70. #define DPRINTF_S(x) xprintf(DEBUG_FD, #x "=%s\n", x)
  71. #define DPRINTF_P(x) xprintf(DEBUG_FD, #x "=%p\n", x)
  72. #else
  73. #define DPRINTF_D(x)
  74. #define DPRINTF_U(x)
  75. #define DPRINTF_S(x)
  76. #define DPRINTF_P(x)
  77. #endif /* DBGMODE */