-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathdev_null.cc
82 lines (64 loc) · 1.47 KB
/
dev_null.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2012 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "dev_null.h"
#include <assert.h>
#include <string.h>
DevNullHandler::DevNullHandler() : ref_(1) {
}
DevNullHandler::~DevNullHandler() {
assert(!ref_);
}
void DevNullHandler::addref() {
++ref_;
}
void DevNullHandler::release() {
if (!--ref_)
delete this;
}
FileStream* DevNullHandler::open(int fd, const char* pathname, int oflag,
int* err) {
return new DevNull(fd, oflag);
}
int DevNullHandler::stat(const char* pathname, nacl_abi_stat* out) {
memset(out, 0, sizeof(nacl_abi_stat));
return 0;
}
//------------------------------------------------------------------------------
DevNull::DevNull(int fd, int oflag)
: fd_(fd), oflag_(oflag), ref_(1) {
}
DevNull::~DevNull() {
assert(!ref_);
}
void DevNull::addref() {
++ref_;
}
void DevNull::release() {
if (!--ref_)
delete this;
}
FileStream* DevNull::dup(int fd) {
return new DevNull(fd, oflag_);
}
void DevNull::close() {
fd_ = 0;
}
int DevNull::read(char* buf, size_t count, size_t* nread) {
*nread = 0;
return 0;
}
int DevNull::write(const char* buf, size_t count, size_t* nwrote) {
*nwrote = count;
return 0;
}
int DevNull::fcntl(int cmd, va_list ap) {
if (cmd == F_GETFL) {
return oflag_;
} else if (cmd == F_SETFL) {
oflag_ = va_arg(ap, long);
return 0;
} else {
return -1;
}
}