首页 > 代码库 > c 实现IO流
c 实现IO流
// // fs_stream.h // fsnet // // Created by Vincent on 14-5-22. // Copyright (c) 2014年 Vincent. All rights reserved. // #ifndef fsnet_fs_stream_h #define fsnet_fs_stream_h #include "fs_define.h" #define OUTPUT_STRAEM_DEFAULT_MAX 128 struct fs_stream; struct fs_input_stream; struct fs_output_stream; struct fs_output_stream* fs_create_output_stream(size_t len); #define fs_create_output_stream_ext fs_create_output_stream(OUTPUT_STRAEM_DEFAULT_MAX) void fs_stream_free_output( struct fs_output_stream* ); void fs_stream_write_byte( struct fs_output_stream*, BYTE); void fs_stream_write_uint32( struct fs_output_stream*, uint32_t); void fs_stream_write_uint16( struct fs_output_stream*, uint16_t); void fs_stream_write_int32( struct fs_output_stream*, int32_t); void fs_stream_write_int16( struct fs_output_stream*, int16_t); void fs_stream_write_float( struct fs_output_stream*, float ); void fs_stream_write_double( struct fs_output_stream*, double ); void fs_stream_write_data( struct fs_output_stream*, BYTE*, size_t len ); const BYTE* fs_stream_get_dataptr( struct fs_output_stream* ); size_t fs_stream_get_len( struct fs_output_stream* ); size_t fs_stream_output_sub( struct fs_output_stream*, size_t start, size_t len ); struct fs_input_stream* fs_create_input_stream(const BYTE* data, size_t len); struct fs_input_stream* fs_create_input_stream_with_copy(const BYTE* data, size_t len); void fs_input_stream_set_data( struct fs_input_stream*, const BYTE* data, size_t len); void fs_input_stream_set_data_copy( struct fs_input_stream*, const BYTE* data, size_t len); size_t fs_input_stream_get_len( struct fs_input_stream* stream); void fs_input_stream_set_order( struct fs_input_stream*, BYTE order); void fs_stream_free_input( struct fs_input_stream* ); BYTE fs_stream_read_byte( struct fs_input_stream* ); uint32_t fs_stream_read_uint32( struct fs_input_stream* ); uint16_t fs_stream_read_uint16( struct fs_input_stream* ); int32_t fs_stream_read_int32( struct fs_input_stream* ); int16_t fs_stream_read_int16( struct fs_input_stream* ); float fs_stream_read_float( struct fs_input_stream* ); double fs_stream_read_double( struct fs_input_stream* ); size_t fs_stream_read_string( struct fs_input_stream* , char**); void fs_output_stream_set_script_id( struct fs_output_stream* , fs_script_id _id ); fs_script_id fs_output_stream_get_script_id( struct fs_output_stream* ); void fs_input_stream_set_script_id( struct fs_input_stream* , fs_script_id _id ); fs_script_id fs_input_stream_get_script_id( struct fs_input_stream* ); #endif
// // fs_stream.c // fsnet // // Created by Vincent on 14-5-22. // Copyright (c) 2014年 Vincent. All rights reserved. // #include <stdio.h> #include <string.h> #include "fs_define.h" #include "fs_stream.h" #include "fs_malloc.h" #define BASE_STREAM BYTE byte_order; BYTE* data; struct fs_input_stream{ BASE_STREAM size_t pos; size_t len; fs_bool copy; fs_script_id script_id; }; struct fs_output_stream{ BASE_STREAM size_t pos; size_t buff_len; fs_script_id script_id; }; struct fs_output_stream* fs_create_output_stream(size_t len){ struct fs_output_stream* ret = (struct fs_output_stream*)fs_malloc(sizeof(*ret)); fs_zero(ret, sizeof(*ret)); ret->data = http://www.mamicode.com/(BYTE*)fs_malloc(len);>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。