diff options
| author | Ilia Alshanetsky <iliaa@php.net> | 2003-02-25 01:39:06 +0000 |
|---|---|---|
| committer | Ilia Alshanetsky <iliaa@php.net> | 2003-02-25 01:39:06 +0000 |
| commit | 862634ffa582e111e9a30e02f6e268e3cfb241ac (patch) | |
| tree | 99e913d69b46c13cb4973b53b2285d69e47d33f5 /ext/standard/file.c | |
| parent | 96563ce34f3cab5195762cc771e374419a67b29f (diff) | |
| download | php-git-862634ffa582e111e9a30e02f6e268e3cfb241ac.tar.gz | |
Added locking to streams.
Allow PHP to automatically release locks on files when terminating the
stream.
Fixed bugs in the handling of the 3rd optional parameter to flock().
Diffstat (limited to 'ext/standard/file.c')
| -rw-r--r-- | ext/standard/file.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c index 24739957b9..5fafdce431 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -218,8 +218,8 @@ static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN }; PHP_FUNCTION(flock) { - zval *arg1, *arg3; - int fd, act, ret; + zval *arg1, *arg3 = NULL; + int fd, act; php_stream *stream; long operation = 0; @@ -241,15 +241,14 @@ PHP_FUNCTION(flock) /* flock_values contains all possible actions if (operation & 4) we won't block on the lock */ act = flock_values[act - 1] | (operation & 4 ? LOCK_NB : 0); - if ((ret = flock(fd, act)) == -1) { - if (errno == EWOULDBLOCK && operation) { - convert_to_long(arg3); - Z_LVAL_P(arg3) = 1; - RETURN_TRUE; + if (!php_stream_lock(stream, act)) { + if (operation && errno == EWOULDBLOCK && arg3 && PZVAL_IS_REF(arg3)) { + convert_to_long_ex(&arg3); + ZVAL_LONG(arg3, 1); } - RETURN_FALSE; + RETURN_TRUE; } - RETURN_TRUE; + RETURN_FALSE; } /* }}} */ |
