FreeBASIC  0.91.0
init.c
Go to the documentation of this file.
1 /* libfb initialization */
2 
3 #include "fb.h"
4 #include <locale.h>
5 
6 FB_RTLIB_CTX __fb_ctx /* not initialized */;
7 static int __fb_is_inicnt = 0;
8 
9 /* called from fbrt0 */
10 void fb_hRtInit( void )
11 {
12  /* already initialized? */
14  if( __fb_is_inicnt != 1 )
15  return;
16 
17  /* initialize context */
18  memset( &__fb_ctx, 0, sizeof( FB_RTLIB_CTX ) );
19 
20  /* os-dep initialization */
21  fb_hInit( );
22 
23 #ifdef ENABLE_MT
24  fb_TlsInit( );
25 #endif
26 
40  setlocale( LC_CTYPE, "" );
41 
42 }
43 
44 /* called from fbrt0 */
45 void fb_hRtExit( void )
46 {
48  if( __fb_is_inicnt != 0 )
49  return;
50 
51  /* atexit() can't be used because if OPEN is called in a global ctor inside
52  a shared-lib and any other file function is called in the respective global
53  dtor, it would be already reseted - the atexit() chain is called before the
54  global dtors one*/
55  fb_FileReset( );
56 
57  /* os-dep termination */
58  fb_hEnd( 0 );
59 
60 #ifdef ENABLE_MT
61  fb_TlsExit( );
62 #endif
63 
64  /* If an error message was stored, print it now, after the console was
65  cleaned up. At least the DOS gfxlib clears the console on exit,
66  thus any error messages must be printed after that or they would
67  not be visible. */
68  if( __fb_ctx.errmsg )
69  fputs( __fb_ctx.errmsg, stderr );
70 }
71 
72 /* called by FB program */
73 FBCALL void fb_Init( int argc, char **argv, int lang )
74 {
75  __fb_ctx.argc = argc;
76  __fb_ctx.argv = argv;
77  __fb_ctx.lang = lang;
78 }
79 
80 /* called by FB program */
81 FBCALL void fb_End( int errlevel )
82 {
83  exit( errlevel );
84 }