libavformat: Remove MAX_PATH limit and use UTF-8 version of getenv()

1. getenv() is replaced with getenv_utf8() across libavformat.
2. New versions of AviSynth+ are now called with UTF-8 filenames.
3. Old versions of AviSynth are still using ANSI strings,
   but MAX_PATH limit on filename is removed.

Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
Nil Admirari
2022-06-20 13:30:00 +03:00
committed by Martin Storsjö
parent 13350e81fd
commit c381f5412f
4 changed files with 74 additions and 34 deletions

View File

@@ -20,6 +20,7 @@
*/
#include "libavutil/avstring.h"
#include "libavutil/getenv_utf8.h"
#include "libavutil/opt.h"
#include <sys/stat.h>
#include "os_support.h"
@@ -55,12 +56,15 @@ static int populate_ipfs_gateway(URLContext *h)
int stat_ret = 0;
int ret = AVERROR(EINVAL);
FILE *gateway_file = NULL;
char *env_ipfs_gateway, *env_ipfs_path;
// Test $IPFS_GATEWAY.
if (getenv("IPFS_GATEWAY") != NULL) {
if (snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), "%s",
getenv("IPFS_GATEWAY"))
>= sizeof(c->gateway_buffer)) {
env_ipfs_gateway = getenv_utf8("IPFS_GATEWAY");
if (env_ipfs_gateway != NULL) {
int printed = snprintf(c->gateway_buffer, sizeof(c->gateway_buffer),
"%s", env_ipfs_gateway);
freeenv_utf8(env_ipfs_gateway);
if (printed >= sizeof(c->gateway_buffer)) {
av_log(h, AV_LOG_WARNING,
"The IPFS_GATEWAY environment variable "
"exceeds the maximum length. "
@@ -77,20 +81,26 @@ static int populate_ipfs_gateway(URLContext *h)
// We need to know the IPFS folder to - eventually - read the contents of
// the "gateway" file which would tell us the gateway to use.
if (getenv("IPFS_PATH") == NULL) {
env_ipfs_path = getenv_utf8("IPFS_PATH");
if (env_ipfs_path == NULL) {
int printed;
char *env_home = getenv_utf8("HOME");
av_log(h, AV_LOG_DEBUG, "$IPFS_PATH is empty.\n");
// Try via the home folder.
if (getenv("HOME") == NULL) {
if (env_home == NULL) {
av_log(h, AV_LOG_WARNING, "$HOME appears to be empty.\n");
ret = AVERROR(EINVAL);
goto err;
}
// Verify the composed path fits.
if (snprintf(ipfs_full_data_folder, sizeof(ipfs_full_data_folder),
"%s/.ipfs/", getenv("HOME"))
>= sizeof(ipfs_full_data_folder)) {
printed = snprintf(
ipfs_full_data_folder, sizeof(ipfs_full_data_folder),
"%s/.ipfs/", env_home);
freeenv_utf8(env_home);
if (printed >= sizeof(ipfs_full_data_folder)) {
av_log(h, AV_LOG_WARNING,
"The IPFS data path exceeds the "
"max path length (%zu)\n",
@@ -113,9 +123,11 @@ static int populate_ipfs_gateway(URLContext *h)
goto err;
}
} else {
if (snprintf(ipfs_full_data_folder, sizeof(ipfs_full_data_folder), "%s",
getenv("IPFS_PATH"))
>= sizeof(ipfs_full_data_folder)) {
int printed = snprintf(
ipfs_full_data_folder, sizeof(ipfs_full_data_folder),
"%s", env_ipfs_path);
freeenv_utf8(env_ipfs_path);
if (printed >= sizeof(ipfs_full_data_folder)) {
av_log(h, AV_LOG_WARNING,
"The IPFS_PATH environment variable "
"exceeds the maximum length. "