PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - dba - dba_flatfile.c
Test: PHP Code Coverage
Date: 2009-11-19 Instrumented lines: 73
Code covered: 83.6 % Executed lines: 61
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | PHP Version 5                                                        |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1997-2009 The PHP Group                                |
       6                 :    +----------------------------------------------------------------------+
       7                 :    | This source file is subject to version 3.01 of the PHP license,      |
       8                 :    | that is bundled with this package in the file LICENSE, and is        |
       9                 :    | available through the world-wide-web at the following url:           |
      10                 :    | http://www.php.net/license/3_01.txt                                  |
      11                 :    | If you did not receive a copy of the PHP license and are unable to   |
      12                 :    | obtain it through the world-wide-web, please send a note to          |
      13                 :    | license@php.net so we can mail you a copy immediately.               |
      14                 :    +----------------------------------------------------------------------+
      15                 :    | Author: Marcus Boerger <helly@php.net>                               |
      16                 :    +----------------------------------------------------------------------+
      17                 :  */
      18                 : 
      19                 : /* $Id: dba_flatfile.c 272374 2008-12-31 11:17:49Z sebastian $ */
      20                 : 
      21                 : #ifdef HAVE_CONFIG_H
      22                 : #include "config.h"
      23                 : #endif
      24                 : 
      25                 : #include "php.h"
      26                 : 
      27                 : #if DBA_FLATFILE
      28                 : #include "php_flatfile.h"
      29                 : 
      30                 : #include "libflatfile/flatfile.h"
      31                 : 
      32                 : #ifdef HAVE_UNISTD_H
      33                 : #include <unistd.h>
      34                 : #endif
      35                 : #include <sys/types.h>
      36                 : #include <sys/stat.h>
      37                 : #include <fcntl.h>
      38                 : 
      39                 : #define FLATFILE_DATA flatfile *dba = info->dbf
      40                 : #define FLATFILE_GKEY datum gkey; gkey.dptr = (char *) key; gkey.dsize = keylen
      41                 : 
      42                 : DBA_OPEN_FUNC(flatfile)
      43              28 : {
      44              28 :         info->dbf = pemalloc(sizeof(flatfile), info->flags&DBA_PERSISTENT);
      45              28 :         memset(info->dbf, 0, sizeof(flatfile));
      46                 : 
      47              28 :         ((flatfile*)info->dbf)->fp = info->fp;
      48                 : 
      49              28 :         return SUCCESS;
      50                 : }
      51                 : 
      52                 : DBA_CLOSE_FUNC(flatfile)
      53              28 : {
      54              28 :         FLATFILE_DATA;
      55                 : 
      56              28 :         if (dba->nextkey.dptr) {
      57               0 :                 efree(dba->nextkey.dptr);
      58                 :         }
      59              28 :         pefree(dba, info->flags&DBA_PERSISTENT);
      60              28 : }
      61                 : 
      62                 : DBA_FETCH_FUNC(flatfile)
      63              38 : {
      64                 :         datum gval;
      65              38 :         char *new = NULL;
      66                 : 
      67              38 :         FLATFILE_DATA;
      68              38 :         FLATFILE_GKEY;
      69                 : 
      70              38 :         gval = flatfile_fetch(dba, gkey TSRMLS_CC);
      71              38 :         if (gval.dptr) {
      72              38 :                 if (newlen) {
      73              38 :                         *newlen = gval.dsize;
      74                 :                 }
      75              38 :                 new = estrndup(gval.dptr, gval.dsize);
      76              38 :                 efree(gval.dptr);
      77                 :         }
      78              38 :         return new;
      79                 : }
      80                 : 
      81                 : DBA_UPDATE_FUNC(flatfile)
      82              58 : {
      83                 :         datum gval;
      84                 : 
      85              58 :         FLATFILE_DATA;
      86              58 :         FLATFILE_GKEY;
      87              58 :         gval.dptr = (char *) val;
      88              58 :         gval.dsize = vallen;
      89                 :         
      90              58 :         switch(flatfile_store(dba, gkey, gval, mode==1 ? FLATFILE_INSERT : FLATFILE_REPLACE TSRMLS_CC)) {
      91                 :         case -1:
      92               0 :                 php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible");
      93               0 :                 return FAILURE;
      94                 :         default:
      95                 :         case 0:
      96              54 :                 return SUCCESS;
      97                 :         case 1:
      98               4 :                 php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Key already exists");
      99               4 :                 return SUCCESS;
     100                 :         }
     101                 : }
     102                 : 
     103                 : DBA_EXISTS_FUNC(flatfile)
     104              30 : {
     105                 :         datum gval;
     106              30 :         FLATFILE_DATA;
     107              30 :         FLATFILE_GKEY;
     108                 :         
     109              30 :         gval = flatfile_fetch(dba, gkey TSRMLS_CC);
     110              30 :         if (gval.dptr) {
     111              20 :                 efree(gval.dptr);
     112              20 :                 return SUCCESS;
     113                 :         }
     114              10 :         return FAILURE;
     115                 : }
     116                 : 
     117                 : DBA_DELETE_FUNC(flatfile)
     118              14 : {
     119              14 :         FLATFILE_DATA;
     120              14 :         FLATFILE_GKEY;
     121              14 :         return(flatfile_delete(dba, gkey TSRMLS_CC) == -1 ? FAILURE : SUCCESS);
     122                 : }
     123                 : 
     124                 : DBA_FIRSTKEY_FUNC(flatfile)
     125              10 : {
     126              10 :         FLATFILE_DATA;
     127                 : 
     128              10 :         if (dba->nextkey.dptr) {
     129               0 :                 efree(dba->nextkey.dptr);
     130                 :         }
     131              10 :         dba->nextkey = flatfile_firstkey(dba TSRMLS_CC);
     132              10 :         if (dba->nextkey.dptr) {
     133              10 :                 if (newlen)  {
     134              10 :                         *newlen = dba->nextkey.dsize;
     135                 :                 }
     136              10 :                 return estrndup(dba->nextkey.dptr, dba->nextkey.dsize);
     137                 :         }
     138               0 :         return NULL;
     139                 : }
     140                 : 
     141                 : DBA_NEXTKEY_FUNC(flatfile)
     142              32 : {
     143              32 :         FLATFILE_DATA;
     144                 :         
     145              32 :         if (!dba->nextkey.dptr) {
     146               0 :                 return NULL;
     147                 :         }
     148                 :         
     149              32 :         if (dba->nextkey.dptr) {
     150              32 :                 efree(dba->nextkey.dptr);
     151                 :         }
     152              32 :         dba->nextkey = flatfile_nextkey(dba TSRMLS_CC);
     153              32 :         if (dba->nextkey.dptr) {
     154              22 :                 if (newlen) {
     155              22 :                         *newlen = dba->nextkey.dsize;
     156                 :                 }
     157              22 :                 return estrndup(dba->nextkey.dptr, dba->nextkey.dsize);
     158                 :         }
     159              10 :         return NULL;
     160                 : }
     161                 : 
     162                 : DBA_OPTIMIZE_FUNC(flatfile)
     163               0 : {
     164                 :         /* dummy */
     165               0 :         return SUCCESS;
     166                 : }
     167                 : 
     168                 : DBA_SYNC_FUNC(flatfile)
     169               0 : {
     170                 :         /* dummy */
     171               0 :         return SUCCESS;
     172                 : }
     173                 : 
     174                 : DBA_INFO_FUNC(flatfile)
     175               0 : {
     176               0 :         return estrdup(flatfile_version());
     177                 : }
     178                 : 
     179                 : #endif
     180                 : 
     181                 : /*
     182                 :  * Local variables:
     183                 :  * tab-width: 4
     184                 :  * c-basic-offset: 4
     185                 :  * End:
     186                 :  * vim600: sw=4 ts=4 fdm=marker
     187                 :  * vim<600: sw=4 ts=4
     188                 :  */

Generated by: LTP GCOV extension version 1.5

Generated at Thu, 19 Nov 2009 08:20:06 +0000 (5 days ago)

Copyright © 2005-2009 The PHP Group
All rights reserved.