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

LCOV - code coverage report
Current view: top level - ext/dba - dba_flatfile.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 66 74 89.2 %
Date: 2014-11-10 Functions: 11 11 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 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$ */
      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          36 : DBA_OPEN_FUNC(flatfile)
      43             : {
      44          72 :         info->dbf = pemalloc(sizeof(flatfile), info->flags&DBA_PERSISTENT);
      45          36 :         memset(info->dbf, 0, sizeof(flatfile));
      46             : 
      47          36 :         ((flatfile*)info->dbf)->fp = info->fp;
      48             : 
      49          36 :         return SUCCESS;
      50             : }
      51             : 
      52          36 : DBA_CLOSE_FUNC(flatfile)
      53             : {
      54          36 :         FLATFILE_DATA;
      55             : 
      56          36 :         if (dba->nextkey.dptr) {
      57           0 :                 efree(dba->nextkey.dptr);
      58             :         }
      59          36 :         pefree(dba, info->flags&DBA_PERSISTENT);
      60          36 : }
      61             : 
      62          34 : DBA_FETCH_FUNC(flatfile)
      63             : {
      64             :         datum gval;
      65          34 :         char *new = NULL;
      66             : 
      67          34 :         FLATFILE_DATA;
      68          34 :         FLATFILE_GKEY;
      69             : 
      70          34 :         gval = flatfile_fetch(dba, gkey TSRMLS_CC);
      71          34 :         if (gval.dptr) {
      72          34 :                 if (newlen) {
      73          34 :                         *newlen = gval.dsize;
      74             :                 }
      75          34 :                 new = estrndup(gval.dptr, gval.dsize);
      76          34 :                 efree(gval.dptr);
      77             :         }
      78          34 :         return new;
      79             : }
      80             : 
      81          66 : DBA_UPDATE_FUNC(flatfile)
      82             : {
      83             :         datum gval;
      84             : 
      85          66 :         FLATFILE_DATA;
      86          66 :         FLATFILE_GKEY;
      87          66 :         gval.dptr = (char *) val;
      88          66 :         gval.dsize = vallen;
      89             :         
      90          66 :         switch(flatfile_store(dba, gkey, gval, mode==1 ? FLATFILE_INSERT : FLATFILE_REPLACE TSRMLS_CC)) {
      91             :                 case 0:
      92          62 :                         return SUCCESS;
      93             :                 case 1:
      94           4 :                         return FAILURE;
      95             :                 case -1:
      96           0 :                         php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible");
      97           0 :                         return FAILURE;
      98             :                 default:
      99           0 :                         php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "Unknown return value");
     100           0 :                         return FAILURE;
     101             :         }
     102             : }
     103             : 
     104          41 : DBA_EXISTS_FUNC(flatfile)
     105             : {
     106             :         datum gval;
     107          41 :         FLATFILE_DATA;
     108          41 :         FLATFILE_GKEY;
     109             :         
     110          41 :         gval = flatfile_fetch(dba, gkey TSRMLS_CC);
     111          41 :         if (gval.dptr) {
     112          30 :                 efree(gval.dptr);
     113          30 :                 return SUCCESS;
     114             :         }
     115          11 :         return FAILURE;
     116             : }
     117             : 
     118          14 : DBA_DELETE_FUNC(flatfile)
     119             : {
     120          14 :         FLATFILE_DATA;
     121          14 :         FLATFILE_GKEY;
     122          14 :         return(flatfile_delete(dba, gkey TSRMLS_CC) == -1 ? FAILURE : SUCCESS);
     123             : }
     124             : 
     125          13 : DBA_FIRSTKEY_FUNC(flatfile)
     126             : {
     127          13 :         FLATFILE_DATA;
     128             : 
     129          13 :         if (dba->nextkey.dptr) {
     130           0 :                 efree(dba->nextkey.dptr);
     131             :         }
     132          13 :         dba->nextkey = flatfile_firstkey(dba TSRMLS_CC);
     133          13 :         if (dba->nextkey.dptr) {
     134          13 :                 if (newlen)  {
     135          13 :                         *newlen = dba->nextkey.dsize;
     136             :                 }
     137          13 :                 return estrndup(dba->nextkey.dptr, dba->nextkey.dsize);
     138             :         }
     139           0 :         return NULL;
     140             : }
     141             : 
     142          42 : DBA_NEXTKEY_FUNC(flatfile)
     143             : {
     144          42 :         FLATFILE_DATA;
     145             :         
     146          42 :         if (!dba->nextkey.dptr) {
     147           0 :                 return NULL;
     148             :         }
     149             :         
     150          42 :         if (dba->nextkey.dptr) {
     151          42 :                 efree(dba->nextkey.dptr);
     152             :         }
     153          42 :         dba->nextkey = flatfile_nextkey(dba TSRMLS_CC);
     154          42 :         if (dba->nextkey.dptr) {
     155          29 :                 if (newlen) {
     156          29 :                         *newlen = dba->nextkey.dsize;
     157             :                 }
     158          29 :                 return estrndup(dba->nextkey.dptr, dba->nextkey.dsize);
     159             :         }
     160          13 :         return NULL;
     161             : }
     162             : 
     163           1 : DBA_OPTIMIZE_FUNC(flatfile)
     164             : {
     165             :         /* dummy */
     166           1 :         return SUCCESS;
     167             : }
     168             : 
     169           1 : DBA_SYNC_FUNC(flatfile)
     170             : {
     171             :         /* dummy */
     172           1 :         return SUCCESS;
     173             : }
     174             : 
     175           2 : DBA_INFO_FUNC(flatfile)
     176             : {
     177           2 :         return estrdup(flatfile_version());
     178             : }
     179             : 
     180             : #endif
     181             : 
     182             : /*
     183             :  * Local variables:
     184             :  * tab-width: 4
     185             :  * c-basic-offset: 4
     186             :  * End:
     187             :  * vim600: sw=4 ts=4 fdm=marker
     188             :  * vim<600: sw=4 ts=4
     189             :  */

Generated by: LCOV version 1.10

Generated at Mon, 10 Nov 2014 22:46:37 +0000 (11 days ago)

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