summaryrefslogtreecommitdiffstats
path: root/libsensors_iio/software/simple_apps/common/fopenCMake.c
diff options
context:
space:
mode:
Diffstat (limited to 'libsensors_iio/software/simple_apps/common/fopenCMake.c')
-rw-r--r--libsensors_iio/software/simple_apps/common/fopenCMake.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/libsensors_iio/software/simple_apps/common/fopenCMake.c b/libsensors_iio/software/simple_apps/common/fopenCMake.c
new file mode 100644
index 0000000..2936109
--- /dev/null
+++ b/libsensors_iio/software/simple_apps/common/fopenCMake.c
@@ -0,0 +1,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;
+}
+
+