FreeBASIC  0.91.0
dev_file_read.c
Go to the documentation of this file.
1 /* file device */
2 
3 #include "fb.h"
4 
5 int fb_DevFileRead( FB_FILE *handle, void *dst, size_t *pLength )
6 {
7  FILE *fp;
8  size_t rlen, length;
9 
10  FB_LOCK();
11 
12  DBG_ASSERT(pLength!=NULL);
13  length = *pLength;
14 
15  if( handle == NULL )
16  fp = stdin;
17  else
18  {
19  fp = (FILE *)handle->opaque;
20  if( fp == stdout || fp == stderr )
21  fp = stdin;
22 
23  if( fp == NULL )
24  {
25  FB_UNLOCK();
27  }
28  }
29 
30  /* do read */
31  rlen = fread( dst, 1, length, fp );
32  /* fill with nulls if at eof */
33  if( rlen != length )
34  memset( ((char *)dst) + rlen, 0, length - rlen );
35 
36  *pLength = rlen;
37 
38  FB_UNLOCK();
39 
40  return fb_ErrorSetNum( FB_RTERROR_OK );
41 }