关于C#:’FILE’在Contiki中是未知的类型

'FILE' is unknown type in Contiki

我正试图在康提基的一个文件中测试写作。这是我使用的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include"contiki.h"
#include <stdio.h>
#define LEN 256
 PROCESS(test_process,"Coffee test process");
 AUTOSTART_PROCESSES(&test_process);
 PROCESS_THREAD(test_process, ev, data)
 /**/
 {
  PROCESS_BEGIN();
FILE * fp;
   int i;
   /* open the file for writing*/
   fp = fopen ("/home/user/contiki/examples/mySim/1.txt","w");

   /* write 10 lines of text into the file stream*/
   for(i = 0; i < 10;i++){
       fprintf (fp,"This is line %d
"
,i + 1);
   }

   /* close the file*/  
   fclose (fp);
  PROCESS_END();
 }

在Cooja模拟器中编译后,我收到此错误消息:

test.c: In function ‘process_thread_test_process’:
test.c:12:1: error: unknown type name ‘FILE’
test.c:15:4: warning: implicit declaration of function ‘fopen’ [-Wimplicit-function-declaration]
test.c:15:7: warning: assignment makes pointer from integer without a cast [enabled by default]
test.c:19:8: warning: implicit declaration of function ‘fprintf’ [-Wimplicit-function-declaration]
test.c:19:8: warning: incompatible implicit declaration of built-in function ‘fprintf’ [enabled by default]
test.c:23:4: warning: implicit declaration of function ‘fclose’ [-Wimplicit-function-declaration]
make: *** [test.co] Error 1
Process returned error code 2

有人知道这个问题吗?


Contiki不提供/支持POSIX文件API,与它没有其他许多东西(POSIX套接字API、POSIX进程创建和控制API)的方式相同。相反,它提供了自己的文件系统API("ProtoSockets"API、"ProtoThreads"API等)。

有两种文件系统实现:CFS(Contiki文件系统)和Coffee。您可以使用wiki页面中描述的函数;它们类似于低级posix文件API(例如,cfs_open类似于posix opencfs_close类似于posix close等)。缓冲I/O功能(fopenfclose)没有类似物,FILE结构不存在。