LCOV - code coverage report
Current view: top level - src - pdf-global.c (source / functions) Hit Total Coverage
Test: libgnupdf.info Lines: 14 20 70.0 %
Date: 2011-12-09 Functions: 2 2 100.0 %
Branches: 7 14 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- mode: C -*-
       2                 :            :  *
       3                 :            :  *       File:         pdf-global.c
       4                 :            :  *       Date:         Thu Jul  5 21:07:10 2007
       5                 :            :  *
       6                 :            :  *       GNU PDF Library - Global code
       7                 :            :  *
       8                 :            :  */
       9                 :            : 
      10                 :            : /* Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. */
      11                 :            : 
      12                 :            : /* This program is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU General Public License as published by
      14                 :            :  * the Free Software Foundation, either version 3 of the License, or
      15                 :            :  * (at your option) any later version.
      16                 :            :  *
      17                 :            :  * This program is distributed in the hope that it will be useful,
      18                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      19                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      20                 :            :  * GNU General Public License for more details.
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU General Public License
      23                 :            :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      24                 :            :  */
      25                 :            : 
      26                 :            : #include <config.h>
      27                 :            : 
      28                 :            : #include <string.h>
      29                 :            : #include <pthread.h>
      30                 :            : #include <pdf-global.h>
      31                 :            : #include <pdf-types.h>
      32                 :            : #include <pdf-crypt.h>
      33                 :            : #include <pdf-text.h>
      34                 :            : #include <pdf-time.h>
      35                 :            : #include <pdf-fsys.h>
      36                 :            : #include <pdf-tokeniser.h>
      37                 :            : 
      38                 :            : /* Global variables */
      39                 :            : 
      40                 :            : const pdf_char_t *pdf_library_name = "libgnupdf";
      41                 :            : const pdf_char_t *pdf_version = "0.1";
      42                 :            : 
      43                 :            : /* This structure contains global data used by the library. A variable
      44                 :            :    of this type, called `pdf_globals', is defined in pdf.c. The
      45                 :            :    contents of this structure are initialized in the `pdf_init'
      46                 :            :    function. */
      47                 :            : struct pdf_globals_s
      48                 :            : {
      49                 :            :   pdf_bool_t initialized;
      50                 :            :   pthread_mutex_t init_mutex;
      51                 :            : };
      52                 :            : 
      53                 :            : /* General library context */
      54                 :            : static struct pdf_globals_s pdf_globals = {
      55                 :            :   PDF_FALSE,
      56                 :            :   PTHREAD_MUTEX_INITIALIZER
      57                 :            : };
      58                 :            : 
      59                 :            : /* Library initialization routine */
      60                 :            : pdf_bool_t
      61                 :        745 : pdf_init (pdf_error_t **error)
      62                 :            : {
      63                 :            :   pdf_bool_t initialized;
      64                 :            : 
      65         [ -  + ]:        745 :   if (pthread_mutex_lock (&(pdf_globals.init_mutex)) != 0)
      66                 :            :     {
      67                 :          0 :       pdf_set_error (error,
      68                 :            :                      PDF_EDOMAIN_GLOBAL,
      69                 :            :                      PDF_ERROR,
      70                 :            :                      "cannot ensure library initialization: "
      71                 :            :                      "unable to lock mutex");
      72                 :          0 :       return PDF_FALSE;
      73                 :            :     }
      74                 :            : 
      75                 :            :   /* The mutex is locked within this brace. NO "return" statements allowed
      76                 :            :    * from within this block as they will leave the mutex locked and set us
      77                 :            :    * up for a deadlock.
      78                 :            :    */
      79         [ -  + ]:        745 :   if (pdf_globals.initialized)
      80                 :          0 :     initialized = PDF_TRUE;
      81                 :            :   else
      82                 :            :     {
      83                 :        745 :       pdf_error_t *inner_error = NULL;
      84                 :            : 
      85 [ +  - ][ +  - ]:        745 :       if (!pdf_crypt_init (&inner_error) ||
         [ +  - ][ +  - ]
                 [ -  + ]
      86                 :            :           !pdf_text_init (&inner_error) ||
      87                 :            :           !pdf_time_module_init (&inner_error) ||
      88                 :            :           !pdf_fsys_init (&inner_error) ||
      89                 :            :           !pdf_tokeniser_init (&inner_error))
      90                 :            :         {
      91                 :          0 :           pdf_propagate_error (error, inner_error);
      92                 :          0 :           pdf_prefix_error (error,
      93                 :            :                             "cannot ensure library initialization: ");
      94                 :          0 :           initialized = PDF_FALSE;
      95                 :            :         }
      96                 :            :       else
      97                 :            :         {
      98                 :        745 :           initialized = PDF_TRUE;
      99                 :        745 :           pdf_globals.initialized = PDF_TRUE;
     100                 :            :         }
     101                 :            :     }
     102                 :            : 
     103                 :        745 :   pthread_mutex_unlock (&(pdf_globals.init_mutex));
     104                 :            : 
     105                 :        745 :   return initialized;
     106                 :            : }
     107                 :            : 
     108                 :            : /* Library finalization routine */
     109                 :            : void
     110                 :        745 : pdf_finish (void)
     111                 :            : {
     112                 :        745 :   pdf_tokeniser_deinit ();
     113                 :        745 :   pdf_fsys_deinit ();
     114                 :        745 :   pdf_text_deinit ();
     115                 :        745 : }
     116                 :            : 
     117                 :            : /* End of pdf-global.c */

Generated by: LCOV version 1.8