Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Null.cxx
Go to the documentation of this file.
1
34#include "Devtab.hxx"
35
36#include <sys/stat.h>
37
39const char *STDIN_DEVICE __attribute__ ((weak)) = "/dev/null";
40
42const char *STDOUT_DEVICE __attribute__ ((weak)) = "/dev/null";
43
45const char *STDERR_DEVICE __attribute__ ((weak)) = "/dev/null";
46
48class Null : public Device
49{
50public:
52 Null(const char* path) : Device(path)
53 {
54 }
55
56 ~Null()
57 {
58 }
59
61 int open(File *, const char *, int, int) OVERRIDE;
63 int close(File *) OVERRIDE;
65 ssize_t read(File *, void *, size_t) OVERRIDE;
67 ssize_t write(File *, const void *, size_t) OVERRIDE;
68
74 int fstat(File* file, struct stat *stat) OVERRIDE;
75
76};
77
79Null null("/dev/null");
80
88int Null::open(File* file, const char *path, int flags, int mode)
89{
90 return 0;
91}
92
97int Null::close(File *file)
98{
99 return 0;
100}
101
108ssize_t Null::read(File *file, void *buf, size_t count)
109{
110 // /dev/null returns EOF when trying to read from it.
111 return 0;
112}
113
120ssize_t Null::write(File *file, const void *buf, size_t count)
121{
122 return count;
123}
124
130int Null::fstat(File* file, struct stat *stat)
131{
132 memset(stat, 0, sizeof(*stat));
133 return 0;
134}
135
const char * STDERR_DEVICE
default stderr
Definition Null.cxx:45
const char * STDIN_DEVICE
default stdin
Definition Null.cxx:39
Null null("/dev/null")
Filesystem node for the null device.
const char * STDOUT_DEVICE
default stdout
Definition Null.cxx:42
Null device instance.
Definition Null.cxx:49
int close(File *) OVERRIDE
Close method.
Definition Null.cxx:97
Null(const char *path)
Constructor.
Definition Null.cxx:52
int open(File *, const char *, int, int) OVERRIDE
Open method.
Definition Null.cxx:88
int fstat(File *file, struct stat *stat) OVERRIDE
Get the status information of a file or device.
Definition Null.cxx:130
ssize_t read(File *, void *, size_t) OVERRIDE
Read method.
Definition Null.cxx:108
ssize_t write(File *, const void *, size_t) OVERRIDE
Write method.
Definition Null.cxx:120
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
Definition macros.h:180
Device tab structure.
Definition Devtab.hxx:432
static int stat(struct _reent *reent, const char *path, struct stat *stat)
Get the status information of a file or device.
Definition Device.cxx:165
File information.
Definition Devtab.hxx:52