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

📄 filesystemhandling.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
字号:
/*______________________________________________________________________________
	Copyright (C) 2002 PGP Corporation
	All rights reserved.


	$Id: FileSystemHandling.c,v 1.8 2002/09/09 00:31:43 sdas Exp $
______________________________________________________________________________*/

/*::: MODULE OVERVIEW :::::::::::::

--- revision history --------
9/6/02 Version 1.1 Paul Ryan
+ added ef_WriteMemToFile()

9/16/00 Version 1.0.1 Paul Ryan
+ added ei_FileAccess() wrapper for ANSI access() function

8/6/99 Version 1.0 Paul Ryan
::::::::::::::::::::::::::::::::::::*/

#include "FileSystemHandling.h"

//global-scope constants
const int  ei_ERR_ACCESS = EACCES, ei_ERR_EXIST = ENOENT, 
			ei_FILE_ACCS_EXIST = 0x0, ei_FILE_ACCS_WRITE = 0x2, 
			ei_FILE_ACCS_READ = 0x4, ei_FILE_ACCS_READWRITE = 0x6;


/** ef_WriteMemToFile( ***


--- parameters & return ----


--- revision history -------
9/6/02 PR: created			*/
//DOC!!
BOOL ef_WriteMemToFile( const unsigned char *const  PUC, 
						const unsigned long  UL, 
						const char PC[])	{
	FILE * pfl;
	BOOL  f_fail;

	if (!( PUC && PC))
		return FALSE;

	if (!( pfl = fopen( PC, "wb")))
		return FALSE;

	fwrite( PUC, 1, UL, pfl);
	f_fail = ferror( pfl);

	if (fclose( pfl) == EOF && !f_fail)
		f_fail = TRUE;

	return !f_fail;
} //ef_WriteMemToFile(


/** ei_FileAccess( ***
Tells whether the caller can obtain a particular access level to the 
specified file.

--- parameter & return ----
PC: extended filename of the file whose access level is to be tested
I: access level to be tested, choices are the ei_FILE_ACCS_* constants, 
	mirroring those used with the ANSI access() function
f_EXCL: Flag telling whether exclusive access is to be tested. Only relevant 
	if the access level being tested is beyond mere file existence.
RETURN:
	eus_SUCCESS if the file has the specified access level
	eus_ERR_INVLD_ARG if any input parameter is obviously invalid
	ei_ERR_ACCESS if the file's permission setting does not allow the 
		specified access level
	ei_ERR_EXIST if the specified file was not found on the file system

--- revision history ------
9/16/00 PR: created			*/
int ei_FileAccess( const char  PC[], 
					const int  I, 
					const BOOL  f_EXCL)	{
	int  i;

	if (!( PC && I >= ei_FILE_ACCS_EXIST && I <= ei_FILE_ACCS_READWRITE))
		return eus_ERR_INVLD_ARG;

	if (access( PC, I) == ei_FAIL)
		return errno;

	if (I && f_EXCL)
		if ((i = sopen( PC, _O_RDONLY, _SH_DENYRW)) == ei_FAIL)
			return errno;
		else
			close( i);

	return eus_SUCCESS;
} //ei_FileAccess(


/** epc_getTempDirNm( ***
Purpose is to fill the specified buffer with the name of the system's 
temporary directory, ending with the path-specifier character (e.g. backslash 
with Win32).

--- parameters & return ----
pc_buf: pointer to the pre-allocated buffer
ui_LEN_BUF: the amount of space in the buffer
RETURN: pc_buf if successful, else NULL

--- revision history -------
8/1/99 PR: created			*/
char * epc_getTempDirNm( char *const  pc_buf, 
							const unsigned int  ui_LEN_BUF)	{
	const char *const  pc_ENV_TEMP = getenv( "TEMP");

	if (!( pc_buf && ui_LEN_BUF))
		return NULL;

	if (strlen( pc_ENV_TEMP) + strlen( epc_PATH_SPECIFIER) > ui_LEN_BUF - 1)
		return NULL;
	strcat( strcpy( pc_buf, pc_ENV_TEMP), (const char *) (strrchr( 
								pc_ENV_TEMP, ec_PATH_SPECIFIER) != 
								pc_ENV_TEMP + strlen( pc_ENV_TEMP) - 1 ? 
								(int) epc_PATH_SPECIFIER : (int) epc_NULL));

	return pc_buf;
} //epc_getTempDirNm(


/** ef_LoadBinaryFile( ***


--- parameters & return ----


--- revision history -------
8/1/99 PR: created			*/
//DOC!!
BOOL ef_LoadBinaryFile( const char  pc_FILENM[], 
						void *const  pv, 
						const int  i_LEN)	{
	FILE * pfl;
	char * pc = NULL;
	BOOL  f_failure;

	if (!( pc_FILENM && pv && i_LEN))
		return FALSE;

	if (!( pfl = fopen( pc_FILENM, "rb")))
		return FALSE;

	if (f_failure = filelength( fileno( pfl)) < i_LEN)
		goto errJump;

	fread( pv, 1, i_LEN, pfl);
	f_failure = ferror( pfl);

errJump:
	if (fclose( pfl) == EOF)
		if (!f_failure)
			f_failure = TRUE;

	return !f_failure;
} //ef_LoadBinaryFile(


/** ef_LoadTextFileEntire( ***


--- parameters & return ----


--- revision history -------
8/1/99 PR: created			*/
//DOC!!
/*BOOL ef_LoadTextFileEntire( const char  pc_FILENM[], 
							char * *const  ppc)	{
	FILE * pfl;
	int  i;
	char * pc = NULL;
	BOOL  f_failure;

	if (!( pc_FILENM && ppc))
		return FALSE;

	*ppc = NULL;

	if (!( pfl = fopen( pc_FILENM, "rt")))
		return FALSE;

	if (f_failure = (i = filelength( fileno( pfl))) < 0)
		goto errJump;

	if (i)	{
		if (f_failure = !( pc = malloc( i + 1)))
			goto errJump;

		i = fread( pc, 1, i, pfl);
		if (f_failure = ferror( pfl))
			goto errJump;
		pc[ i] = NULL;
	} //if (i)

errJump:
	if (fclose( pfl) == EOF)
		if (!f_failure)
			f_failure = TRUE;

	if (pc)
		if (!f_failure)
			*ppc = pc;
		else 
			free( pc);

	return !f_failure;
} //ef_LoadTextFileEntire(
*/

⌨️ 快捷键说明

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