mirror of
https://github.com/php/php-src.git
synced 2025-01-26 21:54:16 +08:00
cleanup, flock() support
This commit is contained in:
parent
f06cb4deb6
commit
08c6298af9
@ -53,7 +53,6 @@ March 1 1999, Version 3.0.7
|
||||
- Add another version of WDDX module
|
||||
(we need to pick a single implementation here)
|
||||
- Fixed includes for iODBC to support both the old and the new LGPL version
|
||||
- Add flock() function
|
||||
- Fix implode() bug - When imploding an array that contained unset() elements
|
||||
it wasn't correctly skipping past these
|
||||
- Add connection_status() function. This returns the raw bitfield which
|
||||
|
@ -198,6 +198,7 @@ function_entry php3_file_functions[] = {
|
||||
{"copy", php3_file_copy, NULL},
|
||||
{"tempnam", php3_tempnam, NULL},
|
||||
{"file", php3_file, NULL},
|
||||
PHP_FE(flock, NULL)
|
||||
{"get_meta_tags", php3_get_meta_tags, NULL},
|
||||
{"set_socket_blocking", php3_set_socket_blocking, NULL},
|
||||
#if (0 && HAVE_SYS_TIME_H && HAVE_SETSOCKOPT && defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO))
|
||||
@ -210,6 +211,59 @@ php3_module_entry php3_file_module_entry = {
|
||||
"PHP_file", php3_file_functions, php3_minit_file, NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES
|
||||
};
|
||||
|
||||
static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN };
|
||||
|
||||
/* {{{ proto bool flock(int fp, int operation)
|
||||
portable file locking */
|
||||
PHP_FUNCTION(flock)
|
||||
{
|
||||
pval *arg1, *arg2;
|
||||
FILE *fp;
|
||||
int type;
|
||||
int issock=0;
|
||||
int *sock, fd=0;
|
||||
int act = 0;
|
||||
TLS_VARS;
|
||||
|
||||
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
convert_to_long(arg1);
|
||||
convert_to_long(arg2);
|
||||
|
||||
fp = php3_list_find(arg1->value.lval, &type);
|
||||
if (type == GLOBAL(wsa_fp)){
|
||||
issock = 1;
|
||||
sock = php3_list_find(arg1->value.lval, &type);
|
||||
fd = *sock;
|
||||
}
|
||||
|
||||
if ((!fp || (type!=GLOBAL(le_fp) && type!=GLOBAL(le_pp))) && (!fd || type!=GLOBAL(wsa_fp))) {
|
||||
php3_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) {
|
||||
php3_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);
|
||||
if (flock(fd, act) == -1) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ proto array get_meta_tags(string filename [, int use_include_path])
|
||||
Extracts all meta tag content attributes from a file and returns an array */
|
||||
|
@ -61,5 +61,6 @@ extern void php3_file(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_set_socket_blocking(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_set_socket_timeout(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_get_meta_tags(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern PHP_FUNCTION(flock);
|
||||
|
||||
#endif /* _FILE_H */
|
||||
|
Loading…
Reference in New Issue
Block a user