summaryrefslogtreecommitdiff
path: root/sanei/sanei_init_debug.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2019-07-31 17:00:20 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2019-07-31 17:00:20 +0200
commit3759ce55ba79b8d3b9d8ed247a252273ee7dade3 (patch)
treed69692a274dd1c7d0672e6bb7155a0fc106f9d49 /sanei/sanei_init_debug.c
parentc8bd2513ecba169cff44c09c8058c36987357b18 (diff)
parent1687222e1b9e74c89cafbb5910e72d8ec7bfd40f (diff)
Update upstream source from tag 'upstream/1.0.28'
Update to upstream version '1.0.28' with Debian dir ec5bb298266630fc3801ff6dc0c258f6df7ba979
Diffstat (limited to 'sanei/sanei_init_debug.c')
-rw-r--r--sanei/sanei_init_debug.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/sanei/sanei_init_debug.c b/sanei/sanei_init_debug.c
index 0abb891..946aee9 100644
--- a/sanei/sanei_init_debug.c
+++ b/sanei/sanei_init_debug.c
@@ -107,16 +107,31 @@ sanei_init_debug (const char * backend, int * var)
DBG (0, "Setting debug level of %s to %d.\n", backend, *var);
}
+static int
+is_socket (int fd)
+{
+ struct stat sbuf;
+
+ if (fstat(fd, &sbuf) == -1) return 0;
+
+#if defined(S_ISSOCK)
+ return S_ISSOCK(sbuf.st_mode);
+#elif defined (S_IFMT) && defined(S_IFMT)
+ return (sbuf.st_mode & S_IFMT) == S_IFSOCK;
+#else
+ return 0;
+#endif
+}
+
void
sanei_debug_msg
(int level, int max_level, const char *be, const char *fmt, va_list ap)
{
char *msg;
-
+
if (max_level >= level)
{
-#ifdef S_IFSOCK
- if ( 1 == isfdtype(fileno(stderr), S_IFSOCK) )
+ if (is_socket(fileno(stderr)))
{
msg = (char *)malloc (sizeof(char) * (strlen(be) + strlen(fmt) + 4));
if (msg == NULL)
@@ -132,12 +147,11 @@ sanei_debug_msg
}
}
else
-#endif
{
fprintf (stderr, "[%s] ", be);
vfprintf (stderr, fmt, ap);
}
-
+
}
}