Admin | Write | GuestBook
[공지] 해당 블로그에 용건이 있으신 분께서는 http://blog.fore.kr/ 의 방명록(Guestbook)으로 부탁드립니다.
심심하니 fread, fwrite, fseek, ftell 구현. (Windows)
Category : Programming/Programming Talk | URL : | Written by 포레 ( 2012. 10. 21. 19:10 ) | 신고

 

# fread

 

 size_t __cdecl fread( void *buffer, size_t size, size_t count, FILE *stream){
 unsigned long ul_rs = 0; //unsigned long return size
 ReadFile( (HANDLE)_get_osfhandle(stream->_file),
     buffer,
     count*size,
     &ul_rs,
     NULL) );
  return (size_t)ul_rs;
 }

 

 

# fwrite

 

 size_t __cdecl fwrite( void *buffer, size_t size, size_t count, FILE *stream){
 unsigned long ul_rs = 0; //unsigned long return size
 WriteFile( (HANDLE)_get_osfhandle(stream->_file),
    buffer,
    count*size,
    &ul_rs,
    NULL) );
 return (size_t)ul_rs;
 }

 

 

# fseek

 

 #define SEEK_SET FILE_BEGIN
 #define SEEK_CUR FILE_CURRENT
 #define SEEK_END FILE_END

 

 int __cdecl fseek( FILE *stream, long offset, int origin ){
  return (SetFilePointer(_get_osfhandle(stream->_file),offset,origin))0:(int)GetLastError();
 }

 

 

# ftell

 

 int __cdecl ftell(FILE *stream){
  return (int) SetFilePointer(_get_osfhandle(stream->_file),0,FILE_CURRENT);
 }

 

 

 

Category
분류 전체보기 (605)
Notice (6)
Programming (79)
DISKER (1)
FSCH (7)
Caption (0)
Rest Time ! (443)
Hobby (64)
Tour (5)
Blind Post (0)
Recent Post
Recent Comment
Link
Calender
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Total :
Today :
Yesterday :