From: Nil Admirari <nil-admirari@mailo.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH v16 3/5] fftools: Remove MAX_PATH limit and switch to UTF-8 versions of fopen() and getenv()
Date: Wed, 15 Jun 2022 23:03:42 +0300
Message-ID: <20220615200344.17211-3-nil-admirari@mailo.com> (raw)
In-Reply-To: <20220615200344.17211-1-nil-admirari@mailo.com>
---
fftools/cmdutils.c | 53 +++++++++++++++++++++++++++++++++-----------
fftools/ffmpeg_opt.c | 9 ++++++--
2 files changed, 47 insertions(+), 15 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 5d7cdc3e10..5e7fbbe2ee 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -39,6 +39,7 @@
#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
#include "libavutil/display.h"
+#include "libavutil/getenv_utf8.h"
#include "libavutil/mathematics.h"
#include "libavutil/imgutils.h"
#include "libavutil/libm.h"
@@ -47,9 +48,11 @@
#include "libavutil/dict.h"
#include "libavutil/opt.h"
#include "cmdutils.h"
+#include "fopen_utf8.h"
#include "opt_common.h"
#ifdef _WIN32
#include <windows.h>
+#include "compat/w32dlfcn.h"
#endif
AVDictionary *sws_dict;
@@ -465,7 +468,7 @@ static void check_options(const OptionDef *po)
void parse_loglevel(int argc, char **argv, const OptionDef *options)
{
int idx = locate_option(argc, argv, options, "loglevel");
- const char *env;
+ char *env;
check_options(options);
@@ -474,7 +477,8 @@ void parse_loglevel(int argc, char **argv, const OptionDef *options)
if (idx && argv[idx + 1])
opt_loglevel(NULL, "loglevel", argv[idx + 1]);
idx = locate_option(argc, argv, options, "report");
- if ((env = getenv("FFREPORT")) || idx) {
+ env = getenv_utf8("FFREPORT");
+ if (env || idx) {
FILE *report_file = NULL;
init_report(env, &report_file);
if (report_file) {
@@ -487,6 +491,7 @@ void parse_loglevel(int argc, char **argv, const OptionDef *options)
fflush(report_file);
}
}
+ av_free(env);
idx = locate_option(argc, argv, options, "hide_banner");
if (idx)
hide_banner = 1;
@@ -812,28 +817,45 @@ FILE *get_preset_file(char *filename, size_t filename_size,
{
FILE *f = NULL;
int i;
- const char *base[3] = { getenv("FFMPEG_DATADIR"),
- getenv("HOME"),
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+ char *datadir = NULL;
+#endif
+ char *env_home = getenv_utf8("HOME");
+ char *env_ffmpeg_datadir = getenv_utf8("FFMPEG_DATADIR");
+ const char *base[3] = { env_home,
+ env_ffmpeg_datadir,
FFMPEG_DATADIR, };
if (is_path) {
av_strlcpy(filename, preset_name, filename_size);
- f = fopen(filename, "r");
+ f = fopen_utf8(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 (wchartoutf8(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
@@ -842,17 +864,22 @@ FILE *get_preset_file(char *filename, size_t filename_size,
continue;
snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
i != 1 ? "" : "/.ffmpeg", preset_name);
- f = fopen(filename, "r");
+ f = fopen_utf8(filename, "r");
if (!f && codec_name) {
snprintf(filename, filename_size,
"%s%s/%s-%s.ffpreset",
base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
preset_name);
- f = fopen(filename, "r");
+ f = fopen_utf8(filename, "r");
}
}
}
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+ av_free(datadir);
+#endif
+ av_free(env_ffmpeg_datadir);
+ av_free(env_home);
return f;
}
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 398067da96..f49acf6ad0 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -44,6 +44,7 @@
#include "libavutil/avutil.h"
#include "libavutil/bprint.h"
#include "libavutil/channel_layout.h"
+#include "libavutil/getenv_utf8.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/fifo.h"
#include "libavutil/mathematics.h"
@@ -1402,8 +1403,10 @@ static int get_preset_file_2(const char *preset_name, const char *codec_name, AV
{
int i, ret = -1;
char filename[1000];
- const char *base[3] = { getenv("AVCONV_DATADIR"),
- getenv("HOME"),
+ char *env_avconv_datadir = getenv_utf8("AVCONV_DATADIR");
+ char *env_home = getenv_utf8("HOME");
+ const char *base[3] = { env_avconv_datadir,
+ env_home,
AVCONV_DATADIR,
};
@@ -1421,6 +1424,8 @@ static int get_preset_file_2(const char *preset_name, const char *codec_name, AV
ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
}
}
+ av_free(env_home);
+ av_free(env_avconv_datadir);
return ret;
}
--
2.34.1
_______________________________________________
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".
next prev parent reply other threads:[~2022-06-15 20:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-15 20:03 [FFmpeg-devel] [PATCH v16 1/5] libavutil: Add wchartoutf8(), wchartoansi(), utf8toansi() and getenv_utf8() Nil Admirari
2022-06-15 20:03 ` [FFmpeg-devel] [PATCH v16 2/5] compat/w32dlfcn.h: Remove MAX_PATH limit and replace LoadLibraryExA with LoadLibraryExW Nil Admirari
2022-06-15 20:03 ` Nil Admirari [this message]
2022-06-15 20:03 ` [FFmpeg-devel] [PATCH v16 4/5] libavformat: Remove MAX_PATH limit and use UTF-8 version of getenv() Nil Admirari
2022-06-15 20:03 ` [FFmpeg-devel] [PATCH v16 5/5] libavfilter/vf_frei0r.c: Use " Nil Admirari
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220615200344.17211-3-nil-admirari@mailo.com \
--to=nil-admirari@mailo.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git