下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

最新资讯
简化任何设备的身份验证云连接。
利用 CoAP 设计节能型云连接 IoT 解决方案。
11.0.0 版 FreeRTOS 内核简介:
FreeRTOS 路线图和代码贡献流程。
使用 FreeRTOS 实现 OPC-UA over TSN。

ff_fopen()

[FreeRTOS-Plus-FAT 标准 API 引用]

ff_stdio.h
FF_FILE *ff_fopen( const char *pcFile, const char *pcMode );
		

在嵌入式 FAT 文件系统中打开文件。

参数:

pcFile   指向以 null 结尾的标准 C 字符串的指针,该字符串包含 正在打开的文件的名称。 该字符串 可包含相对路径。

pcMode   设置文件打开模式的字符串。 有效字符串包括:

字母 模式
"r" 以只读方式打开文件。
"r+" 以可读写方式打开文件。
"w" 以可写入方式打开文件。如果文件已经存在, 则文件长度会被截断为 0。如果文件尚不存在, 则它将被创建。
"a" 以可写入方式打开文件。 如果文件 已经存在,则新数据将附加到 文件结尾。 如果文件尚不存在, 则将创建新文件。
"a+" 以可读写方式打开文件。 如果文件 已经存在,则新数据将附加到 文件结尾。 如果文件尚不存在, 则将创建新文件。

文件始终以二进制模式打开。

返回:

如果成功打开文件, 则返回指向该文件的指针。

如果无法打开文件,则返回 NULL, 并设置任务的 errno 以指示原因。 任务 可以使用 stdioGET_ERRNO() API 函数 获取其 errno 值。

用法示例:


BaseType_t xCopyFile( char *pcSourceFileName, char *pcDestinationFileName )
{
FF_FILE *pxSourceFile, *pxDestinationFile;
size_t xCount;
uint32_t ucBuffer[ 50 ];

/* Open the source file in read only mode. */
pxSourceFile = ff_fopen( pcSourceFileName, "r" );

if( pxSourceFile != NULL )
{
/* Create or overwrite a writable file. */
pxDestinationFile = ff_fopen( pcDestinationFileName, "w+" );

if( pxDestinationFile != NULL )
{
for( ;; )
{
/* Read sizeof( ucBuffer ) bytes from the source file into a buffer. */
xCount = ff_fread( ucBuffer, 1, sizeof( ucBuffer ), pxSourceFile );

/* Write however many bytes were read from the source file into the
destination file. */

ff_fwrite( ucBuffer, xCount, 1, pxDestinationFile );

if( xCount < sizeof( ucBuffer ) )
{
/* The end of the flie was reached. */
break;
}
}

/* Close the destination file. */
ff_fclose( pxDestinationFile );
}

/* Close the source file. */
ff_fclose( pxSourceFile );
}
}

Example use of the ff_fopen() API function to open or create a file


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.