From patchwork Tue May 24 22:20:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 35911 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp766039pzj; Tue, 24 May 2022 15:21:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPK3LzyOaGuM8dWFXa+wGniJ7yzeCuUzLDoaeFuf4w7uybKUzIHKPx8ia947S1hFvwBiR5 X-Received: by 2002:a17:906:4785:b0:6fe:f8ac:2494 with SMTP id cw5-20020a170906478500b006fef8ac2494mr8163434ejc.199.1653430872304; Tue, 24 May 2022 15:21:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653430872; cv=none; d=google.com; s=arc-20160816; b=V7hN69HyBLs6WqdJLcA0QBtsre0lFzB/4nTJSSYP1FjJdixCAk7smFzfhrJbWeKegI L0XSRz06NkArKUxmKtb8/ux1LTrr2yvraD8B4AtN8xtSeDLdxC94zb3S7jbfnLIHudVx 0oSFB+ztiFXVUfLuoTROjA8G+SCrkEpQkS8CB7CtKzmTbB9eA7sXNMuVfW9USGPH9N/x qR0HD02NHn+jM5B7VJzXi4lO2NriJVZ1rBc4oAlaUWw7VvfE/RI2lSUHpzqoD8Bmmtpb AlZHf2VprvOD8oCpGKyCVrqwSSR+/ViTDRsWcoyZPXDgscPLGKTUeItEdzNVfnYmLRLU 9Z8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=ytKRMp3Hw5G1fs3Vgnow0e7tCrt65PWefYbeSG796I4=; b=K7JQmtQx8qotTUUxX7g1YyAX9HREtSUsvd4o93UdlKYJ0LXY6ufmocVx4uTkUp6AUD 5FFNXe0uSYGQ9RKGqBQhvd3ALqmhAAvucqJPaRVYJuqjpJ5NKkWL6x2rzljQO/ZxRhBM 4SX86XlQ0vqQ6qbY6jub04dhlybKmcL3R9oNvJse/ty49ygIf/Tr87BsC4/PFnIu9LKm 3CysetLoEC88WXCsGDQV7EtE6b2ZlzgDUFBwhz5wEoONa7s1ngjSTTQQ8lhkM32U0Gjc 7t/iEd25X+01Ufs6uXyF0rXuFDtqFnL+AhDAA296fPUwGe21ipNwpS0T4jADU3g0d46s OItg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=NlYhwH+i; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z4-20020a056402274400b0042b303fc515si10845460edd.360.2022.05.24.15.21.12; Tue, 24 May 2022 15:21:12 -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 header.s=20210112 header.b=NlYhwH+i; 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=QUARANTINE 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 E2F9368B5A7; Wed, 25 May 2022 01:21:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5A16668B59F for ; Wed, 25 May 2022 01:20:56 +0300 (EEST) Received: by mail-pf1-f176.google.com with SMTP id c14so17655504pfn.2 for ; Tue, 24 May 2022 15:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=m7glWo8l9Vtp0k/JtUjc09ZdO7Jhb0P9L5pdwytooDA=; b=NlYhwH+iaFXWTgD1jQ6t8Q25bUI5Oo2A7fu2YqmMaG6FPgIY73cqRwa9nkpi0D+LUY FdEgN00jSXIj6u37OfRUobgtS7dbgtL0W31P8nz3DEG/+6x00tLi/lFdJeFpfcrYQ3b1 oOOBQr28NLpfoAjTtGTh9Klv7Rp3bt2HyTeXShiD0CH4glGWpMj0thoN9cwx7EFianUc Oqrpx8WGZS5dao2mU140z5RWwLRsFbukRUhFdsl5uGIHscDbpJkM6QbXIHK3vGlz301h HwTwV8nJxjRoJONBzkzbPMxrXhDqJ1YkGnRb7TqkBab7Vyil1yF7uQAoi+9s7RDbgopL 28ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=m7glWo8l9Vtp0k/JtUjc09ZdO7Jhb0P9L5pdwytooDA=; b=siMj/OKiRsljr8SHX2NUvMBBC9why0sszKgWVOuZyFsU+7x4ntIC7sOtwdAXnMApF9 txsjAGpQPllFXnuaOJCek2yPwZ1zrOdBks+3821S8TLqZ99956CnuNcKlQ1mPXFA6j+T DJrmrlxw+2cGAi7bSf6vvhig7SKomPEfFREFYM6ld2U6/Q0K9+8CsHBAaX0HEbMBoe2+ B4h4oim8YuGFXqReoTRTpkXJPlpVoWA0aQ8FxTkWrl9xE2PI1PffPr0q7hk66i0f59vQ yLwwVHsbK3fIWIqnJPc+IeKPjgAHOvPpzfR6olpunzwxECNY2icbIG25N3SGa77XjDJr XGBQ== X-Gm-Message-State: AOAM531efqWyJG35zLppUB4c9P9Z/THNJqFB4XRMVaGkfs3P63KkI+Q/ j+VMZk1j86bNdTE9F3XpgCgfxJrZkss/ew== X-Received: by 2002:a65:44c1:0:b0:3f6:26e8:77a9 with SMTP id g1-20020a6544c1000000b003f626e877a9mr25881088pgs.204.1653430854197; Tue, 24 May 2022 15:20:54 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id d10-20020a17090a2a4a00b001ded49491basm2822422pjg.2.2022.05.24.15.20.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 May 2022 15:20:53 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <960aa795ffd4018d970fb1768afe3ad11cdb6936.1653430851.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Tue, 24 May 2022 22:20:49 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v7 1/3] avutil/wchar_filename, file_open: Support long file names on Windows 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 Cc: Martin =?utf-8?q?Storsj=C3=B6?= , softworkz , Hendrik Leppkes Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: vX2jniIjEfWZ From: softworkz Signed-off-by: softworkz --- libavutil/file_open.c | 2 +- libavutil/wchar_filename.h | 180 +++++++++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+), 1 deletion(-) diff --git a/libavutil/file_open.c b/libavutil/file_open.c index fb64c2e4ee..58a6073353 100644 --- a/libavutil/file_open.c +++ b/libavutil/file_open.c @@ -45,7 +45,7 @@ static int win32_open(const char *filename_utf8, int oflag, int pmode) wchar_t *filename_w; /* convert UTF-8 to wide chars */ - if (utf8towchar(filename_utf8, &filename_w)) + if (get_extended_win32_path(filename_utf8, &filename_w)) return -1; if (!filename_w) goto fallback; diff --git a/libavutil/wchar_filename.h b/libavutil/wchar_filename.h index 90f082452c..f36d9dfea3 100644 --- a/libavutil/wchar_filename.h +++ b/libavutil/wchar_filename.h @@ -40,6 +40,186 @@ static inline int utf8towchar(const char *filename_utf8, wchar_t **filename_w) MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, *filename_w, num_chars); return 0; } + +/** + * Checks for extended path prefixes for which normalization needs to be skipped. + * see .NET6: PathInternal.IsExtended() + * https://github.com/dotnet/runtime/blob/9260c249140ef90b4299d0fe1aa3037e25228518/src/libraries/Common/src/System/IO/PathInternal.Windows.cs#L165 + */ +static inline int path_is_extended(const wchar_t *path) +{ + if (path[0] == L'\\' && (path[1] == L'\\' || path[1] == L'?') && path[2] == L'?' && path[3] == L'\\') + return 1; + + return 0; +} + +/** + * Checks for a device path prefix. + * see .NET6: PathInternal.IsDevice() + * we don't check forward slashes and extended paths (as already done) + * https://github.com/dotnet/runtime/blob/9260c249140ef90b4299d0fe1aa3037e25228518/src/libraries/Common/src/System/IO/PathInternal.Windows.cs#L132 + */ +static inline int path_is_device_path(const wchar_t *path) +{ + if (path[0] == L'\\' && path[1] == L'\\' && path[2] == L'.' && path[3] == L'\\') + return 1; + + return 0; +} + +/** + * Performs path normalization by calling GetFullPathNameW(). + * see .NET6: PathHelper.GetFullPathName() + * https://github.com/dotnet/runtime/blob/2a99e18eedabcf1add064c099da59d9301ce45e0/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs#L70 + */ +static inline int get_full_path_name(wchar_t **ppath_w) +{ + int num_chars; + wchar_t *temp_w; + + num_chars = GetFullPathNameW(*ppath_w, 0, NULL, NULL); + if (num_chars <= 0) { + errno = EINVAL; + return -1; + } + + temp_w = (wchar_t *)av_calloc(num_chars, sizeof(wchar_t)); + if (!temp_w) { + errno = ENOMEM; + return -1; + } + + num_chars = GetFullPathNameW(*ppath_w, num_chars, temp_w, NULL); + if (num_chars <= 0) { + av_free(temp_w); + errno = EINVAL; + return -1; + } + + av_freep(ppath_w); + *ppath_w = temp_w; + + return 0; +} + +/** + * Normalizes a Windows file or folder path. + * Expansion of short paths (with 8.3 path components) is currently omitted + * as it is not required for accessing long paths. + * see .NET6: PathHelper.Normalize() + * https://github.com/dotnet/runtime/blob/2a99e18eedabcf1add064c099da59d9301ce45e0/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs#L25 + */ +static inline int path_normalize(wchar_t **ppath_w) +{ + int ret; + + if ((ret = get_full_path_name(ppath_w)) < 0) + return ret; + + /* What .NET does at this point is to call PathHelper.TryExpandShortFileName() + * in case the path contains a '~' character. + * We don't need to do this as we don't need to normalize the file name + * for presentation, and the extended path prefix works with 8.3 path + * components as well + */ + return 0; +} + +/** + * Adds an extended path or UNC prefix to longs paths or paths ending + * with a space or a dot. (' ' or '.'). + * This function expects that the path has been normalized before by + * calling path_normalize() and it doesn't check whether the path is + * actually long (> MAX_PATH). + * see .NET6: PathInternal.EnsureExtendedPrefix() + * https://github.com/dotnet/runtime/blob/9260c249140ef90b4299d0fe1aa3037e25228518/src/libraries/Common/src/System/IO/PathInternal.Windows.cs#L107 + */ +static inline int add_extended_prefix(wchar_t **ppath_w) +{ + const wchar_t *unc_prefix = L"\\\\?\\UNC\\"; + const wchar_t *extended_path_prefix = L"\\\\?\\"; + const wchar_t *path_w = *ppath_w; + const size_t len = wcslen(path_w); + wchar_t *temp_w; + + /* We're skipping the check IsPartiallyQualified() because + * we expect to have called GetFullPathNameW() already. */ + if (len < 2 || path_is_extended(*ppath_w) || path_is_device_path(*ppath_w)) { + return 0; + } + + if (path_w[0] == L'\\' && path_w[1] == L'\\') { + /* unc_prefix length is 8 plus 1 for terminating zeros, + * we subtract 2 for the leading '\\' of the original path */ + temp_w = (wchar_t *)av_calloc(len - 2 + 8 + 1, sizeof(wchar_t)); + if (!temp_w) { + errno = ENOMEM; + return -1; + } + wcscpy(temp_w, unc_prefix); + wcscat(temp_w, path_w + 2); + } else { + // The length of extended_path_prefix is 4 plus 1 for terminating zeros + temp_w = (wchar_t *)av_calloc(len + 4 + 1, sizeof(wchar_t)); + if (!temp_w) { + errno = ENOMEM; + return -1; + } + wcscpy(temp_w, extended_path_prefix); + wcscat(temp_w, path_w); + } + + av_freep(ppath_w); + *ppath_w = temp_w; + + return 0; +} + +/** + * Converts a file or folder path to wchar_t for use with Windows file + * APIs. Paths with extended path prefix (either '\\?\' or \??\') are + * left unchanged. + * All other paths are normalized and converted to absolute paths. + * Longs paths (>= MAX_PATH) are prefixed with the extended path or extended + * UNC path prefix. + * see .NET6: Path.GetFullPath() and Path.GetFullPathInternal() + * https://github.com/dotnet/runtime/blob/2a99e18eedabcf1add064c099da59d9301ce45e0/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs#L126 + */ +static inline int get_extended_win32_path(const char *path, wchar_t **ppath_w) +{ + int ret; + size_t len; + + if ((ret = utf8towchar(path, ppath_w)) < 0) + return ret; + + if (path_is_extended(*ppath_w)) { + /* Paths prefixed with '\\?\' or \??\' are considered normalized by definition. + * Windows doesn't normalize those paths and neither should we. + */ + return 0; + } + + if ((ret = path_normalize(ppath_w)) < 0) { + av_freep(ppath_w); + return ret; + } + + /* see .NET6: PathInternal.EnsureExtendedPrefixIfNeeded() + * https://github.com/dotnet/runtime/blob/9260c249140ef90b4299d0fe1aa3037e25228518/src/libraries/Common/src/System/IO/PathInternal.Windows.cs#L92 + */ + len = wcslen(*ppath_w); + if (len >= MAX_PATH) { + if ((ret = add_extended_prefix(ppath_w)) < 0) { + av_freep(ppath_w); + return ret; + } + } + + return 0; +} + #endif #endif /* AVUTIL_WCHAR_FILENAME_H */ From patchwork Tue May 24 22:20:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 35912 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp766069pzj; Tue, 24 May 2022 15:21:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxLK2isL00stBtAgkbpx7VgWp5vFxYCJw0fCd8iQiqF+QwQdgg+FUUdb+41hdyGz12wQo2 X-Received: by 2002:a17:907:7674:b0:6fe:9ca3:2a55 with SMTP id kk20-20020a170907767400b006fe9ca32a55mr25413536ejc.125.1653430880740; Tue, 24 May 2022 15:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653430880; cv=none; d=google.com; s=arc-20160816; b=byM0171LA9UUxegPIdXD8LWe7qqlbrCumffAwWvivH4QHs1wbBPFpyLjgg7qUGq89V O7ZOOIluzFhcum+rwX5BOIWJTL/lzijBWOPSEnYyLbj/5Rxi302ccWXM0Pv3e/zdUWcF lAN3lSK1huca37CBgtJyY5uk5GlTfQcrTSzJohbkCpFEYplVb5HRFTn8rWDxLTdh5e8C rl6jxfyp7/XNyi7QLnFFSd55FLIOrxqawLrxz18+Ut7SyyRVQc7ekYwPj2kljIGIuyg3 a2Vwb7ujPjDVzKgJwYOVToQovc+5QkXQianFnjuuaXh10fj6UhZbnsm6sx3KSUjtXXB3 +FwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=m5ryowHryNYXDkjFc2coJfnHMAAR+S1179xFTM7XRgQ=; b=TIyaC8hT86AtotBFPfGNydz1xzZa1N2i1/oUlMj6KGzSjLU5s0xEUPc9GxN8GK0C9F STijKrgOzsQrxQluroTE5lIT6S9q3d+gKXxPtw1JTFhkBcCHpeCYODbLJhWk3G2Ct/m5 mEOabItv06jFY+ekbTWPTtqi3XcKo3rrcWl901gykWt9qozKmeTD++mLKxnWG92CX7JH x58M9PL0G8kE7w+rLODUf6wCToTkxQuZ0+y8QLDOPBTiwfO9PdGHObtQgUs8Kt1PZVx/ XrsKosjWPUbPZ16N1IlPjreSm6r2X8GML8UL4sAOi/r9N4Nz6mho4b6Vetv37UVSTr5h zbDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=ke6kyRmd; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id jg31-20020a170907971f00b006f3b5469ea0si10087005ejc.96.2022.05.24.15.21.20; Tue, 24 May 2022 15:21:20 -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 header.s=20210112 header.b=ke6kyRmd; 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=QUARANTINE 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 B2BE668B5AE; Wed, 25 May 2022 01:21:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D676C68B443 for ; Wed, 25 May 2022 01:20:56 +0300 (EEST) Received: by mail-pf1-f173.google.com with SMTP id y1so1610937pfr.6 for ; Tue, 24 May 2022 15:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=MYkqaEiTntTjEaeyog5bI7QVJPgf/1OR4jjI/zDztDQ=; b=ke6kyRmdnBLn9PRHI/7oLXX5FRH103HFei+nEk5MsTxKv+Y6D4T0I63qIxV6dnqpqu JczjbPduQMmIzAVbyL19itqRltN+Y/I+AhyZkX99ofmttOGULeATnK9RXtK707lnYHeK +V4g7LewsormMkdrWSzHSwTG8JaoB8rNp3incJ4L7xrmdryosU2XFMk/BXnuUVU/LGJW VIYTuRAWz7hiwHB8UpSkhZLHaXoj7I0NC8alYqS2+kRuLKcblyTRo0l5QbuDsNcGFyNK O7PBpNntQrfUHIBh6xREQJPUlmm1o/CEHikT7RIN2x/msy+OZCryf1N8QnIbW8dHhSZG PKcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=MYkqaEiTntTjEaeyog5bI7QVJPgf/1OR4jjI/zDztDQ=; b=R05qKlbO8BjdPIOV2Naw76xuOXbK7BN/s+qfV0fg8OuOByar85F2RNE3YyoJo/2MUW 6BHlG3zN0qR+7uHTL6KmbLQXzNYATtm+D6/xgy294lhx0k8ApU5KwLmAu+6euxsqf9PK QxqE1pVNU46hOj8Ye+FO+vtPYUj42hA44hJ/YNGGP2Is8M88CtmycqUEhKglElW3SWKa t0jWjYt616IWM1tNx87zdVCwxx3VcrBsTdMS97ZV5zhjLZXzovh/yqTvPvNZqnfMTDkR 1NpyOb5ojHISEX2TVCHMZbDfhsxchVx2QwieEOLUfHySVpmTM+G9XaiFSjLaDRK1hD6/ Q82g== X-Gm-Message-State: AOAM532v0peH/iN7WjRirIz0AXp+fgX6L4qresgTuGFUSuwa/zfuNtxb RRi5lbviFIHxacniuqHpRKKR7t1KPkQfiQ== X-Received: by 2002:a05:6a00:849:b0:518:bcbb:a6e1 with SMTP id q9-20020a056a00084900b00518bcbba6e1mr7607677pfk.86.1653430855268; Tue, 24 May 2022 15:20:55 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id o8-20020a62f908000000b0050dc76281fasm9785782pfh.212.2022.05.24.15.20.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 May 2022 15:20:54 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <7751335906bcaa5da249928c9830fcc75b01970c.1653430851.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Tue, 24 May 2022 22:20:50 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v7 2/3] avformat/os_support: Support long file names on Windows 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 Cc: Martin =?utf-8?q?Storsj=C3=B6?= , softworkz , Hendrik Leppkes Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 9jBbuJl4EcAF From: softworkz Signed-off-by: softworkz --- libavformat/os_support.h | 106 ++++++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 25 deletions(-) diff --git a/libavformat/os_support.h b/libavformat/os_support.h index 5e6b32d2dc..1c3b234b06 100644 --- a/libavformat/os_support.h +++ b/libavformat/os_support.h @@ -49,11 +49,28 @@ # ifdef stat # undef stat # endif -# define stat _stati64 + +# define stat win32_stat + + struct win32_stat + { + _dev_t st_dev; /* ID of device containing file */ + _ino_t st_ino; /* inode number */ + unsigned short st_mode; /* protection */ + short st_nlink; /* number of hard links */ + short st_uid; /* user ID of owner */ + short st_gid; /* group ID of owner */ + _dev_t st_rdev; /* device ID (if special file) */ + int64_t st_size; /* total size, in bytes */ + int64_t st_atime; /* time of last access */ + int64_t st_mtime; /* time of last modification */ + int64_t st_ctime; /* time of last status change */ + }; + # ifdef fstat # undef fstat # endif -# define fstat(f,s) _fstati64((f), (s)) +# define fstat win32_fstat #endif /* defined(_WIN32) */ @@ -153,7 +170,7 @@ static inline int win32_##name(const char *filename_utf8) \ wchar_t *filename_w; \ int ret; \ \ - if (utf8towchar(filename_utf8, &filename_w)) \ + if (get_extended_win32_path(filename_utf8, &filename_w)) \ return -1; \ if (!filename_w) \ goto fallback; \ @@ -171,37 +188,76 @@ DEF_FS_FUNCTION(unlink, _wunlink, _unlink) DEF_FS_FUNCTION(mkdir, _wmkdir, _mkdir) DEF_FS_FUNCTION(rmdir, _wrmdir , _rmdir) -#define DEF_FS_FUNCTION2(name, wfunc, afunc, partype) \ -static inline int win32_##name(const char *filename_utf8, partype par) \ -{ \ - wchar_t *filename_w; \ - int ret; \ - \ - if (utf8towchar(filename_utf8, &filename_w)) \ - return -1; \ - if (!filename_w) \ - goto fallback; \ - \ - ret = wfunc(filename_w, par); \ - av_free(filename_w); \ - return ret; \ - \ -fallback: \ - /* filename may be be in CP_ACP */ \ - return afunc(filename_utf8, par); \ +static inline int win32_access(const char *filename_utf8, int par) +{ + wchar_t *filename_w; + int ret; + if (get_extended_win32_path(filename_utf8, &filename_w)) + return -1; + if (!filename_w) + goto fallback; + ret = _waccess(filename_w, par); + av_free(filename_w); + return ret; +fallback: + return _access(filename_utf8, par); +} + +static inline void copy_stat(struct _stati64 *winstat, struct win32_stat *par) +{ + par->st_dev = winstat->st_dev; + par->st_ino = winstat->st_ino; + par->st_mode = winstat->st_mode; + par->st_nlink = winstat->st_nlink; + par->st_uid = winstat->st_uid; + par->st_gid = winstat->st_gid; + par->st_rdev = winstat->st_rdev; + par->st_size = winstat->st_size; + par->st_atime = winstat->st_atime; + par->st_mtime = winstat->st_mtime; + par->st_ctime = winstat->st_ctime; } -DEF_FS_FUNCTION2(access, _waccess, _access, int) -DEF_FS_FUNCTION2(stat, _wstati64, _stati64, struct stat*) +static inline int win32_stat(const char *filename_utf8, struct win32_stat *par) +{ + struct _stati64 winstat = { 0 }; + wchar_t *filename_w; + int ret; + + if (get_extended_win32_path(filename_utf8, &filename_w)) + return -1; + + if (filename_w) { + ret = _wstat64(filename_w, &winstat); + av_free(filename_w); + } else + ret = _stat64(filename_utf8, &winstat); + + copy_stat(&winstat, par); + + return ret; +} + +static inline int win32_fstat(int fd, struct win32_stat *par) +{ + struct _stati64 winstat = { 0 }; + int ret; + + ret = _fstat64(fd, &winstat); + + copy_stat(&winstat, par); + + return ret; +} static inline int win32_rename(const char *src_utf8, const char *dest_utf8) { wchar_t *src_w, *dest_w; int ret; - if (utf8towchar(src_utf8, &src_w)) + if (get_extended_win32_path(src_utf8, &src_w)) return -1; - if (utf8towchar(dest_utf8, &dest_w)) { + if (get_extended_win32_path(dest_utf8, &dest_w)) { av_free(src_w); return -1; } From patchwork Tue May 24 22:20:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 35913 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp766110pzj; Tue, 24 May 2022 15:21:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxEqGrU7OYvBVlhmmzdKmvmhk4c4NP0Mak/0EQsKjioKxvV8DzhhpVT6HRX+x7zdBJWg5c X-Received: by 2002:a05:6402:27d4:b0:42a:ed61:c591 with SMTP id c20-20020a05640227d400b0042aed61c591mr30751378ede.361.1653430889528; Tue, 24 May 2022 15:21:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653430889; cv=none; d=google.com; s=arc-20160816; b=CJkLGboVBJIsn7xyPzON+pclLXuOGH57ZpQJf/L+LgA1adzKkY7oiBy60+RBVPfXC0 n7Ab7WfTf1JBuZ/W8qotxBd0fsx27n+OkR0cvWZqvgsNWEy/V3GM+h5hZzbcRnQ8BPj0 drMFNb3kmeAq+IODY2STWvn6lTGLtxkUqShZaYKS8TG3oZ+HsoBOPMRT+YAEFhYkEYUF U21o5/nkTfluGjjcqbZwdPjGGDrxNPesWd5sQYeVdQRwT8QL9Ahx2GmNTzHYK/XcO2RT 9d8a/xv9iVb35mDtzzwPSADqXy0S4lP8G6GNrrmGF2JsRU3h7ZUKOzhlQn6n6aXJwJ9a 0aeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=MKGGsWTtOoDiDc4ZKXa55XjEEsJ+PRbZboWJmJJIwys=; b=DhUhw+tC1W4RYmth+w6d+CJ/GpmzQbu4Qi/CCJdqpy3fa6r21F9tWge1onwrkLuzKs D+RNhodYmDka+a28VA6sa5nBk3gn1+qYnGMkGTGp7ZgTSpfWHNNPHKERFKLNfDcOq0Rg hKLgQM8xwWW0u9mn5et3oU4+54IRsQ1R1Zn82XumAosFPXpQO3t7hjTUMx0ge2fPk9tA JKMeBYSYuH3q8au3ALOxq8qNhSrSs0fMABQk9al27DVvJPrv8F8soR2pxlyEF8ahthe8 uqGoVy6b1SN48nWHwkxUfpnxA0g123UIVAcCkRFzjk9b0ls3omg9vJDSw/kzjg3IPIvr a/+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=eGPAFwFu; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gb5-20020a170907960500b006f468ea7d57si20574749ejc.355.2022.05.24.15.21.29; Tue, 24 May 2022 15:21:29 -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 header.s=20210112 header.b=eGPAFwFu; 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=QUARANTINE 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 9BC8268B5B5; Wed, 25 May 2022 01:21:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CCA6268B443 for ; Wed, 25 May 2022 01:20:57 +0300 (EEST) Received: by mail-pf1-f169.google.com with SMTP id c14so17655568pfn.2 for ; Tue, 24 May 2022 15:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=GJ4FwzW2alurhInEkW/HsCPnnkTpZPdQRnVXPA2Vsq0=; b=eGPAFwFug81dptJOniYDsXrEVs8jdI/O4qDpQDwWQWLYSwUoVLLk0c4Z1r/mbrc6nK yt88nz6Li7HTh9Brwhmnko9QN8zujMfuAkdZaExx8tIkGcYyZGPZwurhG3FR0yCSFeNt IXq/6vky7xSHCzAomRPHG22vACl2lbM8kd4HBpcUTvUQalK4wTDcWMe3SpRXeWfAxNlV bWFQKitMs79+NQnczt6LKmWhraVgBA19BrJ8MB6udZyrjJ17zkAMG73MTLvlXMepapW5 rzZCNWdE+1GXyaXGUgxzKgRGfBY9RAURPGVkpnwCtjKrdF+Y5u11RXBQBXwfAzZut0dy c9/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=GJ4FwzW2alurhInEkW/HsCPnnkTpZPdQRnVXPA2Vsq0=; b=mE0Xn4n2fclM0XG0MTmGy9OYK1S/eE2n2bONnf6n1CkqgJVA4vUAE4DEu/G1kF3Qek Rp0GzcEyVXnrHeRC7ZmDXWy41BLi0CGeJlpJQWvHVbbtk29hDT5mgZdrPUS6tHUGbXiH +bAG6QBI/3DILuEs9jFeTyckEEQHqwUi3l1VfsDgq/zAMqHhSrGIgM3R0jhTktbJxU8/ lyCdsWV2MDikl3mfOioS1iXbtnh2QEmPqp/BstJ2CLeM/WMJAaSyl7GdPdQ9f6A/vAe6 VDfkZ+LUR4JxIOK4a6H4sjak1bx+sDm2JUFvjPfAjVcCfCfBTb5CXLCMTDMamUByhY0o EbqQ== X-Gm-Message-State: AOAM531tYRU7pyGFgdNwl9Ii6YMqIm0OhN5IbifsUfRlxOakjHFBoJGy Bw5m/tEGR2jtXNFKBYuMWMDjT3vTXSfVOQ== X-Received: by 2002:a63:ed43:0:b0:3ab:54ea:9914 with SMTP id m3-20020a63ed43000000b003ab54ea9914mr26237935pgk.172.1653430856234; Tue, 24 May 2022 15:20:56 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id u10-20020a6540ca000000b003c14af50617sm7075091pgp.47.2022.05.24.15.20.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 May 2022 15:20:55 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <0522fc231501cb5373da377e0d5738a3ef6e673d.1653430851.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Tue, 24 May 2022 22:20:51 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v7 3/3] avformat/file: remove _WIN32 condition 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 Cc: Martin =?utf-8?q?Storsj=C3=B6?= , softworkz , Hendrik Leppkes Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: DCRA2+SyRJ5m From: softworkz stat is now re-mapped with long path support in os_support.h Signed-off-by: softworkz --- libavformat/file.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libavformat/file.c b/libavformat/file.c index 063d7c5aa2..98c9e81bcb 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -154,11 +154,7 @@ static int file_check(URLContext *h, int mask) ret |= AVIO_FLAG_WRITE; #else struct stat st; -# ifndef _WIN32 ret = stat(filename, &st); -# else - ret = win32_stat(filename, &st); -# endif if (ret < 0) return AVERROR(errno);