相关系统文件操作封装
nw_fs.c
#include "nw_define.h"
#include "Fs_errcode.h"
#include "Vmsys.h"
static nw_uint32 nw_file_get_open_flag(const char* mode)
{
nw_uint32 flag = 0;
switch (*mode)
{
case 'r':
flag = NW_READ_ONLY;
if (*(mode + 1) == '+')
{
flag = NW_READ_WRITE;
}
break;
case 'w':
flag = NW_READ_WRITE | NW_CREATE_ALWAYS;
if (*(mode + 1) == '+')
{
flag = NW_READ_WRITE | NW_CREATE_ALWAYS;
}
break;
case 'a':
flag = NW_READ_WRITE |NW_CREATE;
if (*(mode + 1) == '+')
{
flag = NW_READ_WRITE | NW_CREATE;
}
break;
case 'd':
flag = NW_OPEN_DIR | NW_READ_ONLY;
break;
default:
break;
}
if (strchr(mode, 'h') != 0)
{
flag |= NW_ATTR_HIDDEN;
}
return flag;
}
nw_int32 nw_fs_open(const nw_uint16 *file_name, const char *mode)
{
nw_int32 file_handle = 0;
nw_uint32 flag = 0;
if (file_name == 0)
{
return file_handle;
}
flag =nw_file_get_open_flag(mode);
file_handle = FS_Open(file_name, flag);
if (*mode == 'a')
{
//移动文件指针到末尾
FS_Seek(file_handle, 0, 2);
}
return file_handle;
}
nw_int32 nw_fs_read()
{
//DUMMY
return 0;
}
nw_int32 nw_fs_write(nw_uint32 file_handle, void* buf, nw_uint32 size)
{
nw_int32 ressult = 0;
nw_uint32 writed = 0;
if ((ressult = FS_Write(file_handle, buf, size, &writed)) < 0)
{
return ressult;
}
return writed;
}
nw_int32 nw_fs_close(nw_int32 file_handle)
{
return FS_Close(file_handle);
}
nw_int32 nw_fs_seek(nw_uint32 file_handle, nw_int32 offset, nw_int32 mode)
{
return FS_Seek(file_handle, offset, mode);
}
nw_uint8 nw_fs_file_exist(nw_int8 *file_name)
{
nw_int32 retval = FS_GetAttributes(file_name);
if (retval<FS_NO_ERROR||retval == FS_PATH_NOT_FOUND || retval == FS_FILE_NOT_FOUND)
{
return 0;
}
return 1;
}