FreeBASIC  0.91.0
dev_file_write_wstr.c
Go to the documentation of this file.
1 /* wstring to ascii file writing function */
2 
3 #include "fb.h"
4 
5 int fb_DevFileWriteWstr( FB_FILE *handle, const FB_WCHAR* src, size_t chars )
6 {
7  FILE *fp;
8  char *buffer;
9  int res;
10 
11  FB_LOCK();
12 
13  fp = (FILE*) handle->opaque;
14 
15  if( fp == NULL ) {
16  FB_UNLOCK();
18  }
19 
20  if( chars < FB_LOCALBUFF_MAXLEN )
21  buffer = alloca( chars + 1 );
22  else
23  buffer = malloc( chars + 1 );
24 
25  /* convert to ascii, file should be opened with the ENCODING option
26  to allow UTF characters to be written */
27  fb_wstr_ConvToA( buffer, src, chars );
28 
29  /* do write */
30  res = fwrite( (void *)buffer, 1, chars, fp ) == chars;
31 
32  if( chars >= FB_LOCALBUFF_MAXLEN )
33  free( buffer );
34 
35  FB_UNLOCK();
36 
38 }