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