event-utils.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #ifndef __UTIL_H
  21. #define __UTIL_H
  22. #include <ctype.h>
  23. /* Can be overridden */
  24. void die(const char *fmt, ...);
  25. void *malloc_or_die(unsigned int size);
  26. void warning(const char *fmt, ...);
  27. void pr_stat(const char *fmt, ...);
  28. void vpr_stat(const char *fmt, va_list ap);
  29. /* Always available */
  30. void __die(const char *fmt, ...);
  31. void __warning(const char *fmt, ...);
  32. void __pr_stat(const char *fmt, ...);
  33. void __vdie(const char *fmt, ...);
  34. void __vwarning(const char *fmt, ...);
  35. void __vpr_stat(const char *fmt, ...);
  36. #define min(x, y) ({ \
  37. typeof(x) _min1 = (x); \
  38. typeof(y) _min2 = (y); \
  39. (void) (&_min1 == &_min2); \
  40. _min1 < _min2 ? _min1 : _min2; })
  41. static inline char *strim(char *string)
  42. {
  43. char *ret;
  44. if (!string)
  45. return NULL;
  46. while (*string) {
  47. if (!isspace(*string))
  48. break;
  49. string++;
  50. }
  51. ret = string;
  52. string = ret + strlen(ret) - 1;
  53. while (string > ret) {
  54. if (!isspace(*string))
  55. break;
  56. string--;
  57. }
  58. string[1] = 0;
  59. return ret;
  60. }
  61. static inline int has_text(const char *text)
  62. {
  63. if (!text)
  64. return 0;
  65. while (*text) {
  66. if (!isspace(*text))
  67. return 1;
  68. text++;
  69. }
  70. return 0;
  71. }
  72. #endif