MTK HTTP 协议之文件操作

相关系统文件操作封装

 

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;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值