summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2002-11-05 14:46:36 +0000
committerMarcus Boerger <helly@php.net>2002-11-05 14:46:36 +0000
commit177b24a44ee3b0ff39889a1ef1f896edf559a389 (patch)
treea72933d329f02221d61f564caa9c4423e7cb6a5f
parent41a77bccba8f597d694f5b66b289f1bba6529a26 (diff)
downloadphp-git-177b24a44ee3b0ff39889a1ef1f896edf559a389.tar.gz
Why did open fail?
-rw-r--r--ext/dba/dba.c12
-rw-r--r--ext/dba/dba_cdb.c8
-rw-r--r--ext/dba/dba_db2.c9
-rw-r--r--ext/dba/dba_db3.c6
-rw-r--r--ext/dba/dba_dbm.c4
-rw-r--r--ext/dba/dba_gdbm.c3
-rw-r--r--ext/dba/dba_ndbm.c3
-rw-r--r--ext/dba/php_dba.h2
8 files changed, 34 insertions, 13 deletions
diff --git a/ext/dba/dba.c b/ext/dba/dba.c
index 1e674b410c..b30e0b6bb2 100644
--- a/ext/dba/dba.c
+++ b/ext/dba/dba.c
@@ -79,7 +79,7 @@ ZEND_GET_MODULE(dba)
typedef struct dba_handler {
char *name;
- int (*open)(dba_info * TSRMLS_DC);
+ int (*open)(dba_info *, char **error TSRMLS_DC);
void (*close)(dba_info * TSRMLS_DC);
char* (*fetch)(dba_info *, char *, int, int, int * TSRMLS_DC);
int (*update)(dba_info *, char *, int, char *, int, int TSRMLS_DC);
@@ -290,7 +290,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
dba_mode_t modenr;
dba_info *info;
dba_handler *hptr;
- char *key = NULL;
+ char *key = NULL, *error = NULL;
int keylen = 0;
int i;
@@ -341,7 +341,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
for (hptr = handler; hptr->name && strcasecmp(hptr->name, Z_STRVAL_PP(args[2])); hptr++);
if (!hptr->name) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such handler: %s", Z_STRVAL_PP(args[2]));
+ php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "No such handler: %s", Z_STRVAL_PP(args[2]));
FREENOW;
RETURN_FALSE;
}
@@ -360,7 +360,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
modenr = DBA_TRUNC;
break;
default:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal DBA mode: %s", Z_STRVAL_PP(args[1]));
+ php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Illegal DBA mode");
FREENOW;
RETURN_FALSE;
}
@@ -373,9 +373,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
info->argv = args + 3;
info->hnd = NULL;
- if (hptr->open(info TSRMLS_CC) != SUCCESS) {
+ if (hptr->open(info, &error TSRMLS_CC) != SUCCESS) {
dba_close(info TSRMLS_CC);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Driver initialization failed for handler: %s", Z_STRVAL_PP(args[2]));
+ php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Driver initialization failed for handler: %s%s%s", Z_STRVAL_PP(args[2]), error?": ":"", error?error:"");
FREENOW;
RETURN_FALSE;
}
diff --git a/ext/dba/dba_cdb.c b/ext/dba/dba_cdb.c
index 6b025d5466..eac2576aec 100644
--- a/ext/dba/dba_cdb.c
+++ b/ext/dba/dba_cdb.c
@@ -74,11 +74,13 @@ DBA_OPEN_FUNC(cdb)
make = 0;
file = php_stream_open_wrapper(info->path, "rb", STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
if (!file) {
+ *error = "Unable to open file";
return FAILURE;
}
#else
file = VCWD_OPEN(info->path, O_RDONLY);
if (file < 0) {
+ *error = "Unable to open file";
return FAILURE;
}
#endif
@@ -89,24 +91,28 @@ DBA_OPEN_FUNC(cdb)
make = 1;
file = php_stream_open_wrapper(info->path, "wb", STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
if (!file) {
+ *error = "Unable to open file";
return FAILURE;
}
break;
case DBA_WRITER:
+ *error = "Update operations are not supported";
return FAILURE; /* not supported */
#endif
default:
- /* currently not supported: */
+ *error = "Currently not supported";
return FAILURE;
}
cdb = ecalloc(sizeof(dba_cdb), 1);
if (!cdb) {
+ pinfo->dbf = cdb;
#if DBA_CDB_BUILTIN
php_stream_close(file);
#else
close(file);
#endif
+ *error = "Out of memory";
return FAILURE;
}
diff --git a/ext/dba/dba_db2.c b/ext/dba/dba_db2.c
index 5b628c98f6..eb6942f84a 100644
--- a/ext/dba/dba_db2.c
+++ b/ext/dba/dba_db2.c
@@ -63,8 +63,9 @@ DBA_OPEN_FUNC(db2)
info->mode == DBA_WRITER ? 0 :
info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1;
- if (gmode == -1)
- return FAILURE;
+ if (gmode == -1) {
+ return FAILURE;/* not possible */
+ }
if (info->argc > 0) {
convert_to_long_ex(info->argv[0]);
@@ -76,6 +77,10 @@ DBA_OPEN_FUNC(db2)
}
info->dbf = ecalloc(sizeof(dba_db2_data), 1);
+ if (!info->dbf) {
+ *error = "Out of memory";
+ return FAILURE;
+ }
((dba_db2_data *) info->dbf)->dbp = dbp;
return SUCCESS;
}
diff --git a/ext/dba/dba_db3.c b/ext/dba/dba_db3.c
index edade52042..5dd3af58f7 100644
--- a/ext/dba/dba_db3.c
+++ b/ext/dba/dba_db3.c
@@ -66,7 +66,7 @@ DBA_OPEN_FUNC(db3)
info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1;
if (gmode == -1)
- return FAILURE;
+ return FAILURE; /* not possible */
if (info->argc > 0) {
convert_to_long_ex(info->argv[0]);
@@ -78,6 +78,10 @@ DBA_OPEN_FUNC(db3)
dba_db3_data *data;
data = emalloc(sizeof(*data));
+ if (!data) {
+ *error = "Out of memory";
+ return FAILURE;
+ }
data->dbp = dbp;
data->cursor = NULL;
info->dbf = data;
diff --git a/ext/dba/dba_dbm.c b/ext/dba/dba_dbm.c
index 0eea524ccb..5763fad41e 100644
--- a/ext/dba/dba_dbm.c
+++ b/ext/dba/dba_dbm.c
@@ -79,6 +79,10 @@ DBA_OPEN_FUNC(dbm)
}
info->dbf = ecalloc(sizeof(dba_dbm_data), 1);
+ if (!info->dbf) {
+ *error = "Out of memory";
+ return FAILURE;
+ }
return SUCCESS;
}
diff --git a/ext/dba/dba_gdbm.c b/ext/dba/dba_gdbm.c
index e462d01b95..49cf088f78 100644
--- a/ext/dba/dba_gdbm.c
+++ b/ext/dba/dba_gdbm.c
@@ -49,7 +49,7 @@ DBA_OPEN_FUNC(gdbm)
info->mode == DBA_TRUNC ? GDBM_NEWDB : -1;
if(gmode == -1)
- return FAILURE;
+ return FAILURE; /* not possible */
if(info->argc > 0) {
convert_to_long_ex(info->argv[0]);
@@ -63,6 +63,7 @@ DBA_OPEN_FUNC(gdbm)
((dba_gdbm_data *) info->dbf)->dbf = dbf;
return SUCCESS;
}
+ *error = "Out of memory";
return FAILURE;
}
diff --git a/ext/dba/dba_ndbm.c b/ext/dba/dba_ndbm.c
index 7dfb66484b..a362cfc2cc 100644
--- a/ext/dba/dba_ndbm.c
+++ b/ext/dba/dba_ndbm.c
@@ -55,7 +55,7 @@ DBA_OPEN_FUNC(ndbm)
gmode = O_RDWR | O_CREAT | O_TRUNC;
break;
default:
- return FAILURE;
+ return FAILURE; /* not possible */
}
if(info->argc > 0) {
@@ -69,6 +69,7 @@ DBA_OPEN_FUNC(ndbm)
pinfo->dbf = dbf;
return SUCCESS;
}
+ *error = "Out of memory";
return FAILURE;
}
diff --git a/ext/dba/php_dba.h b/ext/dba/php_dba.h
index 7acaa29c0e..c0c1bfc672 100644
--- a/ext/dba/php_dba.h
+++ b/ext/dba/php_dba.h
@@ -48,7 +48,7 @@ extern zend_module_entry dba_module_entry;
/* common prototypes which must be supplied by modules */
#define DBA_OPEN_FUNC(x) \
- int dba_open_##x(dba_info *info TSRMLS_DC)
+ int dba_open_##x(dba_info *info, char **error TSRMLS_DC)
#define DBA_CLOSE_FUNC(x) \
void dba_close_##x(dba_info *info TSRMLS_DC)
#define DBA_FETCH_FUNC(x) \