CVS update: php3/functions
| From: | sas | Date: | Sun, 31 Jan 1999 16:15:38 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-3803@lists.php.net to get a copy of this message | ||
Date: Sunday January 31, 1999 @ 11:15
Author: sas
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv26813/functions
Modified Files:
file.c file.h
Log Message:
Add PHP3 flock() support
Index: php3/functions/file.c
diff -c php3/functions/file.c:1.196 php3/functions/file.c:1.197
*** php3/functions/file.c:1.196 Sun Jan 24 18:53:18 1999
--- php3/functions/file.c Sun Jan 31 11:15:34 1999
***************
*** 26,32 ****
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
! /* $Id: file.c,v 1.196 1999/01/24 23:53:18 sas Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
--- 26,32 ----
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
! /* $Id: file.c,v 1.197 1999/01/31 16:15:34 sas Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
***************
*** 76,81 ****
--- 76,85 ----
#include "fsock.h"
#include "fopen-wrappers.h"
+ #if HAVE_SYS_FILE_H
+ #include <sys/file.h>
+ #endif
+
#if MISSING_FCLOSE_DECL
extern int fclose();
#endif
***************
*** 181,213 ****
#endif
function_entry php3_file_functions[] = {
! {"pclose", php3_pclose, NULL},
! {"popen", php3_popen, NULL},
! {"readfile", php3_readfile, NULL},
! {"rewind", php3_rewind, NULL},
! {"rmdir", php3_rmdir, NULL},
{"umask", php3_fileumask, NULL},
! {"fclose", php3_fclose, NULL},
! {"feof", php3_feof, NULL},
! {"fgetc", php3_fgetc, NULL},
! {"fgets", php3_fgets, NULL},
! {"fgetss", php3_fgetss, NULL},
! {"fread", php3_fread, NULL},
! {"fopen", php3_fopen, NULL},
! {"fpassthru", php3_fpassthru, NULL},
! {"fseek", php3_fseek, NULL},
! {"ftell", php3_ftell, NULL},
! {"fwrite", php3_fwrite, NULL},
{"fputs", php3_fwrite, NULL},
! {"mkdir", php3_mkdir, NULL},
! {"rename", php3_rename, NULL},
{"copy", php3_file_copy, NULL},
! {"tempnam", php3_tempnam, NULL},
! {"file", php3_file, 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))
! {"set_socket_timeout", php3_set_socket_timeout, NULL},
#endif
{NULL, NULL, NULL}
};
--- 185,218 ----
#endif
function_entry php3_file_functions[] = {
! PHP_FE(pclose, NULL)
! PHP_FE(popen, NULL)
! PHP_FE(readfile, NULL)
! PHP_FE(rewind, NULL)
{"umask", php3_fileumask, NULL},
! PHP_FE(rmdir, NULL)
! PHP_FE(fclose, NULL)
! PHP_FE(feof, NULL)
! PHP_FE(fgetc, NULL)
! PHP_FE(fgets, NULL)
! PHP_FE(fgetss, NULL)
! PHP_FE(fpassthru, NULL)
! PHP_FE(fread, NULL)
! PHP_FE(fopen, NULL)
! PHP_FE(fseek, NULL)
! PHP_FE(ftell, NULL)
! PHP_FE(fwrite, NULL)
{"fputs", php3_fwrite, NULL},
! PHP_FE(mkdir, NULL)
! PHP_FE(rename, NULL)
{"copy", php3_file_copy, NULL},
! PHP_FE(tempnam, NULL)
! PHP_FE(file, NULL)
! PHP_FE(flock, NULL)
! PHP_FE(get_meta_tags, NULL)
! PHP_FE(set_socket_blocking, NULL)
#if (0 && HAVE_SYS_TIME_H && HAVE_SETSOCKOPT && defined(SO_SNDTIMEO)
&& defined(SO_RCVTIMEO))
! PHP_FE(set_socket_timeout, NULL)
#endif
{NULL, NULL, NULL}
};
***************
*** 1444,1449 ****
--- 1449,1507 ----
TLS_VARS;
return GLOBAL(le_fp);
}
+
+ static 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;
+ }
+ /* }}} */
/*
* Local variables:
Index: php3/functions/file.h
diff -c php3/functions/file.h:1.26 php3/functions/file.h:1.27
*** php3/functions/file.h:1.26 Fri Jan 1 12:59:09 1999
--- php3/functions/file.h Sun Jan 31 11:15:38 1999
***************
*** 27,33 ****
+----------------------------------------------------------------------+
*/
! /* $Id: file.h,v 1.26 1999/01/01 17:59:09 zeev Exp $ */
#ifndef _FILE_H
#define _FILE_H
--- 27,33 ----
+----------------------------------------------------------------------+
*/
! /* $Id: file.h,v 1.27 1999/01/31 16:15:38 sas Exp $ */
#ifndef _FILE_H
#define _FILE_H
***************
*** 65,69 ****
--- 65,70 ----
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 Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net