1 /* $NetBSD: fileHandlingTest.c,v 1.1.1.1 2015/10/23 17:47:43 christos Exp $ */ 2 3 4 #include "config.h" 5 #include "stdlib.h" 6 #include "sntptest.h" 7 8 #include "fileHandlingTest.h" //required because of the h.in thingy 9 10 #include <string.h> 11 #include <unistd.h> 12 13 /* 14 enum DirectoryType { 15 INPUT_DIR = 0, 16 OUTPUT_DIR = 1 17 }; 18 */ 19 //extern const char srcdir[]; 20 21 const char * 22 CreatePath(const char* filename, enum DirectoryType argument) { 23 const char srcdir[] = SRCDIR_DEF;//"@abs_srcdir@/data/"; 24 char * path = emalloc (sizeof (char) * (strlen(srcdir) + 256)); 25 26 //char cwd[1024]; 27 28 strcpy(path, srcdir); 29 strcat(path, filename); 30 31 return path; 32 } 33 34 35 int 36 GetFileSize(FILE *file) { 37 fseek(file, 0L, SEEK_END); 38 int length = ftell(file); 39 fseek(file, 0L, SEEK_SET); 40 41 return length; 42 } 43 44 45 bool 46 CompareFileContent(FILE* expected, FILE* actual) { 47 int currentLine = 1; 48 49 char actualLine[1024]; 50 char expectedLine[1024]; 51 size_t lenAct = sizeof actualLine; 52 size_t lenExp = sizeof expectedLine; 53 54 while ( ( (fgets(actualLine, lenAct, actual)) != NULL) 55 && ( (fgets(expectedLine, lenExp, expected)) != NULL ) 56 ) { 57 58 59 if( strcmp(actualLine,expectedLine) !=0 ){ 60 printf("Comparision failed on line %d",currentLine); 61 return FALSE; 62 } 63 64 currentLine++; 65 } 66 67 return TRUE; 68 } 69 70 71 void 72 ClearFile(const char * filename) { 73 if (!truncate(filename, 0)) 74 exit(1); 75 } 76 77