diff --git a/src/framework/mlt_producer.c b/src/framework/mlt_producer.c index f8dd26ac8..904c9e029 100644 --- a/src/framework/mlt_producer.c +++ b/src/framework/mlt_producer.c @@ -3,7 +3,7 @@ * \brief abstraction for all producer services * \see mlt_producer_s * - * Copyright (C) 2003-2022 Meltytech, LLC + * Copyright (C) 2003-2023 Meltytech, LLC * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -1256,7 +1256,7 @@ int64_t mlt_producer_get_creation_time(mlt_producer self) } if (resource) { struct stat file_info; - if (!stat(resource, &file_info)) { + if (!mlt_stat(resource, &file_info)) { return (int64_t) file_info.st_mtime * 1000; } } diff --git a/src/framework/mlt_properties.c b/src/framework/mlt_properties.c index b25e75c28..284e4dd8f 100644 --- a/src/framework/mlt_properties.c +++ b/src/framework/mlt_properties.c @@ -3,7 +3,7 @@ * \brief Properties class definition * \see mlt_properties_s * - * Copyright (C) 2003-2022 Meltytech, LLC + * Copyright (C) 2003-2023 Meltytech, LLC * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -288,7 +288,7 @@ int mlt_properties_preset(mlt_properties self, const char *name) return 1; // See if name is an explicit file - if (!stat(name, &stat_buff)) { + if (!mlt_stat(name, &stat_buff)) { return load_properties(self, name); } else { // Look for profile-specific preset before a generic one. diff --git a/src/framework/mlt_repository.c b/src/framework/mlt_repository.c index 96463d20a..caedf2139 100644 --- a/src/framework/mlt_repository.c +++ b/src/framework/mlt_repository.c @@ -567,7 +567,7 @@ static void list_presets(mlt_properties properties, const char *path, const char struct stat info; snprintf(fullname, sizeof(fullname), "%s/%s", dirname, de->d_name); - stat(fullname, &info); + mlt_stat(fullname, &info); if (S_ISDIR(info.st_mode)) { // recurse into subdirectories char sub[PATH_MAX]; diff --git a/src/framework/mlt_types.h b/src/framework/mlt_types.h index 59c61ae65..a1bb3cbc7 100644 --- a/src/framework/mlt_types.h +++ b/src/framework/mlt_types.h @@ -304,12 +304,17 @@ extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); extern int setenv(const char *name, const char *value, int overwrite); extern char *getlocale(); extern FILE *win32_fopen(const char *filename_utf8, const char *mode_utf8); +#include +#include +extern int win32_stat(const char *filename_utf8, struct stat *buffer); #include extern char *strptime(const char *buf, const char *fmt, struct tm *tm); #define mlt_fopen win32_fopen +#define mlt_stat win32_stat #define MLT_DIRLIST_DELIMITER ";" #else #define mlt_fopen fopen +#define mlt_stat stat #define MLT_DIRLIST_DELIMITER ":" #endif /* ifdef _WIN32 */ diff --git a/src/modules/frei0r/factory.c b/src/modules/frei0r/factory.c index db324c10b..10b68ff27 100644 --- a/src/modules/frei0r/factory.c +++ b/src/modules/frei0r/factory.c @@ -125,7 +125,7 @@ static mlt_properties fill_param_info(mlt_service_type type, const char *service servicetype, service_name); memset(&stat_buff, 0, sizeof(stat_buff)); - stat(file, &stat_buff); + mlt_stat(file, &stat_buff); if (S_ISREG(stat_buff.st_mode)) { return mlt_properties_parse_yaml(file); diff --git a/src/modules/gdk/producer_pixbuf.c b/src/modules/gdk/producer_pixbuf.c index cd018e474..afc9e4ba5 100644 --- a/src/modules/gdk/producer_pixbuf.c +++ b/src/modules/gdk/producer_pixbuf.c @@ -1,6 +1,6 @@ /* * producer_pixbuf.c -- raster image loader based upon gdk-pixbuf - * Copyright (C) 2003-2021 Meltytech, LLC + * Copyright (C) 2003-2023 Meltytech, LLC * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -212,7 +212,7 @@ static int load_sequence_sprintf(producer_pixbuf self, while (gap < 100) { struct stat buf; snprintf(full, 1023, filename, i++); - if (stat(full, &buf) == 0) { + if (mlt_stat(full, &buf) == 0) { sprintf(key, "%d", keyvalue++); mlt_properties_set(self->filenames, key, full); gap = 0; @@ -341,7 +341,7 @@ static int load_sequence_csv(producer_pixbuf self, mlt_properties properties, co break; } - if (stat(line, &buf) != 0) { + if (mlt_stat(line, &buf) != 0) { break; } diff --git a/src/modules/opencv/filter_opencv_tracker.cpp b/src/modules/opencv/filter_opencv_tracker.cpp index 59366ae52..970209678 100644 --- a/src/modules/opencv/filter_opencv_tracker.cpp +++ b/src/modules/opencv/filter_opencv_tracker.cpp @@ -1,6 +1,7 @@ /* * filter_tracker.cpp -- Motion tracker * Copyright (C) 2016 Jean-Baptiste Mardelle + * Copyright (C) 2023 Meltytech, LLC * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -175,8 +176,8 @@ static void analyze(mlt_filter filter, // - kernel_r1: https://www.dropbox.com/s/999cqx5zrfi7w4p/dasiamrpn_kernel_r1.onnx?dl=0 // - kernel_cls1: https://www.dropbox.com/s/qvmtszx5h339a0w/dasiamrpn_kernel_cls1.onnx?dl=0 struct stat file_info; - if (stat(model1, &file_info) == 0 && stat(model2, &file_info) == 0 - && stat(model3, &file_info) == 0) { + if (mlt_stat(model1, &file_info) == 0 && mlt_stat(model2, &file_info) == 0 + && mlt_stat(model3, &file_info) == 0) { // Models found, process parameters.model = model1; parameters.kernel_cls1 = model2; @@ -205,7 +206,7 @@ static void analyze(mlt_filter filter, // Models can be downloaded from: // https://github.com/HonglinChu/SiamTrackers/tree/master/NanoTrack/models/nanotrackv2 struct stat file_info; - if (stat(model1, &file_info) == 0 && stat(model2, &file_info) == 0) { + if (mlt_stat(model1, &file_info) == 0 && mlt_stat(model2, &file_info) == 0) { // Models found, process parameters.backbone = model1; parameters.neckhead = model2; diff --git a/src/modules/plus/filter_dynamictext.c b/src/modules/plus/filter_dynamictext.c index 19981cd99..517b71929 100644 --- a/src/modules/plus/filter_dynamictext.c +++ b/src/modules/plus/filter_dynamictext.c @@ -100,7 +100,7 @@ static void get_filedate_str(const char *keyword, mlt_filter filter, mlt_frame f char *filename = mlt_properties_get(producer_properties, "resource"); struct stat file_info; - if (!stat(filename, &file_info)) { + if (!mlt_stat(filename, &file_info)) { const char *format = "%Y/%m/%d"; int n = strlen("filedate") + 1; struct tm *time_info = gmtime(&(file_info.st_mtime)); @@ -124,7 +124,7 @@ static void get_localfiledate_str(const char *keyword, char *filename = mlt_properties_get(producer_properties, "resource"); struct stat file_info; - if (!stat(filename, &file_info)) { + if (!mlt_stat(filename, &file_info)) { const char *format = "%Y/%m/%d"; int n = strlen("localfiledate") + 1; struct tm *time_info = localtime(&(file_info.st_mtime)); @@ -167,7 +167,8 @@ static void get_filename_str(mlt_filter filter, mlt_frame frame, char *text) mlt_producer producer = mlt_producer_cut_parent(mlt_frame_get_original_producer(frame)); mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES(producer); char *filename = mlt_properties_get(producer_properties, "resource"); - if (access(filename, F_OK) == 0) { + struct stat file_info; + if (!mlt_stat(filename, &file_info)) { strncat(text, basename(filename), MAX_TEXT_LEN - strlen(text) - 1); } } @@ -177,7 +178,8 @@ static void get_basename_str(mlt_filter filter, mlt_frame frame, char *text) mlt_producer producer = mlt_producer_cut_parent(mlt_frame_get_original_producer(frame)); mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES(producer); char *filename = strdup(mlt_properties_get(producer_properties, "resource")); - if (access(filename, F_OK) == 0) { + struct stat file_info; + if (!mlt_stat(filename, &file_info)) { char *bname = basename(filename); char *ext = strrchr(bname, '.'); if (ext) { diff --git a/src/modules/qt/qimage_wrapper.cpp b/src/modules/qt/qimage_wrapper.cpp index b028a4511..d757edcd1 100644 --- a/src/modules/qt/qimage_wrapper.cpp +++ b/src/modules/qt/qimage_wrapper.cpp @@ -1,6 +1,6 @@ /* * qimage_wrapper.cpp -- a Qt/QImage based producer for MLT - * Copyright (C) 2006-2022 Meltytech, LLC + * Copyright (C) 2006-2023 Meltytech, LLC * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -500,7 +500,7 @@ int load_sequence_sprintf(producer_qimage self, mlt_properties properties, const for (int gap = 0; gap < 100;) { struct stat buf; snprintf(full, 1023, filename, i++); - if (stat(full, &buf) == 0) { + if (mlt_stat(full, &buf) == 0) { sprintf(key, "%d", keyvalue++); mlt_properties_set(self->filenames, key, full); gap = 0; diff --git a/src/win32/win32.c b/src/win32/win32.c index 8267b67b5..f3e7809d0 100644 --- a/src/win32/win32.c +++ b/src/win32/win32.c @@ -2,7 +2,7 @@ * \file win32.c * \brief Miscellaneous utility functions for Windows. * - * Copyright (C) 2003-2016 Meltytech, LLC + * Copyright (C) 2003-2023 Meltytech, LLC * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include "../framework/mlt_properties.h" #include "../framework/mlt_log.h" @@ -265,3 +267,23 @@ FILE* win32_fopen(const char *filename_utf8, const char *mode_utf8) // Try with regular old fopen. return fopen(filename_utf8, mode_utf8); } + +int win32_stat(const char *filename_utf8, struct stat *buffer) +{ + int ret = stat(filename_utf8, buffer); + if (!ret) { + return ret; + } + // Convert UTF-8 to wide chars. + int n = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename_utf8, -1, NULL, 0); + if (n > 0) { + wchar_t *filename_w = (wchar_t *) calloc(n, sizeof(wchar_t)); + if (filename_w) { + MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, filename_w, n); + ret = _wstat(filename_w, (struct _stat *)buffer); + free(filename_w); + return ret; + } + } + return ret; +} \ No newline at end of file