null.c 970 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
  3. * Licensed under the GPL
  4. */
  5. #include <stddef.h>
  6. #include <errno.h>
  7. #include <fcntl.h>
  8. #include "chan_user.h"
  9. #include <os.h>
  10. /* This address is used only as a unique identifier */
  11. static int null_chan;
  12. static void *null_init(char *str, int device, const struct chan_opts *opts)
  13. {
  14. return &null_chan;
  15. }
  16. static int null_open(int input, int output, int primary, void *d,
  17. char **dev_out)
  18. {
  19. int fd;
  20. *dev_out = NULL;
  21. fd = open(DEV_NULL, O_RDWR);
  22. return (fd < 0) ? -errno : fd;
  23. }
  24. static int null_read(int fd, char *c_out, void *unused)
  25. {
  26. return -ENODEV;
  27. }
  28. static void null_free(void *data)
  29. {
  30. }
  31. const struct chan_ops null_ops = {
  32. .type = "null",
  33. .init = null_init,
  34. .open = null_open,
  35. .close = generic_close,
  36. .read = null_read,
  37. .write = generic_write,
  38. .console_write = generic_console_write,
  39. .window_size = generic_window_size,
  40. .free = null_free,
  41. .winch = 0,
  42. };