00001 #ifndef _MYTH_DB_UTIL_H_
00002 #define _MYTH_DB_UTIL_H_
00003
00004
00005 #include <sys/types.h>
00006 #include <fcntl.h>
00007 #include <errno.h>
00008
00009
00010 #include <QString>
00011
00012
00013 #include "mythlogging.h"
00014
00015 #ifdef USING_MINGW
00016 static inline void setup_pipe(int[2], long[2]) {}
00017 #else
00018 static inline void setup_pipe(int mypipe[2], long myflags[2])
00019 {
00020 int pipe_ret = pipe(mypipe);
00021 if (pipe_ret < 0)
00022 {
00023 LOG(VB_GENERAL, LOG_ERR, "Failed to open pipes" + ENO);
00024 mypipe[0] = mypipe[1] = -1;
00025 }
00026 else
00027 {
00028 errno = 0;
00029 long flags = fcntl(mypipe[0], F_GETFL);
00030 if (0 == errno)
00031 {
00032 int ret = fcntl(mypipe[0], F_SETFL, flags|O_NONBLOCK);
00033 if (ret < 0)
00034 LOG(VB_GENERAL, LOG_ERR,
00035 QString("Set pipe flags error") + ENO);
00036 }
00037 else
00038 {
00039 LOG(VB_GENERAL, LOG_ERR, QString("Get pipe flags error") + ENO);
00040 }
00041
00042 for (uint i = 0; i < 2; i++)
00043 {
00044 errno = 0;
00045 flags = fcntl(mypipe[i], F_GETFL);
00046 if (0 == errno)
00047 myflags[i] = flags;
00048 }
00049 }
00050 }
00051 #endif
00052
00053 #endif // _MYTH_DB_UTIL_H_