Deleted Added
full compact
fileHandlingTest.c (289764) fileHandlingTest.c (294554)
1
2#include "config.h"
3#include "stdlib.h"
4#include "sntptest.h"
5
1
2#include "config.h"
3#include "stdlib.h"
4#include "sntptest.h"
5
6#include "fileHandlingTest.h" //required because of the h.in thingy
6#include "fileHandlingTest.h" /* required because of the h.in thingy */
7
8#include <string.h>
9#include <unistd.h>
10
7
8#include <string.h>
9#include <unistd.h>
10
11/*
12enum DirectoryType {
13 INPUT_DIR = 0,
14 OUTPUT_DIR = 1
15};
16*/
17//extern const char srcdir[];
18
19const char *
11const char *
20CreatePath(const char* filename, enum DirectoryType argument) {
21 const char srcdir[] = SRCDIR_DEF;//"@abs_srcdir@/data/";
22 char * path = emalloc (sizeof (char) * (strlen(srcdir) + 256));
12CreatePath(
13 const char * filename,
14 enum DirectoryType argument
15 )
16{
17 const char srcdir[] = SRCDIR_DEF;//"@abs_srcdir@/data/";
18 size_t plen = sizeof(srcdir) + strlen(filename) + 1;
19 char * path = emalloc(plen);
20 ssize_t retc;
23
21
24 //char cwd[1024];
22 UNUSED_ARG(argument);
25
23
26 strcpy(path, srcdir);
27 strcat(path, filename);
28
24 retc = snprintf(path, plen, "%s%s", srcdir, filename);
25 if (retc <= 0 || (size_t)retc >= plen)
26 exit(1);
29 return path;
30}
31
32
27 return path;
28}
29
30
31void
32DestroyPath(
33 const char * pathname
34 )
35{
36 /* use a union to get terminally rid of the 'const' attribute */
37 union {
38 const char *ccp;
39 void *vp;
40 } any;
41
42 any.ccp = pathname;
43 free(any.vp);
44}
45
46
33int
47int
34GetFileSize(FILE *file) {
48GetFileSize(
49 FILE * file
50 )
51{
35 fseek(file, 0L, SEEK_END);
36 int length = ftell(file);
37 fseek(file, 0L, SEEK_SET);
38
39 return length;
40}
41
42
43bool
52 fseek(file, 0L, SEEK_END);
53 int length = ftell(file);
54 fseek(file, 0L, SEEK_SET);
55
56 return length;
57}
58
59
60bool
44CompareFileContent(FILE* expected, FILE* actual) {
61CompareFileContent(
62 FILE * expected,
63 FILE * actual
64 )
65{
45 int currentLine = 1;
46
47 char actualLine[1024];
48 char expectedLine[1024];
49 size_t lenAct = sizeof actualLine;
50 size_t lenExp = sizeof expectedLine;
51
52 while ( ( (fgets(actualLine, lenAct, actual)) != NULL)

--- 9 unchanged lines hidden (view full) ---

62 currentLine++;
63 }
64
65 return TRUE;
66}
67
68
69void
66 int currentLine = 1;
67
68 char actualLine[1024];
69 char expectedLine[1024];
70 size_t lenAct = sizeof actualLine;
71 size_t lenExp = sizeof expectedLine;
72
73 while ( ( (fgets(actualLine, lenAct, actual)) != NULL)

--- 9 unchanged lines hidden (view full) ---

83 currentLine++;
84 }
85
86 return TRUE;
87}
88
89
90void
70ClearFile(const char * filename) {
91ClearFile(
92 const char * filename
93 )
94{
71 if (!truncate(filename, 0))
72 exit(1);
73}
95 if (!truncate(filename, 0))
96 exit(1);
97}
74