From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 11C3348DFE for ; Sun, 28 Jan 2024 22:39:05 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0D5A068D1A0; Mon, 29 Jan 2024 00:39:03 +0200 (EET) Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5A8E768C4F1 for ; Mon, 29 Jan 2024 00:38:56 +0200 (EET) Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3be15eb82beso1021129b6e.2 for ; Sun, 28 Jan 2024 14:38:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706481534; x=1707086334; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dES0A+KO58MBa0FR/NE0tijU6oz58jzOjyca8LCCoY0=; b=ETLO1DWkirk2ek6YuJ1EV28T4sr0JKHXOiPBX4MhM9lAxm+W8CER/WuGlxiaC8m+6d zSnlk52qUC9jMu0fU2xPCzCIXNBjhVYukADUG46Z6/+DeRn7OEw/yD709eFmPagrfay9 Em4KVDYwtMTDoKrpB/aAP8kxx/ESUPH2AxsEZvPpltRGfaJUSlw1MaJJjhAMbg4jDTZm vUcihQcx/EeVEYYNGgL+2S75686flI6f7Q11aWHo7cukwJuGcFtrbWkV5H60s/eZ1agX Wb3tNH2A1BqjA+KViGxyP1ogtGkea7THqj4GxPDhlUj8T6iXfEDdYY3yA5xL8bIBEM15 2N0Q== X-Gm-Message-State: AOJu0YymqFVy9fwZNmYlnxmH8I+/S9BUUi0u/WsnUb1QyYB9wvhTD2e/ zFntkWqEnuCDC5YHHF7oE3Ae4hQqMj1ZIXNutoRrl+WRjU4dZ3r0Mc5Wj0SD5wecPATZ5KkfVgk = X-Google-Smtp-Source: AGHT+IHO+AJR1V2DHuyIQDEt9OIsvaAkUOB2iyG7gCV6e3N8XOqKnj0518dwD3ujsA1PuhWpePoJiw== X-Received: by 2002:a05:6808:4488:b0:3be:3de9:68eb with SMTP id eq8-20020a056808448800b003be3de968ebmr3345014oib.39.1706481534137; Sun, 28 Jan 2024 14:38:54 -0800 (PST) Received: from rcombs-mbp.localdomain ([2604:4080:11b0:8350:a1b7:ea99:fa1a:76f0]) by smtp.gmail.com with ESMTPSA id n12-20020aa78a4c000000b006ddd2be2169sm4588062pfa.73.2024.01.28.14.38.53 for (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 28 Jan 2024 14:38:53 -0800 (PST) To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 Jan 2024 14:38:27 -0800 Message-ID: <20240128223830.57736-1-rcombs@rcombs.me> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] lavf/avio_internal: add ffio_write_lines for line ending normalization X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: rcombs via ffmpeg-devel Reply-To: FFmpeg development discussions and patches Cc: rcombs Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- libavformat/avio_internal.h | 11 +++++++++++ libavformat/aviobuf.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h index f2e4ff30cb..16cf6ce016 100644 --- a/libavformat/avio_internal.h +++ b/libavformat/avio_internal.h @@ -156,6 +156,17 @@ unsigned int ffio_read_leb(AVIOContext *s); void ffio_write_leb(AVIOContext *s, unsigned val); +/** + * Write a sequence of text lines, converting line endings. + * All input line endings (LF, CRLF, CR) are converted to the configured line ending. + * @param s The AVIOContext to write to + * @param buf The buffer to write + * @param size The size of the buffer, or <0 to use the full length of a null-terminated string + * @param ending The line ending sequence to convert to, or NULL for \n + */ +void ffio_write_lines(AVIOContext *s, const unsigned char *buf, int size, + const unsigned char *ending); + /** * Read size bytes from AVIOContext into buf. * Check that exactly size bytes have been read. diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 5a329ce465..76780bc852 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -1004,6 +1004,37 @@ void ffio_write_leb(AVIOContext *s, unsigned val) } } +void ffio_write_lines(AVIOContext *s, const unsigned char *buf, int size, + const unsigned char *ending) +{ + int ending_len = ending ? strlen(ending) : 1; + if (!ending) + ending = "\n"; + if (size < 0) + size = strlen(buf); + + while (size > 0) { + size_t len = 0; + char last = 0; + for (; len < size; len++) { + last = buf[len]; + if (last == '\r' || last == '\n') + break; + } + + avio_write(s, buf, len); + avio_write(s, ending, ending_len); + + buf += len + 1; + size -= len + 1; + + if (size > 0 && last == '\r' && buf[0] == '\n') { + buf++; + size--; + } + } +} + int ffio_fdopen(AVIOContext **s, URLContext *h) { uint8_t *buffer = NULL; -- 2.42.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".