CVS update: php3/functions

From: Date: Mon, 10 May 1999 11:15:03 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-5473@lists.php.net to get a copy of this message
Date: Monday May 10, 1999 @ 7:15 Author: sas Update of /repository/php3/functions In directory php:/tmp/cvs-serv12031/functions Modified Files: dba.c dba_cdb.c dba_db2.c dba_dbm.c dba_gdbm.c dba_ndbm.c php3_dba.h Log Message: - add support for file mode setting - change return type of dba_optimize - case insensitive handler names - use of SUCCESS/FAILURE instead of 1/0 where possible Index: php3/functions/dba.c diff -u php3/functions/dba.c:1.12 php3/functions/dba.c:1.13 --- php3/functions/dba.c:1.12 Sun May 9 14:08:18 1999 +++ php3/functions/dba.c Mon May 10 07:15:02 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dba.c,v 1.12 1999/05/09 18:08:18 sas Exp $ */ +/* $Id: dba.c,v 1.13 1999/05/10 11:15:02 sas Exp $ */ #include "php.h" @@ -81,7 +81,7 @@ int (*delete)(dba_info *, char *, int); char* (*firstkey)(dba_info *, int *); char* (*nextkey)(dba_info *, int *); - void (*optimize)(dba_info *); + int (*optimize)(dba_info *); int (*sync)(dba_info *); } dba_handler; @@ -117,7 +117,7 @@ #define DBA_ID_GET1 DBA_ID_PARS; DBA_GET1; DBA_ID_GET #define DBA_ID_GET2 DBA_ID_PARS; DBA_GET2; DBA_ID_GET -/* a dba handler must have specific routines */ +/* a DBA handler must have specific routines */ #define DBA_HND(x) \ {\ @@ -190,7 +190,7 @@ { dba_handler *hptr; - PUTS("V1 ($Id: dba.c,v 1.12 1999/05/09 18:08:18 sas Exp $)"); + PUTS("V1 ($Id: dba.c,v 1.13 1999/05/10 11:15:02 sas Exp $)"); for(hptr = handler; hptr->name; hptr++) { PUTS(" "); PUTS(hptr->name); @@ -265,7 +265,7 @@ /* this is O(n) and could be improved */ for(hptr = handler; hptr->name && - strcmp(hptr->name, args[2]->value.str.val); hptr++); + strcasecmp(hptr->name, args[2]->value.str.val); hptr++); if(!hptr->name) { efree(args); @@ -321,7 +321,7 @@ /* }}} */ /* }}} */ -/* {{{ proto int dba_popen(string path, string mode, string handlername, ...) +/* {{{ proto int dba_popen(string path, string mode, string handlername[, ...]) opens path using the specified handler in mode persistently */ PHP_FUNCTION(dba_popen) { @@ -329,7 +329,7 @@ } /* }}} */ -/* {{{ proto int dba_open(string path, string mode, string handlername, ...) +/* {{{ proto int dba_open(string path, string mode, string handlername[, ...]) opens path using the specified handler in mode*/ PHP_FUNCTION(dba_open) { @@ -383,7 +383,7 @@ char *fkey; int len; DBA_ID_GET1; - + fkey = info->hnd->firstkey(info, &len); if(fkey) RETURN_STRINGL(fkey, len, 0); @@ -434,23 +434,26 @@ } /* }}} */ -/* {{{ proto void dba_optimize(int handle) +/* {{{ proto bool dba_optimize(int handle) optimizes (e.g. clean up, vacuum) database */ PHP_FUNCTION(dba_optimize) { DBA_ID_GET1; - info->hnd->optimize(info); + if(info->hnd->optimize(info) == SUCCESS) { + RETURN_TRUE; + } + RETURN_FALSE; } /* }}} */ /* {{{ proto bool dba_sync(int handle) - sync database */ + synchronizes database */ PHP_FUNCTION(dba_sync) { DBA_ID_GET1; - if(info->hnd->sync(info)) { + if(info->hnd->sync(info) == SUCCESS) { RETURN_TRUE; } RETURN_FALSE; Index: php3/functions/dba_cdb.c diff -u php3/functions/dba_cdb.c:1.8 php3/functions/dba_cdb.c:1.9 --- php3/functions/dba_cdb.c:1.8 Sun May 9 12:54:34 1999 +++ php3/functions/dba_cdb.c Mon May 10 07:15:02 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dba_cdb.c,v 1.8 1999/05/09 16:54:34 sas Exp $ */ +/* $Id: dba_cdb.c,v 1.9 1999/05/10 11:15:02 sas Exp $ */ #include "php.h" @@ -116,8 +116,8 @@ int len; if(cdb_seek(cdb->fd, key, keylen, &len) == 1) - return 1; - return 0; + return SUCCESS; + return FAILURE; } DBA_DELETE_FUNC(cdb) @@ -208,12 +208,13 @@ DBA_OPTIMIZE_FUNC(cdb) { + return SUCCESS; } DBA_SYNC_FUNC(cdb) { /* this is read-only */ - return 1; + return SUCCESS; } #endif Index: php3/functions/dba_db2.c diff -u php3/functions/dba_db2.c:1.4 php3/functions/dba_db2.c:1.5 --- php3/functions/dba_db2.c:1.4 Sun May 9 16:26:54 1999 +++ php3/functions/dba_db2.c Mon May 10 07:15:02 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dba_db2.c,v 1.4 1999/05/09 20:26:54 jah Exp $ */ +/* $Id: dba_db2.c,v 1.5 1999/05/10 11:15:02 sas Exp $ */ #include "php.h" @@ -35,7 +35,7 @@ #include "php3_db2.h" #include <sys/stat.h> -#include <string.h> +#include <stdlib.h> #if DB2_DB2_DB_H #include <db2/db.h> #elif DB2_DB_DB2_H @@ -62,6 +62,7 @@ DB *dbp; DBTYPE type; int gmode = 0; + int filemode = 0644; struct stat check_stat; type = info->mode == DBA_READER ? DB_UNKNOWN : @@ -74,7 +75,12 @@ if(gmode == -1) return FAILURE; - if(!db_open(info->path, type, gmode, 0644, NULL, NULL, &dbp)) { + if(info->argc > 0) { + convert_to_long(info->argv[0]); + filemode = info->argv[0]->value.lval; + } + + if(!db_open(info->path, type, gmode, filemode, NULL, NULL, &dbp)) { info->dbf = malloc(sizeof(dba_db2_data)); memset(info->dbf, 0, sizeof(dba_db2_data)); ((dba_db2_data *) info->dbf)->dbp = dbp; @@ -120,9 +126,9 @@ if(!dba->dbp->put(dba->dbp, NULL, &gkey, &gval, mode == 1 ? DB_NOOVERWRITE : 0)) { - return 1; + return SUCCESS; } - return 0; + return FAILURE; } DBA_EXISTS_FUNC(db2) @@ -134,10 +140,9 @@ memset(&gval, 0, sizeof(gval)); if(!dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) { free(gval.data); - return 1; + return SUCCESS; } - - return 0; + return FAILURE; } DBA_DELETE_FUNC(db2) @@ -145,7 +150,7 @@ DB2_DATA; DB2_GKEY; - return !dba->dbp->del(dba->dbp, NULL, &gkey, 0); + return dba->dbp->del(dba->dbp, NULL, &gkey, 0) ? FAILURE : SUCCESS; } DBA_FIRSTKEY_FUNC(db2) @@ -184,13 +189,14 @@ DBA_OPTIMIZE_FUNC(db2) { + return SUCCESS; } DBA_SYNC_FUNC(db2) { DB2_DATA; - return !dba->dbp->sync(dba->dbp, 0); + return dba->dbp->sync(dba->dbp, 0) ? FAILURE : SUCCESS; } #endif Index: php3/functions/dba_dbm.c diff -u php3/functions/dba_dbm.c:1.9 php3/functions/dba_dbm.c:1.10 --- php3/functions/dba_dbm.c:1.9 Sun May 9 14:08:18 1999 +++ php3/functions/dba_dbm.c Mon May 10 07:15:02 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dba_dbm.c,v 1.9 1999/05/09 18:08:18 sas Exp $ */ +/* $Id: dba_dbm.c,v 1.10 1999/05/10 11:15:02 sas Exp $ */ #include "php.h" @@ -99,7 +99,7 @@ gval.dptr = (char *) val; gval.dsize = vallen; - return store(gkey, gval) ? 1 : 0; + return store(gkey, gval) ? SUCCESS : FAILURE; } DBA_EXISTS_FUNC(dbm) @@ -110,9 +110,9 @@ gval = fetch(gkey); if(gval.dptr) { free(gval.dptr); - return 1; + return SUCCESS; } - return 0; + return FAILURE; } DBA_DELETE_FUNC(dbm) @@ -152,11 +152,12 @@ DBA_OPTIMIZE_FUNC(dbm) { /* dummy */ + return SUCCESS; } DBA_SYNC_FUNC(dbm) { - return 1; + return SUCCESS; } #endif Index: php3/functions/dba_gdbm.c diff -u php3/functions/dba_gdbm.c:1.8 php3/functions/dba_gdbm.c:1.9 --- php3/functions/dba_gdbm.c:1.8 Sun May 9 14:08:18 1999 +++ php3/functions/dba_gdbm.c Mon May 10 07:15:02 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dba_gdbm.c,v 1.8 1999/05/09 18:08:18 sas Exp $ */ +/* $Id: dba_gdbm.c,v 1.9 1999/05/10 11:15:02 sas Exp $ */ #include "php.h" @@ -48,23 +48,21 @@ { GDBM_FILE dbf; int gmode = 0; + int filemode = 0644; - switch(info->mode) { - case DBA_READER: - gmode = GDBM_READER; - break; - case DBA_WRITER: - gmode = GDBM_WRCREAT; - break; - case DBA_TRUNC: - gmode = GDBM_NEWDB; - break; - default: - /* should not come here */ - break; + gmode = info->mode == DBA_READER ? GDBM_READER : + info->mode == DBA_WRITER ? GDBM_WRCREAT : + info->mode == DBA_TRUNC ? GDBM_NEWDB : -1; + + if(gmode == -1) + return FAILURE; + + if(info->argc > 0) { + convert_to_long(info->argv[0]); + filemode = info->argv[0]->value.lval; } - dbf = gdbm_open(info->path, 0, gmode, 0644, NULL); + dbf = gdbm_open(info->path, 0, gmode, filemode, NULL); if(dbf) { info->dbf = malloc(sizeof(dba_gdbm_data)); @@ -111,8 +109,8 @@ if(gdbm_store(dba->dbf, gkey, gval, mode == 1 ? GDBM_INSERT : GDBM_REPLACE)) - return 1; - return 0; + return SUCCESS; + return FAILURE; } DBA_EXISTS_FUNC(gdbm) @@ -176,6 +174,7 @@ { GDBM_DATA; gdbm_reorganize(dba->dbf); + return SUCCESS; } DBA_SYNC_FUNC(gdbm) @@ -183,6 +182,6 @@ GDBM_DATA; gdbm_sync(dba->dbf); - return 1; + return SUCCESS; } #endif Index: php3/functions/dba_ndbm.c diff -u php3/functions/dba_ndbm.c:1.7 php3/functions/dba_ndbm.c:1.8 --- php3/functions/dba_ndbm.c:1.7 Sun May 9 14:08:18 1999 +++ php3/functions/dba_ndbm.c Mon May 10 07:15:02 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dba_ndbm.c,v 1.7 1999/05/09 18:08:18 sas Exp $ */ +/* $Id: dba_ndbm.c,v 1.8 1999/05/10 11:15:02 sas Exp $ */ #include "php.h" @@ -49,6 +49,7 @@ { DBM *dbf; int gmode = 0; + int filemode = 0644; dba_info *pinfo = (dba_info *) info; switch(info->mode) { @@ -62,11 +63,15 @@ gmode = O_RDWR | O_CREAT | O_TRUNC; break; default: - /* should not come here */ return FAILURE; } - dbf = dbm_open(info->path, gmode, 0644); + if(info->argc > 0) { + convert_to_long(info->argv[0]); + filemode = info->argv[0]->value.lval; + } + + dbf = dbm_open(info->path, gmode, filemode); if(dbf) { pinfo->dbf = dbf; @@ -104,8 +109,8 @@ gval.dsize = vallen; if(dbm_store(info->dbf, gkey, gval, mode == 1 ? DBM_INSERT : DBM_REPLACE)) - return 1; - return 0; + return SUCCESS; + return FAILURE; } DBA_EXISTS_FUNC(ndbm) @@ -115,9 +120,9 @@ gval = dbm_fetch(info->dbf, gkey); if(gval.dptr) { free(gval.dptr); - return 1; + return SUCCESS; } - return 0; + return FAILURE; } DBA_DELETE_FUNC(ndbm) @@ -156,10 +161,11 @@ DBA_OPTIMIZE_FUNC(ndbm) { + return SUCCESS; } DBA_SYNC_FUNC(ndbm) { - return 1; + return SUCCESS; } #endif Index: php3/functions/php3_dba.h diff -u php3/functions/php3_dba.h:1.9 php3/functions/php3_dba.h:1.10 --- php3/functions/php3_dba.h:1.9 Sun May 9 14:08:18 1999 +++ php3/functions/php3_dba.h Mon May 10 07:15:02 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php3_dba.h,v 1.9 1999/05/09 18:08:18 sas Exp $ */ +/* $Id: php3_dba.h,v 1.10 1999/05/10 11:15:02 sas Exp $ */ #ifndef _DBA_H #define _DBA_H @@ -76,7 +76,7 @@ #define DBA_NEXTKEY_FUNC(x) \ char *dba_nextkey_##x(dba_info *info, int *newlen) #define DBA_OPTIMIZE_FUNC(x) \ - void dba_optimize_##x(dba_info *info) + int dba_optimize_##x(dba_info *info) #define DBA_SYNC_FUNC(x) \ int dba_sync_##x(dba_info *info) -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#5473) next »