From patchwork Thu Sep 6 18:58:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 10260 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp798039jap; Thu, 6 Sep 2018 11:58:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZAxnzl/MLuNq8PmvqDhqWwrG1Hq8GfOTGWLqAsoq535gAUwHGOOloc2zfGsIXh7BjlWj6i X-Received: by 2002:adf:9366:: with SMTP id 93-v6mr3370698wro.60.1536260339500; Thu, 06 Sep 2018 11:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536260339; cv=none; d=google.com; s=arc-20160816; b=Gd0cA+36IhkES8Qj6gejTFCQlHpjSimQbz9i/37oCqqtmlEvUFyjRxtve6C2pqutGX it5B2vca78yuW3MACxNHqwSfEL/w7fI9TO6yIZIsbfw/Bp/iaX1DRSKjs8jEov0ZSjsg gfIEXc6SDRJsGCGfC6jOs94RG/JbBj7eL0k+2PujibJ8X/rIUAmCxIkKORjVuqOIwqM/ GrGpl0ii03K1u+un9LxbCFHY7YATfa2gwJk64lehOLKv4GrZa+dRUE3YvBAjT0q2X4CF OiCisqECELIWAvEZ+BlGcQnEUxDrRm0QebL+86+YDSH2pp9F+1BbpUiqRJ+bBfeZQpsR vg1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=Xr7BWQnNmVPavOuj/w8L+zq/yhm85eZrQaBOrDKJry0=; b=NWwvmeEDAFzd0k2HJlE09OCZNGmdGTF13G7r1oNX+pgrbst+U3/TgEkklpzkEz+Pni osV2el+eRzZ/YOZufNmJW1rmcAWcKVeCCpvYBkWEeE26zzZS1xfKrJhN/kzNNv3qCXUc hFMztc2EG0JqZBjiKATTZknnpDz19xcLrlA9+SjPZ3WQkk7U3JL6Qc1o3J4RM1FvI4zU K2xxTOmgybiGSRhnpCr/aMQ+9tQgex5iIY/I3ZT/0q0ErGE6PsClMBa4dPjKwxuas9Z7 YN3W9ZYLHyNIpCWANU4WcyrJulps2ojmHYjYLUXTf+Y0HreE4srdZlTEHCgY2HrlhE8k es5A== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q9-v6si5787787wrs.107.2018.09.06.11.58.59; Thu, 06 Sep 2018 11:58:59 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F42E68A0B6; Thu, 6 Sep 2018 21:58:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 15D9668A051 for ; Thu, 6 Sep 2018 21:58:43 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id DF0A5E127E; Thu, 6 Sep 2018 20:58:50 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id f2_cL8qRmXtd; Thu, 6 Sep 2018 20:58:50 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D0FABE0F69; Thu, 6 Sep 2018 20:58:48 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Thu, 6 Sep 2018 20:58:37 +0200 Message-Id: <20180906185837.24645-2-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180906185837.24645-1-cus@passwd.hu> References: <20180906185837.24645-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 2/2] avutil/file: allow mapping 0 byte files with av_file_map 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- libavutil/file.c | 8 ++++++++ libavutil/file.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/libavutil/file.c b/libavutil/file.c index 2153e51379..64f11fed76 100644 --- a/libavutil/file.c +++ b/libavutil/file.c @@ -85,6 +85,11 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, } *size = off_size; + if (!*size) { + *bufptr = NULL; + goto out; + } + #if HAVE_MMAP ptr = mmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0); if (ptr == MAP_FAILED) { @@ -126,12 +131,15 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, read(fd, *bufptr, *size); #endif +out: close(fd); return 0; } void av_file_unmap(uint8_t *bufptr, size_t size) { + if (!size) + return; #if HAVE_MMAP munmap(bufptr, size); #elif HAVE_MAPVIEWOFFILE diff --git a/libavutil/file.h b/libavutil/file.h index 8666c7b1d5..ea6798b259 100644 --- a/libavutil/file.h +++ b/libavutil/file.h @@ -33,6 +33,8 @@ * allocated buffer or map it with mmap() when available. * In case of success set *bufptr to the read or mmapped buffer, and * *size to the size in bytes of the buffer in *bufptr. + * Unlike mmap this function succeeds with zero sized files, in this + * case *bufptr will be be NULL and *size will be set to 0. * The returned buffer must be released with av_file_unmap(). * * @param log_offset loglevel offset used for logging