我写了这个:linux编程:写入设备文件
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <mtd/mtd-user.h>
#include <errno.h>
int main(void)
{
int fd;
char buf[4]="abc";
fd = open("/dev/mtd0", O_RDWR);
lseek(fd, 1, SEEK_SET);
write(fd, &buf, 4);
close(fd);
perror("perror output:");
return 0;
}
使用nandsim内核模块中创建的文件/ dev/mtd0,并运行
mtdinfo /dev/mtd0
得到有意义的output.After我运行我的程序,它的输出:
perror output:: Invalid argument
如果在我的程序的任何错误?
您的错误报告是错误的。您需要检查每个系统调用/库函数的返回值,并在调用_failed_之后使用'perror' _right,而不需要中介函数调用。正如所写的,你所做的'perror'调用根本不会给你任何信息。 – Mat 2012-04-28 09:07:23