blob: 293610968dd2cb55f65d31970ebf86e6336c0be0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/*
$License:
Copyright (C) 2011 InvenSense Corporation, All Rights Reserved.
$
*/
/******************************************************************************
*
* $Id: fopenCMake.c 5629 2011-06-11 03:13:08Z mcaramello $
*
*****************************************************************************/
#include <string.h>
#include "fopenCMake.h"
#include "path_configure.h"
/**
* @brief Replacement for fopen that concatenates the location of the
* source tree onto the filename path.
* It looks in 3 locations:
* - in the current directory,
* - then it looks in "..",
* - lastly in the define UNITTEST_SOURCE_DIR which
* gets defined by CMake.
* @param filename
* Filename relative to base of source directory.
* @param prop
* Second argument to fopen.
*/
FILE *fopenCMake(const char *filename, const char *prop)
{
char path[150];
FILE *file;
// Look first in current directory
file = fopen(filename, prop);
if (file == NULL) {
// Now look in ".."
#ifdef WIN32
strcpy(path, "..\\");
#else
strcpy(path, "../");
#endif
strcat(path, filename);
file = fopen(path, prop);
if (file == NULL) {
// Now look in definition by CMake
strcpy(path, PATH_SOURCE_DIR);
strcat(path, filename);
file = fopen(path, prop);
}
}
return file;
}
|