diff options
author | Renato Botelho <renato@netgate.com> | 2016-01-25 08:56:15 -0200 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2016-01-25 08:56:15 -0200 |
commit | eb84e0723f3b4bc5e40024f66fe21c14b09e9ec4 (patch) | |
tree | fec6b99d018e13f1fccbe31478aaf29a28a55642 /contrib/ntp/sntp/tests/fileHandlingTest.c | |
parent | c50df8e1b90c4f9b8bbffa592477c129854776ce (diff) | |
parent | 94b1bbbd44bd88b6db1c00d795cdf7675b3ae254 (diff) | |
download | FreeBSD-src-eb84e0723f3b4bc5e40024f66fe21c14b09e9ec4.zip FreeBSD-src-eb84e0723f3b4bc5e40024f66fe21c14b09e9ec4.tar.gz |
Merge remote-tracking branch 'origin/stable/10' into devel
Diffstat (limited to 'contrib/ntp/sntp/tests/fileHandlingTest.c')
-rw-r--r-- | contrib/ntp/sntp/tests/fileHandlingTest.c | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/contrib/ntp/sntp/tests/fileHandlingTest.c b/contrib/ntp/sntp/tests/fileHandlingTest.c index ce3f0de..8acad54 100644 --- a/contrib/ntp/sntp/tests/fileHandlingTest.c +++ b/contrib/ntp/sntp/tests/fileHandlingTest.c @@ -3,35 +3,52 @@ #include "stdlib.h" #include "sntptest.h" -#include "fileHandlingTest.h" //required because of the h.in thingy +#include "fileHandlingTest.h" /* required because of the h.in thingy */ #include <string.h> #include <unistd.h> -/* -enum DirectoryType { - INPUT_DIR = 0, - OUTPUT_DIR = 1 -}; -*/ -//extern const char srcdir[]; - const char * -CreatePath(const char* filename, enum DirectoryType argument) { - const char srcdir[] = SRCDIR_DEF;//"@abs_srcdir@/data/"; - char * path = emalloc (sizeof (char) * (strlen(srcdir) + 256)); - - //char cwd[1024]; +CreatePath( + const char * filename, + enum DirectoryType argument + ) +{ + const char srcdir[] = SRCDIR_DEF;//"@abs_srcdir@/data/"; + size_t plen = sizeof(srcdir) + strlen(filename) + 1; + char * path = emalloc(plen); + ssize_t retc; + + UNUSED_ARG(argument); + + retc = snprintf(path, plen, "%s%s", srcdir, filename); + if (retc <= 0 || (size_t)retc >= plen) + exit(1); + return path; +} - strcpy(path, srcdir); - strcat(path, filename); - return path; +void +DestroyPath( + const char * pathname + ) +{ + /* use a union to get terminally rid of the 'const' attribute */ + union { + const char *ccp; + void *vp; + } any; + + any.ccp = pathname; + free(any.vp); } int -GetFileSize(FILE *file) { +GetFileSize( + FILE * file + ) +{ fseek(file, 0L, SEEK_END); int length = ftell(file); fseek(file, 0L, SEEK_SET); @@ -41,7 +58,11 @@ GetFileSize(FILE *file) { bool -CompareFileContent(FILE* expected, FILE* actual) { +CompareFileContent( + FILE * expected, + FILE * actual + ) +{ int currentLine = 1; char actualLine[1024]; @@ -67,8 +88,10 @@ CompareFileContent(FILE* expected, FILE* actual) { void -ClearFile(const char * filename) { +ClearFile( + const char * filename + ) +{ if (!truncate(filename, 0)) exit(1); } - |