null.c 970 Bytes
Newer Older
Jeff Dike's avatar
Jeff Dike committed
1
/*
Jeff Dike's avatar
Jeff Dike committed
2
 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
Linus Torvalds's avatar
Linus Torvalds committed
3
4
5
 * Licensed under the GPL
 */

Jeff Dike's avatar
Jeff Dike committed
6
#include <stddef.h>
Linus Torvalds's avatar
Linus Torvalds committed
7
#include <errno.h>
Jeff Dike's avatar
Jeff Dike committed
8
9
#include <fcntl.h>
#include "chan_user.h"
Jeff Dike's avatar
Jeff Dike committed
10
#include "os.h"
Linus Torvalds's avatar
Linus Torvalds committed
11

Simon Arlott's avatar
Simon Arlott committed
12
/* This address is used only as a unique identifier */
Linus Torvalds's avatar
Linus Torvalds committed
13
14
static int null_chan;

Jeff Dike's avatar
Jeff Dike committed
15
static void *null_init(char *str, int device, const struct chan_opts *opts)
Linus Torvalds's avatar
Linus Torvalds committed
16
{
Jeff Dike's avatar
Jeff Dike committed
17
	return &null_chan;
Linus Torvalds's avatar
Linus Torvalds committed
18
19
20
21
22
}

static int null_open(int input, int output, int primary, void *d,
		     char **dev_out)
{
Jeff Dike's avatar
Jeff Dike committed
23
24
	int fd;

Linus Torvalds's avatar
Linus Torvalds committed
25
	*dev_out = NULL;
Jeff Dike's avatar
Jeff Dike committed
26
27
28

	fd = open(DEV_NULL, O_RDWR);
	return (fd < 0) ? -errno : fd;
Linus Torvalds's avatar
Linus Torvalds committed
29
30
31
32
}

static int null_read(int fd, char *c_out, void *unused)
{
Jeff Dike's avatar
Jeff Dike committed
33
	return -ENODEV;
Linus Torvalds's avatar
Linus Torvalds committed
34
35
36
37
38
39
}

static void null_free(void *data)
{
}

Jeff Dike's avatar
Jeff Dike committed
40
const struct chan_ops null_ops = {
Linus Torvalds's avatar
Linus Torvalds committed
41
42
43
44
45
46
47
48
49
50
51
	.type		= "null",
	.init		= null_init,
	.open		= null_open,
	.close		= generic_close,
	.read		= null_read,
	.write		= generic_write,
	.console_write	= generic_console_write,
	.window_size	= generic_window_size,
	.free		= null_free,
	.winch		= 0,
};