1289715Sglebius 2289715Sglebius#include "config.h" 3289715Sglebius#include "stdlib.h" 4289715Sglebius#include "sntptest.h" 5289715Sglebius 6294569Sdelphij#include "fileHandlingTest.h" /* required because of the h.in thingy */ 7289715Sglebius 8289715Sglebius#include <string.h> 9289715Sglebius#include <unistd.h> 10289715Sglebius 11289715Sglebiusconst char * 12294569SdelphijCreatePath( 13294569Sdelphij const char * filename, 14294569Sdelphij enum DirectoryType argument 15294569Sdelphij ) 16294569Sdelphij{ 17294569Sdelphij const char srcdir[] = SRCDIR_DEF;//"@abs_srcdir@/data/"; 18294569Sdelphij size_t plen = sizeof(srcdir) + strlen(filename) + 1; 19294569Sdelphij char * path = emalloc(plen); 20294569Sdelphij ssize_t retc; 21289715Sglebius 22294569Sdelphij UNUSED_ARG(argument); 23289715Sglebius 24294569Sdelphij retc = snprintf(path, plen, "%s%s", srcdir, filename); 25294569Sdelphij if (retc <= 0 || (size_t)retc >= plen) 26294569Sdelphij exit(1); 27289715Sglebius return path; 28289715Sglebius} 29289715Sglebius 30289715Sglebius 31294569Sdelphijvoid 32294569SdelphijDestroyPath( 33294569Sdelphij const char * pathname 34294569Sdelphij ) 35294569Sdelphij{ 36294569Sdelphij /* use a union to get terminally rid of the 'const' attribute */ 37294569Sdelphij union { 38294569Sdelphij const char *ccp; 39294569Sdelphij void *vp; 40294569Sdelphij } any; 41294569Sdelphij 42294569Sdelphij any.ccp = pathname; 43294569Sdelphij free(any.vp); 44294569Sdelphij} 45294569Sdelphij 46294569Sdelphij 47289715Sglebiusint 48294569SdelphijGetFileSize( 49294569Sdelphij FILE * file 50294569Sdelphij ) 51294569Sdelphij{ 52289715Sglebius fseek(file, 0L, SEEK_END); 53289715Sglebius int length = ftell(file); 54289715Sglebius fseek(file, 0L, SEEK_SET); 55289715Sglebius 56289715Sglebius return length; 57289715Sglebius} 58289715Sglebius 59289715Sglebius 60289715Sglebiusbool 61294569SdelphijCompareFileContent( 62294569Sdelphij FILE * expected, 63294569Sdelphij FILE * actual 64294569Sdelphij ) 65294569Sdelphij{ 66289715Sglebius int currentLine = 1; 67289715Sglebius 68289715Sglebius char actualLine[1024]; 69289715Sglebius char expectedLine[1024]; 70289715Sglebius size_t lenAct = sizeof actualLine; 71289715Sglebius size_t lenExp = sizeof expectedLine; 72289715Sglebius 73289715Sglebius while ( ( (fgets(actualLine, lenAct, actual)) != NULL) 74289715Sglebius && ( (fgets(expectedLine, lenExp, expected)) != NULL ) 75289715Sglebius ) { 76289715Sglebius 77289715Sglebius 78289715Sglebius if( strcmp(actualLine,expectedLine) !=0 ){ 79289715Sglebius printf("Comparision failed on line %d",currentLine); 80289715Sglebius return FALSE; 81289715Sglebius } 82289715Sglebius 83289715Sglebius currentLine++; 84289715Sglebius } 85289715Sglebius 86289715Sglebius return TRUE; 87289715Sglebius} 88289715Sglebius 89289715Sglebius 90289715Sglebiusvoid 91294569SdelphijClearFile( 92294569Sdelphij const char * filename 93294569Sdelphij ) 94294569Sdelphij{ 95289715Sglebius if (!truncate(filename, 0)) 96289715Sglebius exit(1); 97289715Sglebius} 98