From patchwork Fri May 20 21:12:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 35856 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a17:906:4548:b0:6fe:2728:7bda with SMTP id s8csp1436391ejq; Fri, 20 May 2022 14:13:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhnTG/Y5DZDUpNY2TTM/w3Pz2mkLnGc/mWpFF5jaHkLHF/Xb58Jxb4QFUcCZXuE6eO04H9 X-Received: by 2002:aa7:db10:0:b0:42a:a983:a5d6 with SMTP id t16-20020aa7db10000000b0042aa983a5d6mr13023491eds.312.1653081192633; Fri, 20 May 2022 14:13:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653081192; cv=none; d=google.com; s=arc-20160816; b=RWg2tdUQui7wqgKJVKt1uX1hbGz3FUJA9xz3IqM2B3hnf9XiNhWNd6Fv2uK3HQSQHU 9c7dx0tr0kuZEierrVv30lUynmdi5Qs+8tb2rc+X4TqvFTNdpfRo+c3i4koUtGo4daCw nH5pdaZ3Z3yr6uG5gDtq6xeVc3BXQdqasZIX2vxUb1JcFBwxt0wU5Rp5PDb0GZpzWiQh bbKfNuvEN9o06ChNevBVHpfMZCFSczjmYZVcLFnFYQ4aowolfq/mPBCWzsUKQLsIZ3Hb Wpfa3FJbvD2K/KCESEpl4QRRZS+I7kwzkSuELK+URcLeDZsadd6XSpPj3Yv1SI+0VP5+ lQ0w== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=wYWhLZzLVbXZw5crtYEUO9gntdhr0wO0sJgZShk3jy4=; b=UwvmH/ddM7YfCnqnYbHCUrh5DXS3BX2Sqyyixuv0/G4UlAb692IJmpb8fxY4rIRX9H C4q2Hq0/5kVNWvbmCkmHtIiLc/osrF8Wbc10QQ1rhCIlcMVAIUxkQTNm5+eTOaGgGegj kDcOHCLxV3ytWuTQ9IQQqLjvZUDU8HbeguvHaWLMHS1J9uUqIVXHKQ+f6mEVVZ7gV099 MEZBW5SH5BfJxKf0mivfRacoH8H4jmNcY79LUosG6HgppHsf0HPqlznysxvAdqyjfMFv Qn+wKkumoNvH9lX4IB+dbP1ql6BmcRdHVLRDLKO4n6YTcGe0HYkDFUuOKZuhqjitnsQC BSXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@martin-st.20210112.gappssmtp.com header.s=20210112 header.b=yd06ns6e; 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 cw19-20020a170906479300b006fe1c07f388si3773950ejc.827.2022.05.20.14.13.06; Fri, 20 May 2022 14:13: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=@martin-st.20210112.gappssmtp.com header.s=20210112 header.b=yd06ns6e; 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 5DF9368B48F; Sat, 21 May 2022 00:13:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DF7FD68B2A8 for ; Sat, 21 May 2022 00:12:56 +0300 (EEST) Received: by mail-wm1-f54.google.com with SMTP id ay35so3551928wmb.5 for ; Fri, 20 May 2022 14:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=h+mTlvg8h49b+TJB7PBBfv5/KyYrOJmAZIyOkWNR1A8=; b=yd06ns6ehSWlIXqVkJykGyMv4e60gcMuw8tmIQ+LL9pg0mkimtSQn/Mzn2862/uygv OUFzEBfn4TXw1xE9Nvz36rykyr2Lbb8Dc3tDhwbNVwWUWqUZVboFydLUYO21VprccPGR hQx0KZ7bk5aOgzGR+/xt4SQEDHOUR/7ICx34+nYvCGofMjTjEClGpvpwMxkEut8JmJ26 20ZWmU03ba7xMEuLOrI5AdrDR6BFoTrf6xUb3LnYg0+xbRn0xI06/HRprUUTuAgGYYUV iFgaz30EEXahj/oLRiTMN9uVpr9QHO2Mu9bQW4P+iSUBjdArIDXkLqSfzx/SiDn3NpSV I2LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=h+mTlvg8h49b+TJB7PBBfv5/KyYrOJmAZIyOkWNR1A8=; b=WyU/i9FZh+uIE+XUuC9UgT2NI/InWIxK6Bq4PU2bkJMOf1Qf/1BMqllO6xKFTQel4m ync4Ua8JETVeTw80Ya7ofePMJKcqfC1I9Ql6fZsPoRoH52W1ahrfhhXZD7/zQ+g4C7r0 +YM1kWv5NP8m42DNHZoxaMAhDaEJllTccG5yAA83k/0EDEEXVPjwdvTWtQT/iMtWuRE7 d9htQT+R5YPj1N6q8JJf8t96rZDWx6ObuLgaZ8S95mVCC1oLbZjyf6Yw2JU2VqscQhJu tLnBQPZTGbFLGnkRHc9uAmb/mAnraKtpgTt935z1KMP0J8G4869q6V+a1uB+a1nl5hGi QLfA== X-Gm-Message-State: AOAM530yjQ+KmhA4Ft6xXnGAtNjWoGTXZgV5GP4UfZsmmYENppteCA04 lQH3RyZT6adZ+VtnP4mVBR330vWgKpTVXsi7 X-Received: by 2002:a7b:cd97:0:b0:38f:f785:ff8 with SMTP id y23-20020a7bcd97000000b0038ff7850ff8mr10059605wmj.44.1653081176267; Fri, 20 May 2022 14:12:56 -0700 (PDT) Received: from localhost (host-97-187.parnet.fi. [77.234.97.187]) by smtp.gmail.com with ESMTPSA id n19-20020a05600c3b9300b003942a244ecbsm2952090wms.16.2022.05.20.14.12.55 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 20 May 2022 14:12:55 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 21 May 2022 00:12:52 +0300 Message-Id: <20220520211254.47116-1-martin@martin.st> X-Mailer: git-send-email 2.32.0 (Apple Git-132) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] fftools: Stop using av_fopen_utf8 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: zrITePTJ6L5n Provide a header based inline reimplementation of it. Using av_fopen_utf8 doesn't work outside of the libraries when built with MSVC as shared libraries (in the default configuration, where each DLL gets a separate statically linked CRT). --- fftools/ffmpeg_opt.c | 3 +- fftools/fopen_utf8.h | 71 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 fftools/fopen_utf8.h diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 47e8b9b7bd..a5cd989d35 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -28,6 +28,7 @@ #endif #include "ffmpeg.h" +#include "fopen_utf8.h" #include "cmdutils.h" #include "opt_common.h" @@ -1882,7 +1883,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in video_enc->stats_in = logbuffer; } if (video_enc->flags & AV_CODEC_FLAG_PASS1) { - f = av_fopen_utf8(logfilename, "wb"); + f = fopen_utf8(logfilename, "wb"); if (!f) { av_log(NULL, AV_LOG_FATAL, "Cannot write log file '%s' for pass-1 encoding: %s\n", diff --git a/fftools/fopen_utf8.h b/fftools/fopen_utf8.h new file mode 100644 index 0000000000..db57fcaec4 --- /dev/null +++ b/fftools/fopen_utf8.h @@ -0,0 +1,71 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFTOOLS_FOPEN_UTF8_H +#define FFTOOLS_FOPEN_UTF8_H + +#include + +/* The fopen_utf8 function here is essentially equivalent to av_fopen_utf8, + * except that it doesn't set O_CLOEXEC, and that it isn't exported + * from a different library. (On Windows, each DLL might use a different + * CRT, and FILE* handles can't be shared across them.) */ + +#ifdef _WIN32 +#include "libavutil/wchar_filename.h" + +static inline FILE *fopen_utf8(const char *path_utf8, const char *mode) +{ + wchar_t *path_w, *mode_w; + FILE *f; + + /* convert UTF-8 to wide chars */ + if (utf8towchar(path_utf8, &path_w)) /* This sets errno on error. */ + return NULL; + if (!path_w) + goto fallback; + + if (utf8towchar(mode, &mode_w)) + return NULL; + if (!mode_w) { + /* If failing to interpret the mode string as utf8, it is an invalid + * parameter. */ + av_freep(&path_w); + errno = EINVAL; + return NULL; + } + + f = _wfopen(path_w, mode_w); + av_freep(&path_w); + av_freep(&mode_w); + + return f; +fallback: + /* path may be in CP_ACP */ + return fopen(path_utf8, mode); +} + +#else + +static inline FILE *fopen_utf8(const char *path, const char *mode) +{ + return fopen(path, mode); +} +#endif + +#endif /* FFTOOLS_FOPEN_UTF8_H */