From patchwork Thu Jun 9 19:04:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nihil-admirari X-Patchwork-Id: 36096 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp542219pzj; Thu, 9 Jun 2022 12:04:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzXcF3+Z4CeL/d24kWo+eWCg9rPZhoIOvA69CbBWttgRwIHoV3NR7i2pviCDXjLMeuYItS X-Received: by 2002:a05:6402:542:b0:42d:c7d6:4121 with SMTP id i2-20020a056402054200b0042dc7d64121mr46121128edx.302.1654801465445; Thu, 09 Jun 2022 12:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654801465; cv=none; d=google.com; s=arc-20160816; b=uy8Dx2EnrkhN3ehFgwSDKuyI9peETAdAONt+1qOmw5tVRFAnVmSQ4l4LZdEveD+EVd XwXR8cYBl/XeWC7r32/rmHdP++z2DPlvCZ7HJzo4xoTkGnmNw8C65WgakxCTr9j7CETr Pcgb1vPThQJmMUpeM5PdVYkUQFuQncQzRuYzQpJzvXzAslB+5zrKU/HVQCpzqpYclSk4 fb5589CHv+cWwl9zRSwjFPC7WbfpI3eSL5ptj7AnKEOq/6ciZiGM97BmD8lY+Awr9ujQ CRCFbMIkRvveZUVLewS7AaKUeFnWXjskR3l8f6EGp3suWym4KIcfqI4AMsygvhF1FsZU J3Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=R0CfGy6UTozgz6Pxl8r7vUtEqtVdeiC6dcYzyZroIdg=; b=Pl/85h+SLxKSOU+eAAY2bNFgPlVn1xiYcqrBKmhM50b6SgMm+Q8qK01434Mz8lIEcB jRtGvEW9s5M4jcmk0PyH2IqjDCIjpyc41djZRSK1sV7vWblIbw4q/RbgZbx17P2lkYE0 JRAtv4cwtjB4LVKoIDcHEvh32hkc/2wOQDaPlbp2V9bJQDkG3GubPOBfmgthqDQ6auJC IAyFidRNru1P2VILMaQTDZhBsAdyymigTa+rEE93W3R7ilSqfC/cbx9StLP1MmcnAGHq 0nfDp13LHkHNojhNfFWhPkUvqXk7+PA6MYnn1g0+hvrpV6xadmJ108Ybf9ao/oO/lmVC kj8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mailo.com header.s=mailo header.b=KiVM6X6o; 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 sp=NONE dis=NONE) header.from=mailo.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n13-20020a05640205cd00b0042aac548ac8si19316106edx.405.2022.06.09.12.04.24; Thu, 09 Jun 2022 12:04:25 -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=@mailo.com header.s=mailo header.b=KiVM6X6o; 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 sp=NONE dis=NONE) header.from=mailo.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7CBA668B759; Thu, 9 Jun 2022 22:04:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from msg-4.mailo.com (ip-15.mailobj.net [213.182.54.15]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D97A168B583 for ; Thu, 9 Jun 2022 22:04:15 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1654801455; bh=Ex0XRnhO+eBaLXd0T9UAKNQ5KIO1V7L41aGOAUt7LFw=; h=X-EA-Auth:From:To:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=KiVM6X6oHCNkNDaAAR8XOzMGyT5NduGT0utvAS8gSpqiw0eiccwHiIRopECN39QCo 48eIDIGJSCU8U6M0NPWZc+LNO0Y91jicYIDLzvcKZrW3uRSMyRpjt7PaBvEH73IgCO wzZRQZdh82VAX/HvthaYk5hc3TyPIFb0lNNrHCm8= Received: by b-1.in.mailobj.net [192.168.90.11] with ESMTP via ip-206.mailobj.net [213.182.55.206] Thu, 9 Jun 2022 21:04:15 +0200 (CEST) X-EA-Auth: fMf3IRd5VoPcE5k3UctEuecs+7RcybiuSd1dkrowzx3iNESWx9m27fGvH/H4zEaTElZ7viVF9LDHBPncGJGWep51Sjq48mYfab+beKIQ6M8= From: Nil Admirari To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Jun 2022 22:04:06 +0300 Message-Id: <20220609190406.6339-4-nil-admirari@mailo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220609190406.6339-1-nil-admirari@mailo.com> References: <20220609190406.6339-1-nil-admirari@mailo.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v13 4/4] fftools/cmdutils.c: Remove MAX_PATH limit 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: bCccloVVTZe/ --- fftools/cmdutils.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 5d7cdc3..d42bb04 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -50,6 +50,7 @@ #include "opt_common.h" #ifdef _WIN32 #include +#include "compat/w32dlfcn.h" #endif AVDictionary *sws_dict; @@ -812,6 +813,9 @@ FILE *get_preset_file(char *filename, size_t filename_size, { FILE *f = NULL; int i; +#if HAVE_GETMODULEHANDLE && defined(_WIN32) + char *datadir = NULL; +#endif const char *base[3] = { getenv("FFMPEG_DATADIR"), getenv("HOME"), FFMPEG_DATADIR, }; @@ -821,19 +825,31 @@ FILE *get_preset_file(char *filename, size_t filename_size, f = fopen(filename, "r"); } else { #if HAVE_GETMODULEHANDLE && defined(_WIN32) - char datadir[MAX_PATH], *ls; + wchar_t *datadir_w = get_module_filename(NULL); base[2] = NULL; - if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1)) + if (wchartoansi(datadir_w, &datadir)) + datadir = NULL; + av_free(datadir_w); + + if (datadir) { - for (ls = datadir; ls < datadir + strlen(datadir); ls++) + char *ls; + for (ls = datadir; *ls; ls++) if (*ls == '\\') *ls = '/'; if (ls = strrchr(datadir, '/')) { - *ls = 0; - strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir)); - base[2] = datadir; + ptrdiff_t datadir_len = ls - datadir; + size_t desired_size = datadir_len + strlen("/ffpresets") + 1; + char *new_datadir = av_realloc_array( + datadir, desired_size, sizeof *datadir); + if (new_datadir) { + datadir = new_datadir; + datadir[datadir_len] = 0; + strncat(datadir, "/ffpresets", desired_size - 1 - datadir_len); + base[2] = datadir; + } } } #endif @@ -853,6 +869,9 @@ FILE *get_preset_file(char *filename, size_t filename_size, } } +#if HAVE_GETMODULEHANDLE && defined(_WIN32) + av_free(datadir); +#endif return f; }