18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <stddef.h>
78c2ecf20Sopenharmony_ci#include <errno.h>
88c2ecf20Sopenharmony_ci#include <fcntl.h>
98c2ecf20Sopenharmony_ci#include "chan_user.h"
108c2ecf20Sopenharmony_ci#include <os.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* This address is used only as a unique identifier */
138c2ecf20Sopenharmony_cistatic int null_chan;
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistatic void *null_init(char *str, int device, const struct chan_opts *opts)
168c2ecf20Sopenharmony_ci{
178c2ecf20Sopenharmony_ci	return &null_chan;
188c2ecf20Sopenharmony_ci}
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistatic int null_open(int input, int output, int primary, void *d,
218c2ecf20Sopenharmony_ci		     char **dev_out)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	int fd;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	*dev_out = NULL;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	fd = open(DEV_NULL, O_RDWR);
288c2ecf20Sopenharmony_ci	return (fd < 0) ? -errno : fd;
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic int null_read(int fd, char *c_out, void *unused)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	return -ENODEV;
348c2ecf20Sopenharmony_ci}
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistatic void null_free(void *data)
378c2ecf20Sopenharmony_ci{
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciconst struct chan_ops null_ops = {
418c2ecf20Sopenharmony_ci	.type		= "null",
428c2ecf20Sopenharmony_ci	.init		= null_init,
438c2ecf20Sopenharmony_ci	.open		= null_open,
448c2ecf20Sopenharmony_ci	.close		= generic_close,
458c2ecf20Sopenharmony_ci	.read		= null_read,
468c2ecf20Sopenharmony_ci	.write		= generic_write,
478c2ecf20Sopenharmony_ci	.console_write	= generic_console_write,
488c2ecf20Sopenharmony_ci	.window_size	= generic_window_size,
498c2ecf20Sopenharmony_ci	.free		= null_free,
508c2ecf20Sopenharmony_ci	.winch		= 0,
518c2ecf20Sopenharmony_ci};
52