X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Flog.c;h=cdf2293bdeb32b012d43548545c44c058eb15a1b;hb=e0b6855bd4daca9f1a27b8e4e0d16b019d5d54e4;hp=db5a3fd42f98ab94beff12983f1809e3f3ed3b0c;hpb=7419638d4c5d21dadccfd8f234c5671c5330dc33;p=libsigrok.git diff --git a/src/log.c b/src/log.c index db5a3fd4..cdf2293b 100644 --- a/src/log.c +++ b/src/log.c @@ -14,17 +14,19 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ +#include #include #include #include #include #include "libsigrok-internal.h" +/** @cond PRIVATE */ #define LOG_PREFIX "log" +/** @endcond */ /** * @file @@ -162,7 +164,8 @@ static int sr_logv(void *cb_data, int loglevel, const char *format, va_list args { uint64_t elapsed_us, minutes; unsigned int rest_us, seconds, microseconds; - int ret; + char *raw_output, *output; + int raw_len, raw_idx, idx, ret; /* This specific log callback doesn't need the void pointer data. */ (void)cb_data; @@ -185,10 +188,25 @@ static int sr_logv(void *cb_data, int loglevel, const char *format, va_list args ret = fputs("sr: ", stderr); } - if (ret < 0 || g_vfprintf(stderr, format, args) < 0 - || putc('\n', stderr) < 0) + if (ret < 0 || (raw_len = g_vasprintf(&raw_output, format, args)) < 0) return SR_ERR; + output = g_malloc0(raw_len + 1); + + /* Copy the string without any unwanted newlines. */ + raw_idx = idx = 0; + while (raw_idx < raw_len) { + if (raw_output[raw_idx] != '\n') { + output[idx] = raw_output[raw_idx]; + idx++; + } + raw_idx++; + } + + g_fprintf(stderr, "%s\n", output); + g_free(raw_output); + g_free(output); + return SR_OK; }