util.c 523 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <thread.h>
  4. #include "usb.h"
  5. int debug, debugdebug, verbose;
  6. char *
  7. namefor(Namelist *list, int item)
  8. {
  9. while (list->name){
  10. if (list->index == item)
  11. return list->name;
  12. list++;
  13. }
  14. return "<unnamed>";
  15. }
  16. void *
  17. emalloc(ulong size)
  18. {
  19. void *x;
  20. x = malloc(size);
  21. if (x == nil)
  22. sysfatal("maloc: %r");
  23. return x;
  24. }
  25. void *
  26. emallocz(ulong size, int zero)
  27. {
  28. void *x;
  29. x = malloc(size);
  30. if (x == nil)
  31. sysfatal("maloc: %r");
  32. if (zero)
  33. memset(x, 0, size);
  34. return x;
  35. }