event-utils.h 2.0 KB

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