我想从套接字读取数据并使用fwrite将它们写入fuile但我一直得到异常。我的代码:
MyFile = fopen ("flash:/ngfm.bin","wb");
if (MyFile != NULL) {
while ((nBytes = read (dataSock, buf, sizeof (buf))) > 0) {
ByteCount++;
if (ByteCount %10)
printf(".");
if (ByteCount %100)
printf("\n");
fwrite( buf, sizeof(buf), nBytes, MyFile );
}
printf("%d Bytes written to flash:/ngfm.bin!\n", ByteCount);
fclose( MyFile );
}
close (dataSock);
这是vxworks
,我的设备闪存:存在且可写!我在shell上做了以下事情:
JPAX-DP> mf = fopen("flash:/test","w")
New symbol "mf" added to kernel symbol table.
mf = 0x26e75e90: value = 636346784 = 0x25ede1a0
JPAX-DP> fputs("TEST",mf)
value = 0 = 0x0
JPAX-DP> fclose(mf)
value = 0 = 0x0
JPAX-DP> ls("flash:/")
flash:/switch_demo_rem.vxs
flash:/switch_demo_lb_on.vxs
flash:/switch_demo_lb_off.vxs
flash:/switch_demo1b.vxs
flash:/switch_demo1a.vxs
flash:/switch_demo.vxs
flash:/sanity.soc
flash:/rc.soc
flash:/protection_init.vxs
flash:/pack_demo.vxs
flash:/init.vxs
flash:/config.bcm
flash:/BCM56440_B0_0.srec
flash:/BCM56440_A0_1.srec
flash:/BCM56440_A0_0.srec
flash:/jpax_msg.log
flash:/jpax_err.log
flash:/ngfm.bin
flash:/test
答案 0 :(得分:1)
确保“buf”声明正确且足够大。