Home | History | Annotate | Download | only in io
      1 /*
      2 ******************************************************************************
      3 *                                                                            *
      4 * Copyright (C) 2001-2011, International Business Machines                   *
      5 *                Corporation and others. All Rights Reserved.                *
      6 *                                                                            *
      7 ******************************************************************************
      8 *   file name:  ucln_io.c
      9 *   encoding:   US-ASCII
     10 *   tab size:   8 (not used)
     11 *   indentation:4
     12 *
     13 *   created on: 2006August11
     14 *   created by: George Rhoten
     15 */
     16 
     17 #include "ucln.h"
     18 #include "ucln_io.h"
     19 #include "umutex.h"
     20 #include "uassert.h"
     21 
     22 #ifndef U_IO_IMPLEMENTATION
     23 #error U_IO_IMPLEMENTATION not set - must be set for all ICU source files in io/ - see http://userguide.icu-project.org/howtouseicu
     24 #endif
     25 
     26 
     27 /**  Auto-client */
     28 #define UCLN_TYPE UCLN_IO
     29 #include "ucln_imp.h"
     30 
     31 /* Leave this copyright notice here! It needs to go somewhere in this library. */
     32 static const char copyright[] = U_COPYRIGHT_STRING;
     33 
     34 static cleanupFunc *gCleanupFunctions[UCLN_IO_COUNT];
     35 
     36 static UBool io_cleanup(void)
     37 {
     38     ECleanupIOType libType = UCLN_IO_START;
     39 
     40     while (++libType<UCLN_IO_COUNT) {
     41         if (gCleanupFunctions[libType])
     42         {
     43             gCleanupFunctions[libType]();
     44             gCleanupFunctions[libType] = NULL;
     45         }
     46     }
     47 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
     48     ucln_unRegisterAutomaticCleanup();
     49 #endif
     50     return TRUE;
     51 }
     52 
     53 void ucln_io_registerCleanup(ECleanupIOType type,
     54                                cleanupFunc *func)
     55 {
     56     U_ASSERT(UCLN_IO_START < type && type < UCLN_IO_COUNT);
     57     ucln_registerCleanup(UCLN_IO, io_cleanup);
     58     if (UCLN_IO_START < type && type < UCLN_IO_COUNT)
     59     {
     60         gCleanupFunctions[type] = func;
     61     }
     62 
     63 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
     64     ucln_registerAutomaticCleanup();
     65 #endif
     66 }
     67 
     68