event-utils.h 1.8 KB

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