event-utils.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. 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