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

📄 jdd_fileapi.c.svn-base

📁 gif to bmp conversion
💻 SVN-BASE
字号:
#define MODULE_NAME						"jdd"
#define FILE_NAME						"jdd_fileapi.c"
/***************************************************************************
 * $Id: jdd_fileapi.c,v 1.46 2008/07/02 13:10:14 kawalccjims Exp $
 * $Revision: 1.46 $
 * $DateTime: $
 * 
 * IMPORTANT NOTICE
 *
 * Please note that any and all title and/or intellectual property rights 
 * in and to this Software or any part of this (including without limitation 
 * any images, photographs, animations, video, audio, music, text and/or 
 * "applets," incorporated into the Software), herein mentioned to as 
 * "Software", the accompanying printed materials, and any copies of the 
 * Software, are owned by Jataayu Software (P) Ltd., Bangalore ("Jataayu") 
 * or Jataayu's suppliers as the case may be. The Software is protected by 
 * copyright, including without limitation by applicable copyright laws, 
 * international treaty provisions, other intellectual property laws and 
 * applicable laws in the country in which the Software is being used. 
 * You shall not modify, adapt or translate the Software, without prior 
 * express written consent from Jataayu. You shall not reverse engineer, 
 * decompile, disassemble or otherwise alter the Software, except and 
 * only to the extent that such activity is expressly permitted by 
 * applicable law notwithstanding this limitation. Unauthorized reproduction 
 * or redistribution of this program or any portion of it may result in severe 
 * civil and criminal penalties and will be prosecuted to the maximum extent 
 * possible under the law. Jataayu reserves all rights not expressly granted. 
 * 
 * THIS SOFTWARE IS PROVIDED TO YOU "AS IS" WITHOUT WARRANTY OF ANY 
 * KIND AND ANY AND ALL REPRESENTATION AND WARRANTIES, EITHER EXPRESS 
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY ACCURACY OF INFORMATIONAL CONTENT, AND/OR FITNESS 
 * FOR A PARTICULAR PURPOSE OR USE, TITLE OR INFRINGEMENT ARE EXPRESSLY 
 * DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. YOU ASSUME THE 
 * ENTIRE RISK AS TO THE ACCURACY AND THE USE OF THIS SOFTWARE. JATAAYU 
 * SHALL NOT BE LIABLE FOR ANY CONSEQUENTIAL, INCIDENTAL, INDIRECT, 
 * EXEMPLARY, SPECIAL OR PUNITIVE DAMAGES INCLUDING WITHOUT LIMITATION 
 * ANY LOSS OF DATA, OR; LOSS OF PROFIT, SAVINGS BUSINESS OR GOODWILL 
 * OR OTHER SIMILAR LOSS RESULTING FROM OR OUT OF THE USE OR INABILITY 
 * TO USE THIS SOFTWARE, EVEN IF JATAAYU HAS BEEN ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE, OR FOR ANY CLAIM BY ANY THIRD PARTY.
 *
 ***************************************************************************
 *
 * Revision Details
 * ----------------
 * $Log: jdd_fileapi.c,v $
 * Revision 1.46  2008/07/02 13:10:14  kawalccjims
 * *** empty log message ***
 *
 * Revision 1.11  2006/01/24 12:02:05  kumardevhtmlbrow
 * *** empty log message ***
 *
 * Revision 1.10  2005/12/12 15:29:02  kumardevhtmlbrow
 * Providing the logging framework for all the modules with the new JDD log abstraction
 *
 * Revision 1.9  2005/12/09 15:15:16  kumardevhtmlbrow
 * Added the suspend and resume request. Providing additional interface for starting confirmed & http push. Changes as per new JDD LOG abstraction
 *
 * Revision 1.8  2005/11/04 15:22:16  kumardevhtmlbrow
 * *** empty log message ***
 *
 * Revision 1.7  2005/09/12 12:17:43  kumardevhtmlbrow
 * Given the additional new line at the end ....
 *
 * Revision 1.6  2005/08/25 04:58:22  kumardevhtmlbrow
 * no message
 *
 * Revision 1.5  2005/08/17 06:25:16  kumardevhtmlbrow
 * Updated the jdd_MemAlloc to jdi_MemAlloc function.
 *
 * Revision 1.4  2005/08/02 12:29:24  kumardevhtmlbrow
 * no message
 *
 * Revision 1.3  2005/07/12 09:49:49  shreyasdevhtmlbrow
 * no message
 *
 * Revision 1.2  2005/04/26 10:01:25  kumardevhtmlbrow
 * Update as per the convention
 *
 * Revision 1.1  2005/04/16 10:51:29  kumardevhtmlbrow
 * Added JDD & jdd_FS call
 *
 *  
 ***************************************************************************/

#include <sys/stat.h>
#include <io.h>

#include <direct.h>
#include <errno.h>

/***************************************************************************
 * User Include Files
 **************************************************************************/

#include <ddl.h>

#ifdef JDD_LOG_ENABLED
#define __MODULE_ID__					FILE_MODULE
#else
#define __MODULE_ID__					0
#endif

#include <jcal.h>
 //#include <jdi_cutils.h>

#define MAX_MODULE_NAME_SIZE			200

JC_RETCODE DirDeleteAll (JDD_FSHANDLE fileSysHandle, const JC_CHAR * psargDirName) ;


// This function needs to be invoked by the application before calling any of the file api calls.
// Here in Win32 Platform it does not support that is why we return it JC_OK.

JC_RETCODE	jdd_FSInitialize (JDD_FSHANDLE * pFileSysHandle)
{
	PARAM_INTENTIONALLY_NOT_USED (pFileSysHandle) ;

	*pFileSysHandle = JC_NULL ;
	return JC_OK ;
}

// This is the function to deinitialize the file system handle and after this call 
// fileSysHandle shall not be used by the other file interface API calls. 
// Here in Win32 Platform it does not support that is why we return it JC_OK.
JC_RETCODE  jdd_FSDeinitialize (JDD_FSHANDLE fileSysHandle)
{
	PARAM_INTENTIONALLY_NOT_USED (fileSysHandle) ;
	return JC_OK ;
}

// This function is responsible for opening the specified file name. 
// On success the opened file reference is returned otherwise NULL.

JDD_FILE  jdd_FSOpen  (JDD_FSHANDLE fileSysHandle, 
							const JC_CHAR * psargFileName,
							EFileOpenMode eOpenMode)
{
	JC_RETCODE eRet = JC_OK;
    FILE *pFile = NULL;        

	PARAM_INTENTIONALLY_NOT_USED (fileSysHandle) ;

	switch (eOpenMode)
	{
		case E_OPEN_READ_MODE :
			_wfopen_s (&pFile, psargFileName, TEXT("rb")) ; 
			break ;

		case E_OPEN_READ_WRITE_MODE :
			//open read-write if the file exists
			_wfopen_s (&pFile, psargFileName, TEXT("rb+")) ; 
			break ;

		case E_CREATE_WRITE_MODE :
			//create a new file, or if already exists truncate existing, write mode
			_wfopen_s (&pFile, psargFileName, TEXT("wb")) ; 
			break ;

		case E_CREATE_WRITE_READ_MODE :
			//create a new file, or if already exists truncate existing, read-write mode
			_wfopen_s (&pFile, psargFileName, TEXT("wb+")) ; 
			break ;

		case E_CREATE_APPEND_WRITE_MODE :
			//if the file exists open it or create a new file, write mode
			_wfopen_s (&pFile, psargFileName, TEXT("ab")) ; 
			break ;

		case E_CREATE_APPEND_WRITE_READ_MODE :
			//if the file exists open it or create a new file, read-write mode
			_wfopen_s (&pFile, psargFileName, TEXT("ab+")) ; 
			break ;
	}

	return pFile;
}

// This function is responsible for closing the opened file specified by the fileHandle. 

JC_RETCODE jdd_FSClose (JDD_FILE fileHandle)
{
	if (NULL == fileHandle)
	{
		return JC_ERR_INVALID_PARAMETER;
	}

	if (fclose((FILE *)fileHandle))
	{
		return JC_ERR_FILE_CLOSE ;
	}
	return JC_OK ;
}

// This function writes the given number of items to the file and returns 
// the number of items successfully written to file. On failure it returns JC_ERR_FILE_WRITE.

JC_INT32 jdd_FSWrite (const void * pWriteBuf, const JC_UINT32 uiItemSize, 
						const JC_UINT32 uiItems, JDD_FILE fileHandle)
{
	JC_UINT32 uiItemsWritten ;

	if (NULL == pWriteBuf || NULL == fileHandle)
	{
		return -1;
	}

	uiItemsWritten = (JC_UINT32)fwrite(pWriteBuf, (size_t)uiItemSize, (size_t)uiItems,(FILE *)fileHandle);	
	if (uiItems > uiItemsWritten)
	{
		return -1;
	}

	fflush (NULL);

	return uiItemsWritten ;
}

// This function flushes any data in the memory for the referred file to the persistent storage.

JC_RETCODE jdd_FSFlush (JDD_FILE fileHandle)
{ 
	if (NULL == fileHandle)
	{
		return JC_ERR_INVALID_PARAMETER;
	}

	if (fflush((FILE *)fileHandle))
		return JC_ERR_FILE_FLUSH;

	return JC_OK;
}

// This function reads the required number of items from the file and returns the number of items 
// successfully read from the file. On failure it returns JC_ERR_FILE_READ error code.

JC_INT32 jdd_FSRead  (void *pReadBuf, const JC_UINT32 uiItemSize, 
						const JC_UINT32 uiItems, JDD_FILE fileHandle)
{
	JC_UINT32 uiBytesRead ;

	if (NULL == pReadBuf || NULL == fileHandle)
	{
		return -1;
	}

	uiBytesRead = (JC_UINT32)fread(pReadBuf,uiItemSize,uiItems,(FILE *)fileHandle);	
	if (0 == uiBytesRead)
	{
		return -1;
	}

	return uiBytesRead ;
}

// This function sets the file pointer at specified position. The new position is 
// calculated from the offset bytes to the position specified by eFromWhere. 

JC_RETCODE jdd_FSSeek (JDD_FILE fileHandle, const JC_INT32 iPos, 
					  EFileSeekMode eFromwhere)
{
	FILE *pFile = (FILE *)fileHandle;
	if (NULL == fileHandle)
	{
		return JC_ERR_INVALID_PARAMETER ;
	}

	switch (eFromwhere)
	{
		case E_FILE_SEEK_SET :
			if (fseek(pFile,iPos,SEEK_SET))
				return JC_ERR_FILE_SEEK;
			break ;
		case E_FILE_SEEK_CUR :
			if (fseek(pFile,iPos,SEEK_CUR))
				return JC_ERR_FILE_SEEK;
			break ;
		case E_FILE_SEEK_END :
			if (fseek(pFile,iPos,SEEK_END))
				return JC_ERR_FILE_SEEK;
			break ;
		default :
			return JC_ERR_INVALID_PARAMETER ;
	}	

	return JC_OK ;
}

// These functions determine the file size in bytes. If success the *puiFileSize contains the size 
// of the file else assigns *puiFileSize with 0.

JC_RETCODE jdd_FSGetSize (JDD_FILE fileHandle, JC_UINT32 *puiFileSize)
{
	FILE *pFile = (FILE *)fileHandle;
	JC_INT64 lFileSize = 0 ;
	*puiFileSize = 0;

	if (NULL == fileHandle)
	{
		return JC_ERR_INVALID_PARAMETER ;
	}

	fseek (pFile,0,SEEK_END);

	lFileSize = ftell(pFile);

	fseek (pFile,0,SEEK_SET);

	if (-1 == lFileSize)
	{
		return JC_ERR_FILE_SIZE ;
	}

	*puiFileSize = (JC_UINT32)lFileSize;

	return JC_OK ;
}

// This function sets the file position indicator to the beginning of the file stream.
// error for the rewind
JC_RETCODE jdd_FSRewind (JDD_FILE fileHandle)
{
	JC_INT32 iReturn = 0 ;

	if (NULL == fileHandle)
	{
		return JC_ERR_INVALID_PARAMETER ;
	}

	iReturn = fseek((FILE *)fileHandle,0,SEEK_SET);		

	if (0 != iReturn)
	{
		return JC_ERR_FILE_SEEK;   
	}

	return JC_OK ;
}

// This function checks if the specified file exists or not. 

JC_BOOLEAN jdd_FSIsFileExist (JDD_FSHANDLE fileSysHandle, JC_CHAR * psargFileName)
{
	JC_BOOLEAN bFileExist;
	FILE *file;

	_wfopen_s(&file, psargFileName, TEXT("r"));

	bFileExist = E_TRUE;
	if(!file)
	{
		bFileExist = E_FALSE;
	}

	fclose(file);

	return bFileExist;
}


// These functions determine the file size in bytes. If success the *puiFileSize contains the size 
// of the file and in case of failure *puiFileSize contains 0.

JC_RETCODE jdd_FSGetFileSize (JDD_FSHANDLE fileSysHandle, JC_CHAR * psargFileName, 
							  JC_UINT32 *puiFileSize)
{
	FILE *fp = NULL;
	JC_RETCODE eRet = JC_OK;
	JC_INT64 lFileSize = 0 ;

	*puiFileSize = 0;

	PARAM_INTENTIONALLY_NOT_USED (fileSysHandle) ;


	_wfopen_s(&fp, psargFileName, TEXT("r"));

	fseek (fp,0,SEEK_END);

	lFileSize = ftell(fp);

	fseek (fp,0,SEEK_SET);

	if (-1 == lFileSize)
	{
		fclose(fp);
		return JC_ERR_FILE_SIZE ;
	}

	fclose(fp);
	*puiFileSize = (JC_UINT32)lFileSize;

	return eRet ;
}

// This function creates a directory with the specified name.

JC_RETCODE jdd_FSMakeDir (JDD_FSHANDLE fileSysHandle, const JC_CHAR * psargDirName)
{
	return JC_ERR_NOT_IMPLEMENTED;
}


// This function change the current directory path to the one specified. 

JC_RETCODE jdd_FSChDir (JDD_FSHANDLE fileSysHandle, const JC_CHAR * psargDirName)
{
	return JC_ERR_NOT_IMPLEMENTED;
}

// This function deletes the directory that is specified in the arguement.

JC_RETCODE jdd_FSDelDir (JDD_FSHANDLE fileSysHandle, const JC_CHAR * psargDirName)
{
return JC_ERR_NOT_IMPLEMENTED;
}

// This function parses through the directory and deletes all the contents.

JC_RETCODE DirDeleteAll (JDD_FSHANDLE fileSysHandle, const JC_CHAR * psargDirName)
{
	return JC_ERR_NOT_IMPLEMENTED;
}

// This function renames the old(source) Directory name specified to the new(destination) Directory name.

JC_RETCODE jdd_FSDirRename (JDD_FSHANDLE fileSysHandle, const JC_CHAR * psargSrcDirName, 
							const JC_CHAR * psargDestDirName)
{
	return JC_ERR_NOT_IMPLEMENTED;
}
 
// This function checks if the specified Directory exists or not. 

JC_BOOLEAN jdd_FSIsDirExist (JDD_FSHANDLE fileSysHandle, const JC_CHAR * psargDirName)
{
	return JC_ERR_NOT_IMPLEMENTED;
}

// This function deletes the specified file. 

JC_RETCODE jdd_FSDelete (JDD_FSHANDLE fileSysHandle, const JC_CHAR * psargFileName)
{
	JC_RETCODE eRet = JC_OK;

	PARAM_INTENTIONALLY_NOT_USED (fileSysHandle) ;

	if (-1 == _wremove(psargFileName))
	{
		return JC_ERR_FILE_DELETE;
	}

	return eRet ;
}

// This function renames the old(source) file name specified to the new(destination) file name.

JC_RETCODE jdd_FSRename (JDD_FSHANDLE fileSysHandle, const JC_CHAR * psargSrcFileName, 
							const JC_CHAR * psargDestFileName)
{
	JC_RETCODE eRet = JC_OK;
	JC_INT8 *psSrcFileName = NULL;
	JC_INT8 *psDestFileName = NULL;

	PARAM_INTENTIONALLY_NOT_USED (fileSysHandle) ;

	if ( 0 != _wrename(psargSrcFileName, psargDestFileName))
	{
		eRet = JC_ERR_FILE_RENAME;
	}

	return eRet;
}

/* @fn jdd_FSGetRootDirectory 
 * @brief
 *    This function copies the root directory to pmRootDirectory.If the param pmRootDirectory 
 * is NULL or puiDirSize is lessthan the reqired size then it fills the puiDirSize with the 
 * reqired size and returns the error code JC_ERR_CFG_INSUFFICIENT_MEMORY.
 */
JC_RETCODE jdd_FSGetRootDirectory (JC_CHAR *pmRootDirectory, JC_UINT32 *puiDirSize)
{
	return JC_ERR_NOT_IMPLEMENTED;
}

/***************************************************************************
* All Global Function Definitions
**************************************************************************/


/* END OF FILE */

⌨️ 快捷键说明

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