event-utils.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* SPDX-License-Identifier: LGPL-2.1 */
  2. /*
  3. * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
  4. *
  5. */
  6. #ifndef __UTIL_H
  7. #define __UTIL_H
  8. #include <ctype.h>
  9. /* Can be overridden */
  10. void warning(const char *fmt, ...);
  11. void pr_stat(const char *fmt, ...);
  12. void vpr_stat(const char *fmt, va_list ap);
  13. /* Always available */
  14. void __warning(const char *fmt, ...);
  15. void __pr_stat(const char *fmt, ...);
  16. void __vwarning(const char *fmt, ...);
  17. void __vpr_stat(const char *fmt, ...);
  18. #define min(x, y) ({ \
  19. typeof(x) _min1 = (x); \
  20. typeof(y) _min2 = (y); \
  21. (void) (&_min1 == &_min2); \
  22. _min1 < _min2 ? _min1 : _min2; })
  23. static inline char *strim(char *string)
  24. {
  25. char *ret;
  26. if (!string)
  27. return NULL;
  28. while (*string) {
  29. if (!isspace(*string))
  30. break;
  31. string++;
  32. }
  33. ret = string;
  34. string = ret + strlen(ret) - 1;
  35. while (string > ret) {
  36. if (!isspace(*string))
  37. break;
  38. string--;
  39. }
  40. string[1] = 0;
  41. return ret;
  42. }
  43. static inline int has_text(const char *text)
  44. {
  45. if (!text)
  46. return 0;
  47. while (*text) {
  48. if (!isspace(*text))
  49. return 1;
  50. text++;
  51. }
  52. return 0;
  53. }
  54. #endif