event-utils.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. static inline char *strim(char *string)
  25. {
  26. char *ret;
  27. if (!string)
  28. return NULL;
  29. while (*string) {
  30. if (!isspace(*string))
  31. break;
  32. string++;
  33. }
  34. ret = string;
  35. string = ret + strlen(ret) - 1;
  36. while (string > ret) {
  37. if (!isspace(*string))
  38. break;
  39. string--;
  40. }
  41. string[1] = 0;
  42. return ret;
  43. }
  44. static inline int has_text(const char *text)
  45. {
  46. if (!text)
  47. return 0;
  48. while (*text) {
  49. if (!isspace(*text))
  50. return 1;
  51. text++;
  52. }
  53. return 0;
  54. }
  55. #endif