AP_HAL_Linux: add function to check if path is chardev

Utility function to allow checking if a certain path is a character
device.
This commit is contained in:
Lucas De Marchi 2015-06-27 18:18:09 -03:00 committed by Andrew Tridgell
parent a4c1b0d75f
commit acc571c2c5
2 changed files with 13 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#include <stdio.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
@ -62,4 +63,14 @@ void LinuxUtil::set_system_clock(uint64_t time_utc_usec)
#endif
}
bool LinuxUtil::is_chardev_node(const char *path)
{
struct stat st;
if (!path || lstat(path, &st) < 0)
return false;
return S_ISCHR(st.st_mode);
}
#endif // CONFIG_HAL_BOARD == HAL_BOARD_LINUX

View File

@ -31,6 +31,8 @@ public:
*/
void set_system_clock(uint64_t time_utc_usec);
bool is_chardev_node(const char *path);
private:
static Linux::ToneAlarm _toneAlarm;
int saved_argc;