FreeBASIC  0.91.0
dev_file_encod_read_wstr.c
Go to the documentation of this file.
1 /* UTF-encoded input for file devices */
2 
3 #include "fb.h"
4 
5 int fb_DevFileReadEncodWstr( FB_FILE *handle, FB_WCHAR *dst, size_t *max_chars )
6 {
7  FILE *fp;
8  size_t chars;
9 
10  FB_LOCK();
11 
12  chars = *max_chars;
13 
14  fp = (FILE *)handle->opaque;
15  if( fp == stdout || fp == stderr )
16  fp = stdin;
17 
18  if( fp == NULL )
19  {
20  FB_UNLOCK();
22  }
23 
24  /* do read */
25  chars = fb_hFileRead_UTFToWchar( fp, handle->encod, dst, chars );
26 
27  /* fill with nulls if at eof */
28  if( chars != *max_chars )
29  memset( (char *)&dst[chars], 0, (*max_chars - chars) * sizeof( FB_WCHAR ) );
30 
31  *max_chars = chars;
32 
33  FB_UNLOCK();
34 
35  return fb_ErrorSetNum( FB_RTERROR_OK );
36 }