FreeBASIC  0.91.0
file_putback_wstr.c
Go to the documentation of this file.
1 /* ungetwc-like function */
2 
3 #include "fb.h"
4 
5 int fb_FilePutBackWstrEx( FB_FILE *handle, const FB_WCHAR *src, size_t chars )
6 {
7  int res;
8  size_t bytes;
9  char *dst;
10 
11  if( !FB_HANDLE_USED(handle) )
13 
14  FB_LOCK();
15 
17 
18  /* UTF? */
19  if( handle->encod != FB_FILE_ENCOD_ASCII )
20  bytes = chars * sizeof( FB_WCHAR );
21  else
22  bytes = chars;
23 
24  if( handle->putback_size + bytes > sizeof(handle->putback_buffer) )
25  {
27  }
28  else
29  {
30  if( handle->putback_size )
31  memmove( handle->putback_buffer + bytes,
32  handle->putback_buffer,
33  handle->putback_size );
34 
35  handle->putback_size += bytes;
36 
37  /* note: if encoding != ASCII, putback buffer will be in
38  wchar format, not in UTF */
39  if( handle->encod != FB_FILE_ENCOD_ASCII )
40  memcpy( handle->putback_buffer, src, bytes );
41  else
42  {
43  /* wchar to char */
44  dst = handle->putback_buffer;
45  while( chars-- > 0 )
46  *dst++ = *src++;
47  }
48  }
49 
50  FB_UNLOCK();
51 
52  return res;
53 }
54 
55 FBCALL int fb_FilePutBackWstr( int fnum, const FB_WCHAR *src, size_t chars )
56 {
57  return fb_FilePutBackWstrEx( FB_FILE_TO_HANDLE(fnum), src, chars );
58 }