ת»»Ϊgb2312±àÂë
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
/*
|
||||
|
||||
C语言库函数实现
|
||||
C<EFBFBD><EFBFBD><EFBFBD>Կ⺯<EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>
|
||||
|
||||
*/
|
||||
|
||||
@@ -21,19 +21,19 @@
|
||||
|
||||
|
||||
|
||||
// 常规文件
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
#define FILE_TYPE_FILE 0
|
||||
// 设备文件
|
||||
// <EFBFBD>豸<EFBFBD>ļ<EFBFBD>
|
||||
#define FILE_TYPE_DEVICE 1
|
||||
// 内存文件
|
||||
// <EFBFBD>ڴ<EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
#define FILE_TYPE_MEM 2
|
||||
|
||||
// 定义内存文件大小
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>С
|
||||
#define MEM_FILE_SIZE (100*1024)
|
||||
|
||||
|
||||
|
||||
// 定义flash中的文件
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>flash<EFBFBD>е<EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
typedef struct
|
||||
{
|
||||
u32 addr;
|
||||
@@ -42,7 +42,7 @@ typedef struct
|
||||
}libc_flash_file;
|
||||
|
||||
|
||||
// 定义常规文件
|
||||
// <EFBFBD><EFBFBD><EFBFBD>峣<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
typedef struct
|
||||
{
|
||||
libc_flash_file flash;
|
||||
@@ -55,7 +55,7 @@ typedef struct
|
||||
|
||||
|
||||
|
||||
// 定义内存文件
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
typedef struct
|
||||
{
|
||||
uint8_t data[MEM_FILE_SIZE];
|
||||
@@ -65,7 +65,7 @@ typedef struct
|
||||
|
||||
|
||||
|
||||
// 定义文件结构体
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>ṹ<EFBFBD><EFBFBD>
|
||||
struct __FILE
|
||||
{
|
||||
int type;
|
||||
@@ -74,7 +74,7 @@ struct __FILE
|
||||
libc_mem_file *mem;
|
||||
};
|
||||
|
||||
// 寻找指定名称的设备
|
||||
// Ѱ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>豸
|
||||
extern const unsigned int Load$$libc_dev$$Base;
|
||||
extern const unsigned int Load$$libc_dev$$Limit;
|
||||
const libc_device_file *libc_find_dev(const char *name)
|
||||
@@ -93,7 +93,7 @@ const libc_device_file *libc_find_dev(const char *name)
|
||||
|
||||
|
||||
|
||||
// 基本输入输出流
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
FILE __stdin={
|
||||
.type=FILE_TYPE_DEVICE,
|
||||
.dev=0,
|
||||
@@ -126,7 +126,7 @@ static int libc_init(void)
|
||||
|
||||
|
||||
|
||||
// 删除文件,返回0成功
|
||||
// ɾ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD>ɹ<EFBFBD>
|
||||
int remove(const char * filename)
|
||||
{
|
||||
if (f_unlink(filename)==FR_OK)
|
||||
@@ -137,7 +137,7 @@ int remove(const char * filename)
|
||||
|
||||
|
||||
|
||||
//重命名,返回0成功
|
||||
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD>ɹ<EFBFBD>
|
||||
int rename(const char * old_, const char * new_)
|
||||
{
|
||||
if (f_rename (old_,new_)==FR_OK)
|
||||
@@ -147,7 +147,7 @@ int rename(const char * old_, const char * new_)
|
||||
}
|
||||
|
||||
|
||||
// 在指定流上创建临时文件
|
||||
// <EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ļ<EFBFBD>
|
||||
static FILE *tmpfile_s(FILE * stream)
|
||||
{
|
||||
FILE *file=stream;
|
||||
@@ -160,21 +160,21 @@ static FILE *tmpfile_s(FILE * stream)
|
||||
return file;
|
||||
}
|
||||
|
||||
// 创建临时文件,在文件关闭时自动删除
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>ر<EFBFBD>ʱ<EFBFBD>Զ<EFBFBD>ɾ<EFBFBD><EFBFBD>
|
||||
FILE *tmpfile(void)
|
||||
{
|
||||
return tmpfile_s(NULL);
|
||||
}
|
||||
|
||||
|
||||
// 返回一个和现有文件名不同的字符串,这里始终返回 NULL
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>շ<EFBFBD><EFBFBD><EFBFBD> NULL
|
||||
char *tmpnam(char * s)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// 关闭文件,返回0成功
|
||||
// <EFBFBD>ر<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD>ɹ<EFBFBD>
|
||||
int fclose(FILE * stream)
|
||||
{
|
||||
FILE * file=stream;
|
||||
@@ -200,12 +200,12 @@ int fclose(FILE * stream)
|
||||
}
|
||||
if((file!=stdin)&&(file!=stdout)&&(file!=stderr))
|
||||
{
|
||||
// 基本输入输出流使用的是静态内存
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD><EFBFBD>Ǿ<EFBFBD>̬<EFBFBD>ڴ<EFBFBD>
|
||||
free(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 设置为初始流设备
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>豸
|
||||
// freopen("uart5","r+",file);
|
||||
}
|
||||
return 0;
|
||||
@@ -214,7 +214,7 @@ int fclose(FILE * stream)
|
||||
}
|
||||
|
||||
|
||||
// 刷新,返回0成功
|
||||
// ˢ<EFBFBD>£<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD>ɹ<EFBFBD>
|
||||
int fflush(FILE * stream)
|
||||
{
|
||||
return 0;
|
||||
@@ -227,7 +227,7 @@ int ferror(FILE * stream)
|
||||
|
||||
|
||||
|
||||
// 由字符得到打开类型
|
||||
// <EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
static BYTE f_get_mode(const char *mode)
|
||||
{
|
||||
typedef struct{
|
||||
@@ -262,7 +262,7 @@ static BYTE f_get_mode(const char *mode)
|
||||
|
||||
|
||||
|
||||
// 在指定流上打开文件
|
||||
// <EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
static FILE *fopen_s(const char * filename,const char * mode,FILE *stream)
|
||||
{
|
||||
FILE *file=stream;
|
||||
@@ -271,7 +271,7 @@ static FILE *fopen_s(const char * filename,const char * mode,FILE *stream)
|
||||
file_struct_private *file_p=NULL;
|
||||
u8 ret=0;
|
||||
|
||||
// 首先查找同名设备
|
||||
// <EFBFBD><EFBFBD><EFBFBD>Ȳ<EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD>豸
|
||||
file->type=FILE_TYPE_DEVICE;
|
||||
file->dev=libc_find_dev(filename);
|
||||
if(file->dev!=NULL)
|
||||
@@ -317,26 +317,26 @@ static FILE *fopen_s(const char * filename,const char * mode,FILE *stream)
|
||||
}
|
||||
|
||||
|
||||
// 打开文件
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
FILE *fopen(const char * filename,const char * mode)
|
||||
{
|
||||
return fopen_s(filename,mode,NULL);
|
||||
}
|
||||
|
||||
// 把新的文件名和流关联,输出新的流
|
||||
// 如果filename==NULL,则创建一个内存文件
|
||||
// <EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD>
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>filename==NULL<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
FILE *freopen(const char * filename, const char * mode, FILE * stream)
|
||||
{
|
||||
FILE * file=stream;
|
||||
if(file==NULL) return NULL;
|
||||
|
||||
// 在本例中只允许修改基本输入输出流
|
||||
// <EFBFBD>ڱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if((file!=stdin)&&(file!=stdout)&&(file!=stderr)) return NULL;
|
||||
|
||||
// 首先尝试关闭与流关联的文件
|
||||
// <EFBFBD><EFBFBD><EFBFBD>ȳ<EFBFBD><EFBFBD>Թر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
fclose(stream);
|
||||
|
||||
// 把新文件关联到流
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(filename!=NULL)
|
||||
return fopen_s(filename,mode,stream);
|
||||
else
|
||||
@@ -344,7 +344,7 @@ FILE *freopen(const char * filename, const char * mode, FILE * stream)
|
||||
}
|
||||
|
||||
|
||||
// 设置缓冲区,返回0成功
|
||||
// <EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD>ɹ<EFBFBD>
|
||||
int setvbuf(FILE * stream, char * buf, int mode, size_t size)
|
||||
{
|
||||
return 0;
|
||||
@@ -360,7 +360,7 @@ void setbuf(FILE * stream,char * buf)
|
||||
|
||||
|
||||
|
||||
// 设备文件获取一个字符
|
||||
// <EFBFBD>豸<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ȡһ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
static int fgetc_dev(FILE * stream)
|
||||
{
|
||||
int c=EOF;
|
||||
@@ -376,7 +376,7 @@ static int fgetc_dev(FILE * stream)
|
||||
return c;
|
||||
}
|
||||
|
||||
// 内存文件获取一个字符
|
||||
// <EFBFBD>ڴ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ȡһ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
static int fgetc_mem(FILE * stream)
|
||||
{
|
||||
int c=EOF;
|
||||
@@ -393,7 +393,7 @@ static int fgetc_mem(FILE * stream)
|
||||
return c;
|
||||
}
|
||||
|
||||
// 普通文件获取一个字符
|
||||
// <EFBFBD><EFBFBD>ͨ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ȡһ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
static int fgetc_fil(FILE * stream)
|
||||
{
|
||||
int c=EOF;
|
||||
@@ -410,7 +410,7 @@ static int (*const g_getc_funs[3])(FILE *)={
|
||||
};
|
||||
|
||||
|
||||
// 获取文件流中的一个字符
|
||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
int fgetc(FILE * stream)
|
||||
{
|
||||
int c=EOF;
|
||||
@@ -425,7 +425,7 @@ int fgetc(FILE * stream)
|
||||
|
||||
|
||||
|
||||
// 设备文件写入一个字符
|
||||
// <EFBFBD>豸<EFBFBD>ļ<EFBFBD>д<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
static int fputc_dev(int c,FILE * stream)
|
||||
{
|
||||
const libc_device_file *dev=stream->dev;
|
||||
@@ -440,7 +440,7 @@ static int fputc_dev(int c,FILE * stream)
|
||||
return EOF;
|
||||
}
|
||||
|
||||
// 内存文件写入一个字符
|
||||
// <EFBFBD>ڴ<EFBFBD><EFBFBD>ļ<EFBFBD>д<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
static int fputc_mem(int c,FILE * stream)
|
||||
{
|
||||
libc_mem_file *mem=stream->mem;
|
||||
@@ -456,7 +456,7 @@ static int fputc_mem(int c,FILE * stream)
|
||||
return EOF;
|
||||
}
|
||||
|
||||
// 普通文件写入一个字符
|
||||
// <EFBFBD><EFBFBD>ͨ<EFBFBD>ļ<EFBFBD>д<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
static int fputc_fil(int c,FILE * stream)
|
||||
{
|
||||
uint8_t d=c;
|
||||
@@ -473,7 +473,7 @@ static int (*const g_putc_funs[3])(int,FILE *)={
|
||||
};
|
||||
|
||||
|
||||
// 写入一个字符
|
||||
// д<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
int fputc(int c, FILE * stream)
|
||||
{
|
||||
if(stream)
|
||||
@@ -484,7 +484,7 @@ int fputc(int c, FILE * stream)
|
||||
}
|
||||
|
||||
|
||||
// 普通文件读取
|
||||
// <EFBFBD><EFBFBD>ͨ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ȡ
|
||||
static size_t fread_fil(void * ptr, size_t size, size_t nmemb, FILE * stream)
|
||||
{
|
||||
file_struct_private * file=stream->ptr;
|
||||
@@ -509,27 +509,27 @@ static size_t fread_fil(void * ptr, size_t size, size_t nmemb, FILE * stream)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 设备文件读取
|
||||
// <EFBFBD>豸<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ȡ
|
||||
static size_t fread_dev(void * ptr, size_t size, size_t nmemb, FILE * stream)
|
||||
{
|
||||
const libc_device_file *dev=stream->dev;
|
||||
|
||||
if(dev)
|
||||
{
|
||||
// 暂时不支持设备文件读取
|
||||
// <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ȡ
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 内存文件读取
|
||||
// <EFBFBD>ڴ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ȡ
|
||||
static size_t fread_mem(void * ptr, size_t size, size_t nmemb, FILE * stream)
|
||||
{
|
||||
libc_mem_file *mem=stream->mem;
|
||||
|
||||
if(mem)
|
||||
{
|
||||
// 暂时不支持内存文件读取
|
||||
// <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ȡ
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -542,7 +542,7 @@ static size_t (*const g_read_funs[3])(void *,size_t,size_t,FILE *)={
|
||||
fread_mem,
|
||||
};
|
||||
|
||||
// 读取文件
|
||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD>
|
||||
size_t fread(void * ptr, size_t size, size_t nmemb, FILE * stream)
|
||||
{
|
||||
if(stream)
|
||||
@@ -557,7 +557,7 @@ size_t fread(void * ptr, size_t size, size_t nmemb, FILE * stream)
|
||||
|
||||
|
||||
|
||||
// 设备文件写入
|
||||
// <EFBFBD>豸<EFBFBD>ļ<EFBFBD>д<EFBFBD><EFBFBD>
|
||||
static size_t fwrite_dev(const void * ptr, size_t size, size_t nmemb, FILE * stream)
|
||||
{
|
||||
const libc_device_file *dev=stream->dev;
|
||||
@@ -573,20 +573,20 @@ static size_t fwrite_dev(const void * ptr, size_t size, size_t nmemb, FILE * str
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 内存文件写入
|
||||
// <EFBFBD>ڴ<EFBFBD><EFBFBD>ļ<EFBFBD>д<EFBFBD><EFBFBD>
|
||||
static size_t fwrite_mem(const void * ptr, size_t size, size_t nmemb, FILE * stream)
|
||||
{
|
||||
libc_mem_file *mem=stream->mem;
|
||||
|
||||
if(mem)
|
||||
{
|
||||
// 暂时不支持内存文件写入
|
||||
// <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ļ<EFBFBD>д<EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 普通文件写入
|
||||
// <EFBFBD><EFBFBD>ͨ<EFBFBD>ļ<EFBFBD>д<EFBFBD><EFBFBD>
|
||||
static size_t fwrite_fil(const void * ptr, size_t size, size_t nmemb, FILE * stream)
|
||||
{
|
||||
file_struct_private * file=stream->ptr;
|
||||
@@ -600,7 +600,7 @@ static size_t fwrite_fil(const void * ptr, size_t size, size_t nmemb, FILE * str
|
||||
}
|
||||
else
|
||||
{
|
||||
//flash暂时不支持写入
|
||||
//flash<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -615,7 +615,7 @@ static size_t (*const g_write_funs[3])(const void *,size_t,size_t,FILE *)={
|
||||
};
|
||||
|
||||
|
||||
// 写入文件
|
||||
// д<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
size_t fwrite(const void * ptr, size_t size, size_t nmemb, FILE * stream)
|
||||
{
|
||||
if(stream)
|
||||
@@ -626,13 +626,13 @@ size_t fwrite(const void * ptr, size_t size, size_t nmemb, FILE * stream)
|
||||
}
|
||||
|
||||
|
||||
// 获取文件位置,成功返回0
|
||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD>λ<EFBFBD>ã<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
||||
int fgetpos(FILE * stream, fpos_t *pos)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 设置文件位置,成功返回0
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>λ<EFBFBD>ã<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
||||
int fsetpos(FILE * stream, const fpos_t * pos)
|
||||
{
|
||||
return 1;
|
||||
@@ -643,7 +643,7 @@ int fsetpos(FILE * stream, const fpos_t * pos)
|
||||
|
||||
|
||||
|
||||
// 普通文件设置文件偏移,成功返回0
|
||||
// <EFBFBD><EFBFBD>ͨ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ƫ<EFBFBD>ƣ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
||||
static int fseek_fil(FILE * stream, long int offset, int whence)
|
||||
{
|
||||
file_struct_private * file=stream->ptr;
|
||||
@@ -651,7 +651,7 @@ static int fseek_fil(FILE * stream, long int offset, int whence)
|
||||
{
|
||||
if (file->flash.size==0)
|
||||
{
|
||||
//文件开头
|
||||
//<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ͷ
|
||||
if (SEEK_SET==whence)
|
||||
{
|
||||
if (f_lseek(&file->file,offset)==FR_OK)
|
||||
@@ -659,14 +659,14 @@ static int fseek_fil(FILE * stream, long int offset, int whence)
|
||||
}
|
||||
else if (SEEK_END==whence)
|
||||
{
|
||||
//这时offset为负数
|
||||
//<EFBFBD><EFBFBD>ʱoffsetΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
offset=file->file_info.fsize+offset;
|
||||
if (f_lseek(&file->file,offset)==FR_OK)
|
||||
return 0;
|
||||
}
|
||||
else if (SEEK_CUR==whence)
|
||||
{
|
||||
//这时offset可正可负
|
||||
//<EFBFBD><EFBFBD>ʱoffset<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɸ<EFBFBD>
|
||||
long int pos=f_tell(&file->file);
|
||||
offset=pos+offset;
|
||||
if (f_lseek(&file->file,offset)==FR_OK)
|
||||
@@ -675,7 +675,7 @@ static int fseek_fil(FILE * stream, long int offset, int whence)
|
||||
}
|
||||
else
|
||||
{
|
||||
//文件开头
|
||||
//<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ͷ
|
||||
if (SEEK_SET==whence)
|
||||
{
|
||||
if(offset>=0&&offset<=file->flash.size)
|
||||
@@ -695,7 +695,7 @@ static int fseek_fil(FILE * stream, long int offset, int whence)
|
||||
}
|
||||
else if (SEEK_CUR==whence)
|
||||
{
|
||||
//这时offset可正可负
|
||||
//<EFBFBD><EFBFBD>ʱoffset<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɸ<EFBFBD>
|
||||
long int pos=file->flash.ptr;
|
||||
offset=pos+offset;
|
||||
if(offset>=0&&offset<=file->flash.size)
|
||||
@@ -709,7 +709,7 @@ static int fseek_fil(FILE * stream, long int offset, int whence)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 设备文件设置文件偏移,成功返回0
|
||||
// <EFBFBD>豸<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ƫ<EFBFBD>ƣ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
||||
static int fseek_dev(FILE * stream, long int offset, int whence)
|
||||
{
|
||||
const libc_device_file *dev=stream->dev;
|
||||
@@ -721,14 +721,14 @@ static int fseek_dev(FILE * stream, long int offset, int whence)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 内存文件设置文件偏移,成功返回0
|
||||
// <EFBFBD>ڴ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ƫ<EFBFBD>ƣ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
||||
static int fseek_mem(FILE * stream, long int offset, int whence)
|
||||
{
|
||||
libc_mem_file *mem=stream->mem;
|
||||
|
||||
if(mem)
|
||||
{
|
||||
//文件开头
|
||||
//<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ͷ
|
||||
if (SEEK_SET==whence)
|
||||
{
|
||||
if(offset>=0&&offset<=mem->size)
|
||||
@@ -748,7 +748,7 @@ static int fseek_mem(FILE * stream, long int offset, int whence)
|
||||
}
|
||||
else if (SEEK_CUR==whence)
|
||||
{
|
||||
//这时offset可正可负
|
||||
//<EFBFBD><EFBFBD>ʱoffset<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɸ<EFBFBD>
|
||||
long int pos=mem->ptr;
|
||||
offset=pos+offset;
|
||||
if(offset>=0&&offset<=mem->size)
|
||||
@@ -768,7 +768,7 @@ static int (*const g_seek_funs[3])(FILE *,long int,int)={
|
||||
fseek_mem,
|
||||
};
|
||||
|
||||
// 设置文件偏移,成功返回0
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ƫ<EFBFBD>ƣ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
||||
int fseek(FILE * stream, long int offset, int whence)
|
||||
{
|
||||
if(stream)
|
||||
@@ -779,7 +779,7 @@ int fseek(FILE * stream, long int offset, int whence)
|
||||
}
|
||||
|
||||
|
||||
// 返回文件指针偏移
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ָ<EFBFBD><EFBFBD>ƫ<EFBFBD><EFBFBD>
|
||||
static long int ftell_fil(FILE * stream)
|
||||
{
|
||||
file_struct_private * file=stream->ptr;
|
||||
@@ -797,7 +797,7 @@ static long int ftell_fil(FILE * stream)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 返回文件指针偏移
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ָ<EFBFBD><EFBFBD>ƫ<EFBFBD><EFBFBD>
|
||||
static long int ftell_dev(FILE * stream)
|
||||
{
|
||||
const libc_device_file *dev=stream->dev;
|
||||
@@ -805,7 +805,7 @@ static long int ftell_dev(FILE * stream)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 返回文件指针偏移
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ָ<EFBFBD><EFBFBD>ƫ<EFBFBD><EFBFBD>
|
||||
static long int ftell_mem(FILE * stream)
|
||||
{
|
||||
libc_mem_file *mem=stream->mem;
|
||||
@@ -822,7 +822,7 @@ static long int (*const g_tell_funs[3])(FILE *)={
|
||||
};
|
||||
|
||||
|
||||
// 返回文件指针偏移
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ָ<EFBFBD><EFBFBD>ƫ<EFBFBD><EFBFBD>
|
||||
long int ftell(FILE * stream)
|
||||
{
|
||||
if(stream)
|
||||
@@ -833,14 +833,14 @@ long int ftell(FILE * stream)
|
||||
}
|
||||
|
||||
|
||||
// 把文件指针设置为文件开头
|
||||
// <EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ͷ
|
||||
void rewind(FILE * stream)
|
||||
{
|
||||
fseek(stream, 0L, SEEK_SET);
|
||||
}
|
||||
|
||||
|
||||
// 测试文件结束,未结束返回0,已结束返回1
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><EFBFBD><EFBFBD>ѽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
||||
static int feof_fil(FILE * stream)
|
||||
{
|
||||
file_struct_private * file=stream->ptr;
|
||||
@@ -858,7 +858,7 @@ static int feof_fil(FILE * stream)
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
// 测试文件结束,未结束返回0,已结束返回1
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><EFBFBD><EFBFBD>ѽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
||||
static int feof_dev(FILE * stream)
|
||||
{
|
||||
const libc_device_file *dev=stream->dev;
|
||||
@@ -886,7 +886,7 @@ static int (*const g_eof_funs[3])(FILE *)={
|
||||
};
|
||||
|
||||
|
||||
// 测试文件结束,未结束返回0,已结束返回1
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><EFBFBD><EFBFBD>ѽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
||||
int feof(FILE * stream)
|
||||
{
|
||||
if(stream)
|
||||
@@ -896,7 +896,7 @@ int feof(FILE * stream)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 断言,c语言标准库使用这个函数
|
||||
// <EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD>c<EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void __aeabi_assert(const char * e, const char *_file_, int _line_)
|
||||
{
|
||||
printf("%s:%s,at %d\r\n",e,_file_,_line_);
|
||||
|
||||
Reference in New Issue
Block a user