diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-10-06 14:00:40 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-10-06 14:00:40 +0200 |
commit | 6e9c41a892ed0e0da326e0278b3221ce3f5713b8 (patch) | |
tree | 2e301d871bbeeb44aa57ff9cc070fcf3be484487 /lib/isfdtype.c |
Initial import of sane-backends version 1.0.24-1.2
Diffstat (limited to 'lib/isfdtype.c')
-rw-r--r-- | lib/isfdtype.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/isfdtype.c b/lib/isfdtype.c new file mode 100644 index 0000000..8e51516 --- /dev/null +++ b/lib/isfdtype.c @@ -0,0 +1,25 @@ +#include "../include/sane/config.h" + +#ifndef HAVE_ISFDTYPE + +#include <sys/stat.h> + +int +isfdtype(int fd, int fdtype) +{ + struct stat st; + + if (fstat(fd, &st) == -1) return 0; /* couldn't stat fd */ + + if (st.st_mode == 0) + return 1; /* At least Irix doesn't seem to know socket type */ +#if defined(S_ISSOCK) + return S_ISSOCK(st.st_mode) != 0; +#elif defined(S_IFSOCK) && defined(S_IFMT) + return (st.st_mode & S_IFMT) == S_IFSOCK; +#else + return 0; +#endif +} + +#endif /* !HAVE_ISFDTYPE */ |