PUBLIC _Bool eml_dupqfile(char *qfilename,const char *dest)
{
+#define OPEP "unieml.c:eml_dupqfile,"
_Bool status;
+char *filename;
+FILE *fin;
+FILE *fout;
+int phase;
+_Bool proceed;
status=false;
+filename=rou_apppath(QDIR);
+fin=(FILE *)0;
+fout=(FILE *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
+ switch (phase) {
+ case 0 : //lets open the queue directory
+ if ((qfilename==(char *)0)||(dest==(char *)0)) {
+ (void) rou_alert(0,"%s filename=<%s> or dest=<%s> missing (Bug?)",
+ OPEP,qfilename,dest);
+ phase=999; //Big trouble
+ }
+ break;
+ case 1 : //opening origin file
+ if (qfilename!=(char *)0) { //always
+ char name[300];
+
+ (void) snprintf(name,sizeof(name),"%s/%s",filename,qfilename);
+ if ((fin=fopen(name,"r"))==(FILE *)0) {
+ (void) rou_alert(0,"%s unable to open source <%s> (error=<%s>)",
+ OPEP,name,strerror(errno));
+ phase=999; //Big trouble
+ }
+ }
+ break;
+ case 2 : //opening destination file
+ if (fin!=(FILE *)0) { //always
+ char name[300];
+
+ (void) snprintf(name,sizeof(name),"%s/%s",dest,qfilename);
+ if ((fout=fopen(name,"w"))==(FILE *)0) {
+ (void) rou_alert(0,"%s unable to open destination <%s> (error=<%s>)",
+ OPEP,name,strerror(errno));
+ (void) fclose(fin);
+ phase=999; //Big trouble
+ }
+ }
+ break;
+ case 3 : //duplicating file
+ if (fout!=(FILE *)0) {
+ int count;
+ char buffer[2048];
+
+ while ((count=fread(buffer,sizeof(char),sizeof(buffer),fin))>0) {
+ if (fwrite(buffer,sizeof(char),count,fout)!=count) {
+ (void) rou_alert(0,"%s unable to fully write destination (error=<%s>)",
+ OPEP,strerror(errno));
+ phase=999;
+ }
+ }
+ (void) fclose(fout);
+ (void) fclose(fin);
+ }
+ break;
+ case 4 : //duplication is a success
+ status=true;
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+filename=rou_freestr(filename);
return status;
+#undef OPEP
}
/*
^L