From 747ba59e743e4d3b5b1265c0e755a4b7951d2fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCnther?= Date: Fri, 10 Jul 2009 23:37:37 +0200 Subject: Replaced asprintf with cString::sprintf in GetFrontend*() --- HISTORY | 1 + common.c | 56 ++++++++++++++++++++++++++------------------------------ 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/HISTORY b/HISTORY index 5122126..30d12f7 100644 --- a/HISTORY +++ b/HISTORY @@ -77,6 +77,7 @@ ____-__-__: Version 1.3 - Use pkg-config to find compilation flags, libs etc for FreeType and Imlib2. - Fixed crash with FrontendHasLock and FrontendHasSignal (closes #147 - thanks to a.g.prosat at tochka.ru for reporting this) +- Replaced asprintf with cString::sprintf in GetFrontend*() 2009-06-01: Version 1.2 diff --git a/common.c b/common.c index 5512bae..c676fdb 100644 --- a/common.c +++ b/common.c @@ -90,60 +90,56 @@ const cRecording *GetRecordingByFileName(const char *FileName) int GetFrontendSTR(void) { uint16_t value = 0; - char *dev = NULL; + cString dev = cString::sprintf(FRONTEND_DEVICE, cDevice::ActualDevice()->CardIndex(), 0); - asprintf(&dev, FRONTEND_DEVICE, cDevice::ActualDevice()->CardIndex(), 0); int fe = open(dev, O_RDONLY | O_NONBLOCK); - free(dev); - if (fe >= 0) { - CHECK(ioctl(fe, FE_READ_SIGNAL_STRENGTH, &value)); - close(fe); - } + if (fe < 0) + return 0; + CHECK(ioctl(fe, FE_READ_SIGNAL_STRENGTH, &value)); + close(fe); + return value / 655; } int GetFrontendSNR(void) { uint16_t value = 0; - char *dev = NULL; + cString dev = cString::sprintf(FRONTEND_DEVICE, cDevice::ActualDevice()->CardIndex(), 0); - asprintf(&dev, FRONTEND_DEVICE, cDevice::ActualDevice()->CardIndex(), 0); int fe = open(dev, O_RDONLY | O_NONBLOCK); - free(dev); - if (fe >= 0) { - CHECK(ioctl(fe, FE_READ_SNR, &value)); - close(fe); - } + if (fe < 0) + return 0; + CHECK(ioctl(fe, FE_READ_SNR, &value)); + close(fe); + return value / 655; } bool GetFrontendHasLock(void) { - fe_status_t value = fe_status_t(0); - char *dev = NULL; + fe_status_t value; + cString dev = cString::sprintf(FRONTEND_DEVICE, cDevice::ActualDevice()->CardIndex(), 0); - asprintf(&dev, FRONTEND_DEVICE, cDevice::ActualDevice()->CardIndex(), 0); int fe = open(dev, O_RDONLY | O_NONBLOCK); - free(dev); - if (fe >= 0) { - CHECK(ioctl(fe, FE_READ_STATUS, &value)); - close(fe); - } + if (fe < 0) + return false; + CHECK(ioctl(fe, FE_READ_STATUS, &value)); + close(fe); + return value & FE_HAS_LOCK; } bool GetFrontendHasSignal(void) { - fe_status_t value = fe_status_t(0); - char *dev = NULL; + fe_status_t value; + cString dev = cString::sprintf(FRONTEND_DEVICE, cDevice::ActualDevice()->CardIndex(), 0); - asprintf(&dev, FRONTEND_DEVICE, cDevice::ActualDevice()->CardIndex(), 0); int fe = open(dev, O_RDONLY | O_NONBLOCK); - free(dev); - if (fe >= 0) { - CHECK(ioctl(fe, FE_READ_STATUS, &value)); - close(fe); - } + if (fe < 0) + return false; + CHECK(ioctl(fe, FE_READ_STATUS, &value)); + close(fe); + return value & FE_HAS_SIGNAL; } -- cgit v1.2.3