parse-utils.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
  3. *
  4. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation;
  8. * version 2.1 of the License (not later!)
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this program; if not, see <http://www.gnu.org/licenses>
  17. *
  18. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <stdarg.h>
  24. #include <errno.h>
  25. #define __weak __attribute__((weak))
  26. void __vdie(const char *fmt, va_list ap)
  27. {
  28. int ret = errno;
  29. if (errno)
  30. perror("trace-cmd");
  31. else
  32. ret = -1;
  33. fprintf(stderr, " ");
  34. vfprintf(stderr, fmt, ap);
  35. fprintf(stderr, "\n");
  36. exit(ret);
  37. }
  38. void __die(const char *fmt, ...)
  39. {
  40. va_list ap;
  41. va_start(ap, fmt);
  42. __vdie(fmt, ap);
  43. va_end(ap);
  44. }
  45. void __weak die(const char *fmt, ...)
  46. {
  47. va_list ap;
  48. va_start(ap, fmt);
  49. __vdie(fmt, ap);
  50. va_end(ap);
  51. }
  52. void __vwarning(const char *fmt, va_list ap)
  53. {
  54. if (errno)
  55. perror("trace-cmd");
  56. errno = 0;
  57. fprintf(stderr, " ");
  58. vfprintf(stderr, fmt, ap);
  59. fprintf(stderr, "\n");
  60. }
  61. void __warning(const char *fmt, ...)
  62. {
  63. va_list ap;
  64. va_start(ap, fmt);
  65. __vwarning(fmt, ap);
  66. va_end(ap);
  67. }
  68. void __weak warning(const char *fmt, ...)
  69. {
  70. va_list ap;
  71. va_start(ap, fmt);
  72. __vwarning(fmt, ap);
  73. va_end(ap);
  74. }
  75. void __vpr_stat(const char *fmt, va_list ap)
  76. {
  77. vprintf(fmt, ap);
  78. printf("\n");
  79. }
  80. void __pr_stat(const char *fmt, ...)
  81. {
  82. va_list ap;
  83. va_start(ap, fmt);
  84. __vpr_stat(fmt, ap);
  85. va_end(ap);
  86. }
  87. void __weak vpr_stat(const char *fmt, va_list ap)
  88. {
  89. __vpr_stat(fmt, ap);
  90. }
  91. void __weak pr_stat(const char *fmt, ...)
  92. {
  93. va_list ap;
  94. va_start(ap, fmt);
  95. __vpr_stat(fmt, ap);
  96. va_end(ap);
  97. }
  98. void __weak *malloc_or_die(unsigned int size)
  99. {
  100. void *data;
  101. data = malloc(size);
  102. if (!data)
  103. die("malloc");
  104. return data;
  105. }