1289715Sglebius 2289715Sglebius#include "config.h" 3289715Sglebius#include "stdlib.h" 4289715Sglebius#include "sntptest.h" 5289715Sglebius 6294904Sdelphij#include "fileHandlingTest.h" /* required because of the h.in thingy */ 7289715Sglebius 8289715Sglebius#include <string.h> 9289715Sglebius#include <unistd.h> 10289715Sglebius 11289715Sglebiusconst char * 12294904SdelphijCreatePath( 13294904Sdelphij const char * filename, 14294904Sdelphij enum DirectoryType argument 15294904Sdelphij ) 16294904Sdelphij{ 17294904Sdelphij const char srcdir[] = SRCDIR_DEF;//"@abs_srcdir@/data/"; 18294904Sdelphij size_t plen = sizeof(srcdir) + strlen(filename) + 1; 19294904Sdelphij char * path = emalloc(plen); 20294904Sdelphij ssize_t retc; 21289715Sglebius 22294904Sdelphij UNUSED_ARG(argument); 23289715Sglebius 24294904Sdelphij retc = snprintf(path, plen, "%s%s", srcdir, filename); 25294904Sdelphij if (retc <= 0 || (size_t)retc >= plen) 26294904Sdelphij exit(1); 27289715Sglebius return path; 28289715Sglebius} 29289715Sglebius 30289715Sglebius 31294904Sdelphijvoid 32294904SdelphijDestroyPath( 33294904Sdelphij const char * pathname 34294904Sdelphij ) 35294904Sdelphij{ 36294904Sdelphij /* use a union to get terminally rid of the 'const' attribute */ 37294904Sdelphij union { 38294904Sdelphij const char *ccp; 39294904Sdelphij void *vp; 40294904Sdelphij } any; 41294904Sdelphij 42294904Sdelphij any.ccp = pathname; 43294904Sdelphij free(any.vp); 44294904Sdelphij} 45294904Sdelphij 46294904Sdelphij 47289715Sglebiusint 48294904SdelphijGetFileSize( 49294904Sdelphij FILE * file 50294904Sdelphij ) 51294904Sdelphij{ 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 61294904SdelphijCompareFileContent( 62294904Sdelphij FILE * expected, 63294904Sdelphij FILE * actual 64294904Sdelphij ) 65294904Sdelphij{ 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 91294904SdelphijClearFile( 92294904Sdelphij const char * filename 93294904Sdelphij ) 94294904Sdelphij{ 95289715Sglebius if (!truncate(filename, 0)) 96289715Sglebius exit(1); 97289715Sglebius} 98