new api fo dl() - renamed php3_dl to php_dl (added compat header)

This commit is contained in:
Thies C. Arntzen 1999-10-13 19:55:25 +00:00
parent f5fa29184c
commit e2d66a6d28
5 changed files with 37 additions and 43 deletions

View File

@ -53,33 +53,35 @@ php3_module_entry dl_module_entry = {
#endif
/* {{{ proto int dl(string extension_filename)
Load a PHP extension at runtime */
void dl(INTERNAL_FUNCTION_PARAMETERS)
{
pval *file;
pval **file;
PLS_FETCH();
/* obtain arguments */
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &file) == FAILURE) {
if (ARG_COUNT(ht) != 1 || getParametersEx(1, &file) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(file);
convert_to_string_ex(file);
if (!PG(enable_dl)) {
php_error(E_ERROR, "Dynamically loaded extentions aren't enabled.");
} else if (PG(safe_mode)) {
php_error(E_ERROR, "Dynamically loaded extensions aren't allowed when running in SAFE MODE.");
} else {
php3_dl(file,MODULE_TEMPORARY,return_value);
php_dl(*file,MODULE_TEMPORARY,return_value);
}
}
/* }}} */
#if HAVE_LIBDL
void php3_dl(pval *file,int type,pval *return_value)
void php_dl(pval *file,int type,pval *return_value)
{
void *handle;
char libpath[MAXPATHLEN + 1];
@ -165,7 +167,7 @@ PHP_MINFO_FUNCTION(dl)
#else
void php3_dl(pval *file,int type,pval *return_value)
void php_dl(pval *file,int type,pval *return_value)
{
php_error(E_WARNING,"Cannot dynamically load %s - dynamic modules are not supported",file->value.str.val);
RETURN_FALSE;

View File

@ -35,7 +35,7 @@
#ifndef _DL_H
#define _DL_H
void php3_dl(pval *file,int type,pval *return_value);
void php_dl(pval *file,int type,pval *return_value);
#if HAVE_LIBDL

View File

@ -236,44 +236,36 @@ static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN };
portable file locking */
PHP_FUNCTION(flock)
{
pval *arg1, *arg2;
FILE *fp;
pval **arg1, **arg2;
int type;
int issock=0;
int *sock, fd=0;
int fd=0;
int act = 0;
void *what;
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
if (ARG_COUNT(ht) != 2 || getParametersEx(2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg1);
convert_to_long(arg2);
what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_socket,le_popen,le_socket);
ZEND_VERIFY_RESOURCE(what);
if (type == le_socket) {
fd = *(int *) what;
} else {
fd = fileno((FILE*) what);
}
convert_to_long_ex(arg2);
fp = php3_list_find(arg1->value.lval, &type);
if (type == le_socket){
issock = 1;
sock = php3_list_find(arg1->value.lval, &type);
fd = *sock;
act = (*arg2)->value.lval & 3;
if (act < 1 || act > 3) {
php_error(E_WARNING, "illegal value for second argument");
RETURN_FALSE;
}
if ((!fp || (type!=le_fopen && type!=le_popen)) && (!fd || type!=le_socket)) {
php_error(E_WARNING,"Unable to find file identifier %d",arg1->value.lval);
RETURN_FALSE;
}
if (!issock) {
fd = fileno(fp);
}
act = arg2->value.lval & 3;
if(act < 1 || act > 3) {
php_error(E_WARNING, "illegal value for second argument");
RETURN_FALSE;
}
/* flock_values contains all possible actions
if (arg2 & 4) we won't block on the lock */
act = flock_values[act - 1] | (arg2->value.lval & 4 ? LOCK_NB : 0);
act = flock_values[act - 1] | ((*arg2)->value.lval & 4 ? LOCK_NB : 0);
if (flock(fd, act) == -1) {
RETURN_FALSE;
}
@ -545,7 +537,6 @@ PHP_FUNCTION(fopen)
FILE *fp;
char *p;
int *sock;
int id;
int use_include_path = 0;
int issock=0, socketd=0;
@ -583,16 +574,17 @@ PHP_FUNCTION(fopen)
efree(p);
RETURN_FALSE;
}
efree(p);
fgetss_state=0;
if (issock) {
sock=emalloc(sizeof(int));
*sock=socketd;
id = php3_list_insert(sock,le_socket);
ZEND_REGISTER_RESOURCE(return_value,sock,le_socket);
} else {
id = php3_list_insert(fp,le_fopen);
ZEND_REGISTER_RESOURCE(return_value,fp,le_fopen);
}
efree(p);
RETURN_LONG(id);
}
/* }}} */
@ -627,7 +619,6 @@ PHP_FUNCTION(popen)
{
pval *arg1, *arg2;
FILE *fp;
int id;
char *p;
char *b, buf[1024];
PLS_FETCH();
@ -670,9 +661,9 @@ PHP_FUNCTION(popen)
RETURN_FALSE;
}
}
id = php3_list_insert(fp,le_popen);
efree(p);
RETURN_LONG(id);
ZEND_REGISTER_RESOURCE(return_value,fp,le_popen);
}
/* }}} */

View File

@ -370,7 +370,7 @@ statement:
printf("Loading '%s'\n",$3.value.str.val);
#endif
php3_dl(&$3,MODULE_PERSISTENT,&dummy);
php_dl(&$3,MODULE_PERSISTENT,&dummy);
}
| T_ZEND_EXTENSION '=' string {
#if !defined(ZTS) && !ZEND_DEBUG

View File

@ -88,5 +88,6 @@
#define _php3_addslashes php_addslashes
#define _php3_stripslashes php_stripslashes
#define php3_dl php_dl
#endif /* _PHP3_COMPAT_H */