Skip to content

Commit

Permalink
Add zend_ini_string_ex so that the you can differentiate between NULL…
Browse files Browse the repository at this point in the history
… as a value and its absence, this is important for ini_get. Related to bug #42657 and #43348
  • Loading branch information
Scott MacVicar committed Jul 7, 2008
1 parent 5c158c0 commit 43e7784
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
28 changes: 24 additions & 4 deletions Zend/zend_ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,25 +367,45 @@ ZEND_API double zend_ini_double(char *name, uint name_length, int orig) /* {{{ *
}
/* }}} */

ZEND_API char *zend_ini_string(char *name, uint name_length, int orig) /* {{{ */
ZEND_API char *zend_ini_string_ex(char *name, uint name_length, int orig, zend_bool *exists) /* {{{ */
{
zend_ini_entry *ini_entry;
TSRMLS_FETCH();

if (zend_hash_find(EG(ini_directives), name, name_length, (void **) &ini_entry) == SUCCESS) {
if (exists) {
*exists = 1;
}

if (orig && ini_entry->modified) {
return ini_entry->orig_value ? ini_entry->orig_value : "";
return ini_entry->orig_value;
} else {
return ini_entry->value ? ini_entry->value : "";
return ini_entry->value;
}
} else {
} else if (exists) {
*exists = 0;
return NULL;
}

return "";
}
/* }}} */

ZEND_API char *zend_ini_string(char *name, uint name_length, int orig) /* {{{ */
{
zend_bool exists = 1;
char *return_value;

return_value = zend_ini_string_ex(name, name_length, orig, &exists);
if (!exists) {
return NULL;
} else if (!return_value) {
return_value = "";
}
return return_value;
}
/* }}} */

#if TONY_20070307
static void zend_ini_displayer_cb(zend_ini_entry *ini_entry, int type) /* {{{ */
{
Expand Down
3 changes: 2 additions & 1 deletion Zend/zend_ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ ZEND_API void display_ini_entries(zend_module_entry *module);
ZEND_API long zend_ini_long(char *name, uint name_length, int orig);
ZEND_API double zend_ini_double(char *name, uint name_length, int orig);
ZEND_API char *zend_ini_string(char *name, uint name_length, int orig);
ZEND_API char *zend_ini_string_ex(char *name, uint name_length, int orig, zend_bool *exists);

ZEND_API int zend_ini_register_displayer(char *name, uint name_length, void (*displayer)(zend_ini_entry *ini_entry, int type));

Expand Down Expand Up @@ -157,7 +158,7 @@ END_EXTERN_C()

#define INI_INT(name) zend_ini_long((name), sizeof(name), 0)
#define INI_FLT(name) zend_ini_double((name), sizeof(name), 0)
#define INI_STR(name) zend_ini_string((name), sizeof(name), 0)
#define INI_STR(name) zend_ini_string_ex((name), sizeof(name), 0, NULL)
#define INI_BOOL(name) ((zend_bool) INI_INT(name))

#define INI_ORIG_INT(name) zend_ini_long((name), sizeof(name), 1)
Expand Down

0 comments on commit 43e7784

Please sign in to comment.