【发布时间】:2016-09-12 02:10:31
【问题描述】:
我在 CentOS 7 上实现了一个字符设备驱动程序。当从 C 程序调用该驱动程序时,它运行正常,因此...
char bytes[8];
int fd = open("/dev/fortuna", O_RDONLY);
if (fd < 0) {
perror("File open error: ");
return -1;
}
int in = read(fd, bytes, 8);
if (in < 0) {
perror("File read error: ");
}
close(fd);
使用 count = 8 调用驱动程序读取函数,程序完成且没有错误。驱动函数原型是……
static ssize_t fortuna_read(struct file *filp, char *buff, size_t count, loff_t *offp);
但是,如果从 C++ 流中调用读取,则如下...
char bytes[8];
std::ifstream in("/dev/fortuna");
if (in.good()) {
in.read(bytes, 8);
}
in.close();
驱动读取函数调用count = 8191。如果驱动是从Java FileReader调用的,如下...
File file = new File("/dev/fortuna");
file.setReadOnly();
FileReader reader = new FileReader(file);
char[] cbuf = new char[8];
int read = reader.read(cbuf);
reader.close();
使用 count = 8192 调用驱动程序读取函数。写入函数的行为类似。
Google 让我失望了。帮忙?
【问题讨论】:
标签: inputstream linux-device-driver iostream