我寫了這個: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