diff --git a/src/meson.build b/src/meson.build index f916890..e0fe1f4 100644 --- a/src/meson.build +++ b/src/meson.build @@ -25,6 +25,7 @@ sources = [ 'accel-mount-matrix.c', 'accel-scale.c', 'accel-attributes.c', + 'utils.c', resources, ] diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..5ea4287 --- /dev/null +++ b/src/utils.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 Bastien Nocera + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as published by + * the Free Software Foundation. + * + */ + +#include "utils.h" + +char * +get_device_file (GUdevDevice *device) +{ + if (!IS_TEST) + return g_udev_device_get_device_file (device); + + return g_build_filename (g_getenv ("UMOCKDEV_DIR"), + "iio-dev-data.bin", + NULL); +} diff --git a/src/utils.h b/src/utils.h index 0109a1b..a117d51 100644 --- a/src/utils.h +++ b/src/utils.h @@ -10,5 +10,8 @@ #pragma once #include +#include #define IS_TEST (g_getenv ("UMOCKDEV_DIR") != NULL) + +char *get_device_file (GUdevDevice *device);