[PHP4BETA] CVS update: php4/ext/standard
| From: | sas | Date: | Wed, 21 Apr 1999 18:10:18 +0000 |
| Subject: | [PHP4BETA] CVS update: php4/ext/standard | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-241@lists.php.net to get a copy of this message | ||
Date: Wednesday April 21, 1999 @ 14:10
Author: sas
Update of /repository/php4/ext/standard
In directory php:/tmp/cvs-serv3788/ext/standard
Modified Files:
file.c file.h
Log Message:
cleanup, flock() support
Index: php4/ext/standard/file.c
diff -c php4/ext/standard/file.c:1.4 php4/ext/standard/file.c:1.5
*** php4/ext/standard/file.c:1.4 Wed Apr 21 13:57:40 1999
--- php4/ext/standard/file.c Wed Apr 21 14:10:17 1999
***************
*** 26,32 ****
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
! /* $Id: file.c,v 1.4 1999/04/21 17:57:40 sas Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
--- 26,32 ----
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
! /* $Id: file.c,v 1.5 1999/04/21 18:10:17 sas Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
***************
*** 198,203 ****
--- 198,204 ----
{"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))
***************
*** 209,214 ****
--- 210,268 ----
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])
Index: php4/ext/standard/file.h
diff -c php4/ext/standard/file.h:1.1 php4/ext/standard/file.h:1.2
*** php4/ext/standard/file.h:1.1 Fri Apr 16 20:37:06 1999
--- php4/ext/standard/file.h Wed Apr 21 14:10:18 1999
***************
*** 27,33 ****
+----------------------------------------------------------------------+
*/
! /* $Id: file.h,v 1.1 1999/04/17 00:37:06 ssb Exp $ */
#ifndef _FILE_H
#define _FILE_H
--- 27,33 ----
+----------------------------------------------------------------------+
*/
! /* $Id: file.h,v 1.2 1999/04/21 18:10:18 sas Exp $ */
#ifndef _FILE_H
#define _FILE_H
***************
*** 61,65 ****
--- 61,66 ----
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 */
--
PHP 4 Beta