From patchwork Thu Oct 13 17:40:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Sabatini X-Patchwork-Id: 990 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp299808vsd; Thu, 13 Oct 2016 10:57:06 -0700 (PDT) X-Received: by 10.28.153.76 with SMTP id b73mr2989016wme.60.1476381426255; Thu, 13 Oct 2016 10:57:06 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id wo8si19093700wjc.122.2016.10.13.10.57.05; Thu, 13 Oct 2016 10:57:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A66AF689897; Thu, 13 Oct 2016 20:57:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf0-f65.google.com (mail-lf0-f65.google.com [209.85.215.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4971F680D4F for ; Thu, 13 Oct 2016 20:56:56 +0300 (EEST) Received: by mail-lf0-f65.google.com with SMTP id x23so8116003lfi.1 for ; Thu, 13 Oct 2016 10:56:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=l1MHDZDW5+7Bwhr7JQl65dykcLMcTC9491EdH+E/8aA=; b=kc3w5iTeTMLuvn5aZ/Oc2Mww1Y9IEXae6DUV6m9YpX79tmM9u9eqEvyDKy/l11gt6N jU8rOFmMRw5CpLSgBgs2Wm65shfLsID2v4t1IJvYpEcedH9WKNnzweRIwjG8tETA8Gvs wPOXYirW2jjrs5zPFMSr5eUDzeli0KJWMQqx4krUWE8chqP0M6dits4h2ypKN0gcJ2VO x4qxFaMVlmMYchgQZjsE0glA34O+QsM8aWf7fqkeg9BhtxPznUkoY0vFBkkqUzT+AsON RZtepaRG2bn04Yw7AWJxPgDfzcuaGBC8wAFZcZzMOt8mMPkzaAabgHJj3TIUkq1KxugH QGiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=l1MHDZDW5+7Bwhr7JQl65dykcLMcTC9491EdH+E/8aA=; b=VrPDPbm4EmNljVGCb+71YkLW6ShfEGMP+KKI+Vokc430n7m3VyNwR40U6qofz0baqe 2pKFwFhOm7OGH2sAP2OnPlIrQ3hGEIzKkH2ZcR0gCxjeZzHhfnT5DDLEb854u3psRSlr Y9uldt2qVEYH8xYaEA5VnOF2WmDH5NmNxRS+JCSbF36MIjR3tCK9fmyabXpK3V5avWsh JUPlYO0odWsCiNiXBZlChAiwJvhBHa4hkQjThxRcseC2Cb/b3FrSqBROOm4Y5eoqY5tN JybU6Lvr33hCu1nopiVq30UQ+YCRFUSAKODgLRoUCQUckza02I42LkKohhx41c/cjGQ1 MBog== X-Gm-Message-State: AA6/9Rkw9+spiU41lhA+hl3AE5GCSmbxdR7BvFeMxegXeTKmrN236l6zlBKkqRcRPNOGFg== X-Received: by 10.194.154.227 with SMTP id vr3mr8084116wjb.127.1476380464327; Thu, 13 Oct 2016 10:41:04 -0700 (PDT) Received: from barisone ([151.56.76.109]) by smtp.gmail.com with ESMTPSA id us3sm24217418wjb.32.2016.10.13.10.41.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Oct 2016 10:41:03 -0700 (PDT) Received: by barisone (Postfix, from userid 1000) id 98CD81A8969; Thu, 13 Oct 2016 19:40:59 +0200 (CEST) From: Stefano Sabatini To: FFmpeg development discussions and patches Date: Thu, 13 Oct 2016 19:40:59 +0200 Message-Id: <1476380459-3167-1-git-send-email-stefasab@gmail.com> X-Mailer: git-send-email 1.9.1 Subject: [FFmpeg-devel] [PATCH] lavf/aviobuf: add ff_get_line2() variant X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Stefano Sabatini MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This allows to probe if the read line was partially discarded. --- libavformat/aviobuf.c | 10 +++++++++- libavformat/internal.h | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 134d627..28183b4 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -764,18 +764,26 @@ unsigned int avio_rb32(AVIOContext *s) int ff_get_line(AVIOContext *s, char *buf, int maxlen) { - int i = 0; + return ff_get_line2(s, buf, maxlen, NULL); +} + +int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen) +{ + int i = 0, j = 0; char c; do { c = avio_r8(s); if (c && i < maxlen-1) buf[i++] = c; + j++; } while (c != '\n' && c != '\r' && c); if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s)) avio_skip(s, -1); buf[i] = 0; + if (readlen) + *readlen = j; return i; } diff --git a/libavformat/internal.h b/libavformat/internal.h index 49244fa..cffc787 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -274,6 +274,20 @@ void ff_put_v(AVIOContext *bc, uint64_t val); */ int ff_get_line(AVIOContext *s, char *buf, int maxlen); +/** + * Read a whole line of text from AVIOContext. Stop reading after reaching + * either a \\n, a \\0 or EOF. The returned string is always \\0-terminated, + * and may be truncated if the buffer is too small. + * + * @param s the read-only AVIOContext + * @param buf buffer to store the read line + * @param maxlen size of the buffer + * @param readlen length of the read line, including the terminating newline character + * @return the length of the string written in the buffer, not including the + * final \\0 + */ +int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen); + #define SPACE_CHARS " \t\r\n" /**