util.c 518 B

123456789101112131415161718192021222324252627282930
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include "tests.h"
  8. #include "debugfs.h"
  9. int trace_event__id(const char *evname)
  10. {
  11. char *filename;
  12. int err = -1, fd;
  13. if (asprintf(&filename,
  14. "%s/syscalls/%s/id",
  15. tracing_events_path, evname) < 0)
  16. return -1;
  17. fd = open(filename, O_RDONLY);
  18. if (fd >= 0) {
  19. char id[16];
  20. if (read(fd, id, sizeof(id)) > 0)
  21. err = atoi(id);
  22. close(fd);
  23. }
  24. free(filename);
  25. return err;
  26. }