-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathdev_random.h
56 lines (42 loc) · 1.42 KB
/
dev_random.h
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
// 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.
#ifndef DEV_RANDOM_H
#define DEV_RANDOM_H
#include "file_interfaces.h"
#include "pthread_helpers.h"
class DevRandomHandler : public PathHandler {
public:
DevRandomHandler(
int (*get_random_bytes)(void* buf, size_t count, size_t* nread));
virtual ~DevRandomHandler();
virtual void addref();
virtual void release();
virtual FileStream* open(int fd, const char* pathname, int oflag, int* err);
virtual int stat(const char* pathname, nacl_abi_stat* out);
private:
int ref_;
int (*get_random_bytes_)(void* buf, size_t count, size_t* nread);
DISALLOW_COPY_AND_ASSIGN(DevRandomHandler);
};
class DevRandom : public FileStream {
public:
DevRandom(int fd, int oflag,
int (*get_random_bytes)(void* buf, size_t count, size_t* nread));
virtual ~DevRandom();
virtual void addref();
virtual void release();
virtual FileStream* dup(int fd);
virtual void close();
virtual int read(char* buf, size_t count, size_t* nread);
virtual int write(const char* buf, size_t count, size_t* nwrote);
virtual int fstat(nacl_abi_stat* out);
virtual int fcntl(int cmd, va_list ap);
private:
int fd_;
int oflag_;
int ref_;
int (*get_random_bytes_)(void* buf, size_t count, size_t* nread);
DISALLOW_COPY_AND_ASSIGN(DevRandom);
};
#endif // DEV_RANDOM_H