diff options
author | Sascha Schumann <sas@php.net> | 1999-04-21 18:10:18 +0000 |
---|---|---|
committer | Sascha Schumann <sas@php.net> | 1999-04-21 18:10:18 +0000 |
commit | 08c6298af9a05eae678cf9c01d72b9cbe72a8acc (patch) | |
tree | 8f793e2a15d42fb6cfad66067c31efd27e427a20 /ext | |
parent | f06cb4deb6115b120e8dfcf14ca1dacc83d887fe (diff) | |
download | php-git-08c6298af9a05eae678cf9c01d72b9cbe72a8acc.tar.gz |
cleanup, flock() support
Diffstat (limited to 'ext')
-rw-r--r-- | ext/standard/file.c | 54 | ||||
-rw-r--r-- | ext/standard/file.h | 1 |
2 files changed, 55 insertions, 0 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c index 0bd00625a4..066c69420b 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -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 */ diff --git a/ext/standard/file.h b/ext/standard/file.h index 08f1440f13..e0f1340119 100644 --- a/ext/standard/file.h +++ b/ext/standard/file.h @@ -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 */ |