_init

Is a prototype for startup code for a UNIX style library.

Library:LibC
Classification:Other
Service:File and Directory I/O

Syntax

  #include <unistd.h> 
   
  int _init ( void );
  

Return Values

If successful in initializing your library, _init should return 0. Any other value should indicate failure.

Remarks

The _init function should allocate and initialize any data structures or resources that your library needs to do its work. If you write an _init function for initialization, you should also write a _fini function to prepare your library for unloading.

LibC supports four methods for initializing a library; they should not be mixed. For more information, see Section 12.2, Available Approaches for Writing a Library.

See Also

Sample Code

Don’t write an _init function if your library is also using a DllMain function.

  static int initted = FALSE;    // a little protection--probably unnecessary
  
  int _init( void ) 
  {
      int err;
  
      if (initted)
          return 0;
  
      gModuleHandle = getnlmhandle();
      if (err=pthread_key_create(&gKey, (void (*)(void *))
          DisposeThrData))
          return err;
  
      initted = TRUE;
   
      return 0;
  }