Exemplo n.º 1
0
int more_cmd(int argc, char **argv, FF_ENVIRONMENT *pEnv) {
	FF_FILE		*f;
	FF_ERROR	Error;
	FF_T_SINT32	c;
	FF_T_INT8	path[FF_MAX_PATH];

	if(argc == 2) {

		ProcessPath(path, argv[1], pEnv);

		f = FF_Open(pEnv->pIoman, path, FF_MODE_READ, &Error);
		if(f) {
			printf("//---------- START OF FILE\n");
			while(!FF_isEOF(f)) {
				c = FF_GetC(f);
				if(c >= 0) {
					printf("%c", (FF_T_INT8) c);
				} else {
					printf("Error while reading file: %s\n", FF_GetErrMessage(c));
					FF_Close(f);
					return -3;
				}
			}
			printf("\n//---------- END OF FILE\n");

			FF_Close(f);
		} else {
			printf("Could not open file: %s\n", FF_GetErrMessage(Error));
			return -2;
		}
	} else {
		printf("Usage: %s [filename]\n", argv[0]);
	}
	return 0;
}
Exemplo n.º 2
0
static BT_s32 fullfat_getc(BT_HANDLE hFile, BT_u32 ulFlags, BT_ERROR *pError) {

	BT_FF_FILE *pFile = (BT_FF_FILE *) hFile;

	FF_T_SINT32 ret = FF_GetC(pFile->pFile);

	return ret;
}
Exemplo n.º 3
0
int test_7(FF_IOMAN *pIoman, TEST_PARAMS *pParams) {
	FF_FILE *pFile;
	FF_ERROR Error;
	int i;
	int c;
	unsigned long size = pIoman->pPartition->SectorsPerCluster * pIoman->pPartition->BlkSize;
	unsigned long startSize;
	char test[] = "Another simple sentence.";
	

	pFile = FF_Open(pIoman, "\\test.7.dat", FF_GetModeBits("a+"), &Error);
	if(!pFile) { CHECK_ERR(Error) }

	startSize = pFile->Filesize;

	for(i = startSize; i < (size * 3)+startSize; i++) {
		Error = FF_PutC(pFile, test[i % (sizeof(test)-1)]);
	}

	Error = FF_Close(pFile);
	CHECK_ERR(Error);

	pFile = FF_Open(pIoman, "\\test.7.dat", FF_GetModeBits("rb"), &Error);
	if(!pFile) { CHECK_ERR(Error) }

	i = 0;

	do {
		c = FF_GetC(pFile);
		if(c >= 0) {
			if(c != test[i++ % (sizeof(test)-1)]) {
				sprintf(pParams->errBuf, "Char at offset: %d does not match input.\n", i);
				*pParams->pszpMessage = pParams->errBuf;
				FF_Close(pFile);
				DO_FAIL;
			}
		}
	} while(c >= 0);

	FF_Close(pFile);

	return PASS;
}
Exemplo n.º 4
0
/**
 * @public
 * @brief	Gets a Line from a Text File, but no more than ulLimit charachters. The line will be NULL terminated.
 *
 *			The behaviour of this function is undefined when called on a binary file.
 *			It should just read in ulLimit bytes of binary, and ZERO terminate the line.
 *
 *			This function works for both UNIX line feeds, and Windows CRLF type files.
 *
 * @param	pFile	The FF_FILE object pointer.
 * @param	szLine	The charachter buffer where the line should be stored.
 * @param	ulLimit	This should be the max number of charachters that szLine can hold.
 *
 * @return	The number of charachters read from the line, on success.
 * @return	0 when no more lines are available, or when ulLimit is 0.
 * @return	FF_ERR_NULL_POINTER if pFile or szLine are NULL;
 *
 **/
FF_T_SINT32 FF_GetLine(FF_FILE *pFile, FF_T_INT8 *szLine, FF_T_UINT32 ulLimit) {
	FF_T_SINT32 c;
	FF_T_UINT32 i;

	if(!pFile || !szLine) {
		return FF_ERR_NULL_POINTER;
	}

	for(i = 0; i < (ulLimit - 1) && (c=FF_GetC(pFile)) >= 0 && c != '\n'; ++i) {
		if(c == '\r') {
			i--;
		} else {
			szLine[i] = (FF_T_INT8) c;
		}
	}

	szLine[i] = '\0';
	return i;
}