⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filepro.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*   +----------------------------------------------------------------------+   | PHP Version 4                                                        |   +----------------------------------------------------------------------+   | Copyright (c) 1997-2007 The PHP Group                                |   +----------------------------------------------------------------------+   | This source file is subject to version 3.01 of the PHP license,      |   | that is bundled with this package in the file LICENSE, and is        |   | available through the world-wide-web at the following url:           |   | http://www.php.net/license/3_01.txt                                  |   | If you did not receive a copy of the PHP license and are unable to   |   | obtain it through the world-wide-web, please send a note to          |   | license@php.net so we can mail you a copy immediately.               |   +----------------------------------------------------------------------+   | Author: Chad Robinson <chadr@brttech.com>                            |   +----------------------------------------------------------------------+*//* $Id: filepro.c,v 1.47.2.3.2.2 2007/01/01 09:46:41 sebastian Exp $ *//*  filePro 4.x support developed by Chad Robinson, chadr@brttech.com  Contact Chad Robinson at BRT Technical Services Corp. for details.  filePro is a registered trademark by Fiserv, Inc.  This file contains  no code or information that is not freely available from the filePro  web site at http://www.fileproplus.com/*/#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#include "safe_mode.h"#include "fopen_wrappers.h"#include <string.h>#ifdef PHP_WIN32#include <windows.h>#else#include <sys/param.h>#endif#include <errno.h>#include "php_globals.h"#include "php_filepro.h"#if HAVE_FILEPROtypedef struct fp_field {	char *name;	char *format;	int width;	struct fp_field *next;} FP_FIELD;#ifdef THREAD_SAFEDWORD FPTls;static int numthreads=0;typedef struct fp_global_struct{	char *fp_database;	signed int fp_fcount;	signed int fp_keysize;	FP_FIELD *fp_fieldlist;}fp_global_struct;#define FP_GLOBAL(a) fp_globals->a#define FP_TLS_VARS \	fp_global_struct *fp_globals; \	fp_globals=TlsGetValue(FPTls); #else#define FP_GLOBAL(a) a#define FP_TLS_VARSstatic char *fp_database = NULL;			/* Database directory */static signed int fp_fcount = -1;			/* Column count */static signed int fp_keysize = -1;			/* Size of key records */static FP_FIELD *fp_fieldlist = NULL;		/* List of fields */#endif/* {{{ PHP_MINIT_FUNCTION */PHP_MINIT_FUNCTION(filepro){#ifdef THREAD_SAFE	fp_global_struct *fp_globals;#ifdef COMPILE_DL_FILEPRO	CREATE_MUTEX(fp_mutex,"FP_TLS");	SET_MUTEX(fp_mutex);	numthreads++;	if (numthreads==1){	if ((FPTls=TlsAlloc())==0xFFFFFFFF){		FREE_MUTEX(fp_mutex);		return 0;	}}	FREE_MUTEX(fp_mutex);#endif	fp_globals = (fp_global_struct *) LocalAlloc(LPTR, sizeof(fp_global_struct)); 	TlsSetValue(FPTls, (void *) fp_globals);#endif	return SUCCESS;}/* }}} *//* {{{ PHP_RINIT_FUNCTION */PHP_RINIT_FUNCTION(filepro){	FP_GLOBAL(fp_database)=NULL;	FP_GLOBAL(fp_fcount)=-1;	FP_GLOBAL(fp_keysize)=-1;	FP_GLOBAL(fp_fieldlist)=NULL; 	return SUCCESS;}/* }}} *//* {{{ PHP_RSHUTDOWN_FUNCTION */PHP_RSHUTDOWN_FUNCTION(filepro){	FP_FIELD *tmp, *next;	if (FP_GLOBAL(fp_database)) {		efree(FP_GLOBAL(fp_database));	}		if (FP_GLOBAL(fp_fieldlist)) {		for (tmp = FP_GLOBAL(fp_fieldlist); tmp;) {			efree(tmp->name);			efree(tmp->format);			next = tmp->next;			efree(tmp);			tmp=next;		}		}	return SUCCESS;}/* }}} *//* {{{ PHP_MSHUTDOWN_FUNCTION */PHP_MSHUTDOWN_FUNCTION(filepro){#ifdef THREAD_SAFE	fp_global_struct *fp_globals;	fp_globals = TlsGetValue(FPTls); 	if (fp_globals != 0) 		LocalFree((HLOCAL) fp_globals); #ifdef COMPILE_DL_FILEPRO	SET_MUTEX(fp_mutex);	numthreads--;	if (!numthreads){		if (!TlsFree(FPTls)){			FREE_MUTEX(fp_mutex);			return 0;		}	}	FREE_MUTEX(fp_mutex);#endif#endif	return SUCCESS;}/* }}} */function_entry filepro_functions[] = {	PHP_FE(filepro,									NULL)	PHP_FE(filepro_rowcount,						NULL)	PHP_FE(filepro_fieldname,						NULL)	PHP_FE(filepro_fieldtype,						NULL)	PHP_FE(filepro_fieldwidth,						NULL)	PHP_FE(filepro_fieldcount,						NULL)	PHP_FE(filepro_retrieve,						NULL)	{NULL, NULL, NULL}};zend_module_entry filepro_module_entry = {	STANDARD_MODULE_HEADER,	"filepro", 	filepro_functions, 	PHP_MINIT(filepro), 	PHP_MSHUTDOWN(filepro), 	PHP_RINIT(filepro),	PHP_RSHUTDOWN(filepro), 	NULL, 	NO_VERSION_YET, 	STANDARD_MODULE_PROPERTIES};#ifdef COMPILE_DL_FILEPROZEND_GET_MODULE(filepro)#if defined(PHP_WIN32) && defined(THREAD_SAFE)/*NOTE: You should have an odbc.def file where youexport DllMain*/BOOL WINAPI DllMain(HANDLE hModule,                       DWORD  ul_reason_for_call,                       LPVOID lpReserved){	switch( ul_reason_for_call ) {		case DLL_PROCESS_ATTACH:			if ((FPTls=TlsAlloc())==0xFFFFFFFF) {				return 0;			}			break;    		case DLL_THREAD_ATTACH:			break;		case DLL_THREAD_DETACH:			break;		case DLL_PROCESS_DETACH:			if (!TlsFree(FPTls)) {				return 0;			}			break;	}	return 1;}#endif#endif/* * LONG filePro(STRING directory) *  * Read and verify the map file.  We store the field count and field info * internally, which means we become unstable if you modify the table while * a user is using it!  We cannot lock anything since Web connections don't * provide the ability to later unlock what we locked.  Be smart, be safe. *//* {{{ proto bool filepro(string directory)   Read and verify the map file */PHP_FUNCTION(filepro){	pval *dir;	FILE *fp;	char workbuf[MAXPATHLEN];	char readbuf[256];	char *strtok_buf = NULL;	int i;	FP_FIELD *new_field, *tmp, *next;	FP_TLS_VARS;	if (ZEND_NUM_ARGS() != 1 || getParameters(ht, 1, &dir) == FAILURE) {		WRONG_PARAM_COUNT;	}	convert_to_string(dir);	/* free memory */	if (FP_GLOBAL(fp_database) != NULL) {		efree (FP_GLOBAL(fp_database));	}		/* free linked list of fields */	tmp = FP_GLOBAL(fp_fieldlist);	while (tmp != NULL) {		next = tmp->next;		efree(tmp->name);		efree(tmp->format);		efree(tmp);		tmp = next;	} 		/* init the global vars */	FP_GLOBAL(fp_database) = NULL;	FP_GLOBAL(fp_fieldlist) = NULL;	FP_GLOBAL(fp_fcount) = -1;	FP_GLOBAL(fp_keysize) = -1;		snprintf(workbuf, sizeof(workbuf), "%s/map", Z_STRVAL_P(dir));	if (PG(safe_mode) && (!php_checkuid(workbuf, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {		RETURN_FALSE;	}		if (php_check_open_basedir(workbuf TSRMLS_CC)) {		RETURN_FALSE;	}	if (!(fp = VCWD_FOPEN(workbuf, "r"))) {		php_error(E_WARNING, "%s(): Cannot open map: [%d] %s", get_active_function_name(TSRMLS_C),					errno, strerror(errno));		RETURN_FALSE;	}	if (!fgets(readbuf, sizeof(readbuf), fp)) {		fclose(fp);		php_error(E_WARNING, "%s(): Cannot read map: [%d] %s", get_active_function_name(TSRMLS_C),					errno, strerror(errno));		RETURN_FALSE;	}		/* Get the field count, assume the file is readable! */	if (strcmp(php_strtok_r(readbuf, ":", &strtok_buf), "map")) {		php_error(E_WARNING, "%s(): Map file corrupt or encrypted", get_active_function_name(TSRMLS_C));		RETURN_FALSE;	}	FP_GLOBAL(fp_keysize) = atoi(php_strtok_r(NULL, ":", &strtok_buf));	php_strtok_r(NULL, ":", &strtok_buf);	FP_GLOBAL(fp_fcount) = atoi(php_strtok_r(NULL, ":", &strtok_buf));	/* Read in the fields themselves */	for (i = 0; i < FP_GLOBAL(fp_fcount); i++) {		if (!fgets(readbuf, sizeof(readbuf), fp)) {			fclose(fp);			php_error(E_WARNING, "%s(): Cannot read map: [%d] %s", get_active_function_name(TSRMLS_C),						errno, strerror(errno));			RETURN_FALSE;		}		new_field = emalloc(sizeof(FP_FIELD));		new_field->next = NULL;		new_field->name = estrdup(php_strtok_r(readbuf, ":", &strtok_buf));		new_field->width = atoi(php_strtok_r(NULL, ":", &strtok_buf));		new_field->format = estrdup(php_strtok_r(NULL, ":", &strtok_buf));        		/* Store in forward-order to save time later */		if (!FP_GLOBAL(fp_fieldlist)) {			FP_GLOBAL(fp_fieldlist) = new_field;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -