<<<< Working CODE >>>>
Code:
/*
Will BE MULTITHREADED
open a original file (source file)
Look for the existing custom folder in the HOME directory
If the HOME directory does not exist
Then see if the specs exists in the /usr/local/share (Default)
If the /usr/local/share does not exist then create a template
create a temp
*/
#include <cliargs.h>
short get_Stream(FILE* pSource,char* result);
char* get_Copy(char* pStr);
char* get_Copy(char* pStr){
char *final=0;
char byte = 0;
char dummy = 0;
final = &dummy;
*final = '\0';
char *temp=0;temp = pStr;
//initilize the contents with new address
do{ byte = *temp;
*final = &byte;
final++; temp++;
}while(byte!='\0');
final++;
*final='\0';
temp = 0;
if(pStr!=NULL){
temp = pStr;
final = strcpy(final,temp);}else final="";
return final;
}//EOF
short get_Stream(FILE* pSource,char* result){
size_t buflen = 0;
char offset= 0;
int ret=EXIT_SUCCESS;
fpos_t* pCurPos=0 ; //current file position
fpos_t* pOldPos=0 ; //old file position
char *finally = 0;
const char *buffer = 0;
//get the starting File pointer position
fgetpos(pSource,&pOldPos);
//find the newline = 0x13
//0F == 15
//0E == 14
//0D == 13
//0C == 12
//0B == 11
//0A == 10
do{offset=0; offset=fgetc(pSource); }
while(offset!=0x0A && offset!=0x0D && offset!=EOF && offset!=NULL);
//Are we at end of the file?
if(offset == EOF || offset==NULL)
ret= EXIT_FAILURE;
else{
//get the Current File position
fgetpos (pSource,&pCurPos);
//Total Buffer Length
buflen = (size_t)pCurPos - (size_t)pOldPos;
if(buflen == EXIT_FAILURE){buflen=buflen+1;ret = EXIT_FAILURE;}
else{
ret=EXIT_SUCCESS;
//Reset Everything
fsetpos (pSource,&pOldPos);
//allocate memory for the new address register
buffer = (const char *)malloc(buflen);
//read file buffer using fgets
if(fgets(buffer,buflen,pSource)!=NULL)
//copy the string to a automatic variable register
finally = get_Copy(buffer);
//free the contents
free(buffer);
printf("%s",finally);
}//ELSE
}//ELSE
buffer=0;
pCurPos = 0;
pOldPos = 0;
return ret;
}//EOF
int main(int argc,const char* argv[]){
struct FileSettings{
// DIR *pFolder;
FILE* rTmpFile;
FILE* rSourceFile;
const char* ATOMIC_NAME;
};
struct FileSettings *pSetting=0;
char* ret="";
pSetting = (struct FileSettings *)malloc(sizeof(struct FileSettings));
pSetting->ATOMIC_NAME = "/home/generic/config.log";
pSetting->rSourceFile = fopen(pSetting->ATOMIC_NAME,"rb");
if(pSetting->rSourceFile==NULL){
printf("File not found");
}
else{
fseek(pSetting->rSourceFile,SEEK_SET,SEEK_SET);
while(feof(pSetting->rSourceFile)==EXIT_SUCCESS)
if(get_Stream(pSetting->rSourceFile,ret)==EXIT_SUCCESS){
printf("\n");
}
}
fclose(pSetting->rSourceFile);
free(pSetting);
}//End of Main Application
To quazah:
I do not think you have understood the main purpose of the function get_Copy() have you?
Stage 2
Besides all this; in the driver_module in the line:
How do I make this a reality?
Code:
if(get_Stream(pSetting->rSourceFile,ret)==EXIT_SUCCESS){
printf("\n" ,ret );
}