From dab29f44d315774083ea1fb2dc90fbbf41f16446 Mon Sep 17 00:00:00 2001 From: Kartatz <105828205+Kartatz@users.noreply.github.com> Date: Sat, 1 Jun 2024 19:36:41 -0300 Subject: [PATCH] Update to GCC 14.1.0 --- .github/workflows/build.yml | 12 +-- CMakeLists.txt | 19 +---- src/biggestint.c | 27 +++++++ src/biggestint.h | 3 + src/filesystem.c | 125 ------------------------------ src/filesystem.h | 1 - src/getdents.c | 150 ------------------------------------ src/getdents.h | 62 --------------- src/m3u8.c | 7 +- src/m3u8download.c | 4 +- src/m3u8parser.c | 8 +- src/main.c | 8 +- src/readlines.c | 4 +- src/walkdir.h | 11 ++- 14 files changed, 67 insertions(+), 374 deletions(-) create mode 100644 src/biggestint.c delete mode 100644 src/getdents.c delete mode 100644 src/getdents.h diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5ed7589..615d50e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,12 +52,12 @@ jobs: - name: Increase swap space run: | sudo swapoff -a - sudo fallocate -l 15G '/mnt/swapfile' + sudo fallocate -l '15G' '/mnt/swapfile' sudo mkswap '/mnt/swapfile' sudo swapon '/mnt/swapfile' - name: Install required dependencies run: | - sudo apt-get install libxml2-dev + sudo apt-get install 'libxml2-dev' - name: Setup Linux cross-compiler run: | declare -r SPHYNX_TAG="$(jq --raw-output '.tag_name' <<< "$(curl --connect-timeout '10' --retry '15' --retry-all-errors --fail --silent --url 'https://api.github.com/repos/AmanoTeam/Sphynx/releases/latest')")" @@ -269,7 +269,7 @@ jobs: echo '/tmp/nul/bin' >> "${GITHUB_PATH}" - name: Build with CMake run: | - declare -r targets=( + declare -ra targets=( x86_64-unknown-linux-gnu # hppa-unknown-openbsd arm-unknown-openbsd @@ -391,7 +391,7 @@ jobs: for target in "${targets[@]}"; do echo "Building for ${target}" - KAI_ENABLE_LTO='ON' + KAI_ENABLE_LTO='OFF' if [[ "${target}" == *-apple-darwin ]] || [[ "${target}" == *-w64-mingw32 ]] || [[ "${target}" == *-unknown-openbsd ]]; then KAI_ENABLE_LTO=OFF @@ -401,7 +401,7 @@ jobs: -DKAI_ENABLE_LTO="${KAI_ENABLE_LTO}" \ -DCMAKE_TOOLCHAIN_FILE="./.github/workflows/cmake_toolchains/${target}.cmake" \ -DCMAKE_INSTALL_PREFIX="${target}" \ - -DCMAKE_BUILD_TYPE='MinSizeRel' ../ + -DCMAKE_BUILD_TYPE='MinSizeRel' ../ 1>/dev/null pushd './ffmpeg-build' make --jobs 1>/dev/null @@ -412,6 +412,8 @@ jobs: cmake --build ./ -- --jobs 1>/dev/null cmake --install ./ --strip 1>/dev/null + chmod 644 "${target}/lib/libav"* + if [[ "${target}" == *'mingw32' ]]; then zip --recurse-paths -9 "${OUTPUT_DIRECTORY}/${target}.zip" "${target}" 1>/dev/null else diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d6879d..5b869b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -442,6 +442,7 @@ set( --enable-small --enable-version3 --extra-cflags=-Dstatic_assert=_Static_assert + --extra-cflags=-w --extra-ldflags=-fPIC --prefix="${FFMPEG_INSTALL_PREFIX}" ) @@ -646,7 +647,7 @@ foreach(source ${libraries}) endif() if (UNIX) - if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android") + if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD") string(APPEND destination "${CMAKE_SHARED_LIBRARY_SUFFIX}") elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") string(APPEND destination "${SOVERSION_SEPARATOR}${major_version}${CMAKE_SHARED_LIBRARY_SUFFIX}") @@ -714,16 +715,9 @@ add_executable( src/showformats.c src/callbacks.c src/resources.c + src/biggestint.c ) -if (NOT (WIN32 OR SERENITYOS)) - target_sources( - kai - PRIVATE - src/getdents.c - ) -endif() - foreach(target kai) target_compile_options( ${target} @@ -855,13 +849,6 @@ target_link_libraries( # libswresample ) -if (WIN32) - target_link_libraries( - kai - shlwapi - ) -endif() - foreach(target kai bearssl libcurl_shared) install( TARGETS ${target} diff --git a/src/biggestint.c b/src/biggestint.c new file mode 100644 index 0000000..61477d7 --- /dev/null +++ b/src/biggestint.c @@ -0,0 +1,27 @@ +#include + +#include "biggestint.h" + +bigint_t ptobigint(const void* const pointer) { + /* + Convert a pointer to a bigint_t. + */ + + const intptr_t value = (intptr_t) pointer; + const bigint_t result = (bigint_t) value; + + return result; + +} + +biguint_t ptobiguint(const void* const pointer) { + /* + Convert a pointer to a biguint_t. + */ + + const uintptr_t value = (uintptr_t) pointer; + const biguint_t result = (biguint_t) value; + + return result; + +} diff --git a/src/biggestint.h b/src/biggestint.h index 8ac6386..12c0b50 100644 --- a/src/biggestint.h +++ b/src/biggestint.h @@ -37,4 +37,7 @@ typedef long double bigfloat_t; #define strtobui strtoul #endif +bigint_t ptobigint(const void* const pointer); +biguint_t ptobiguint(const void* const pointer); + #endif \ No newline at end of file diff --git a/src/filesystem.c b/src/filesystem.c index 229ecbf..8ceeb14 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -4,7 +4,6 @@ #if defined(_WIN32) #include #include - #include #endif #if defined(__FreeBSD__) @@ -41,10 +40,6 @@ #include "walkdir.h" #include "pathsep.h" -#if !(defined(_WIN32) || defined(__serenity__)) - #include "getdents.h" -#endif - #if defined(_WIN32) || defined(__OpenBSD__) #include "path.h" #endif @@ -466,126 +461,6 @@ int directory_exists(const char* const directory) { } -int directory_empty(const char* const directory) { - /* - Determines whether a specified path is an empty directory. - - Returns (1) if directory is empty, (0) if it does not, (-1) on error. - */ - - #if defined(_WIN32) - DWORD attributes = 0; - BOOL status = FALSE; - - #if defined(_UNICODE) - wchar_t* wdirectory = NULL; - - /* This prefix is required to support long paths in Windows 10+ */ - const size_t prefixs = isabsolute(directory) ? wcslen(WIN10_LONG_PATH_PREFIX) : 0; - - const int wdirectorys = MultiByteToWideChar(CP_UTF8, 0, directory, -1, NULL, 0); - - if (wdirectorys == 0) { - return -1; - } - - wdirectory = malloc(prefixs + (size_t) wdirectorys); - - if (wdirectory == NULL) { - return -1; - } - - if (prefixs > 0) { - wcscpy(wdirectory, WIN10_LONG_PATH_PREFIX); - } - - if (MultiByteToWideChar(CP_UTF8, 0, directory, -1, wdirectory + prefixs, wdirectorys) == 0) { - free(wdirectory); - return -1; - } - - attributes = GetFileAttributesW(wdirectory); - #else - attributes = GetFileAttributesA(directory); - #endif - - if (attributes == INVALID_FILE_ATTRIBUTES) { - #if defined(_UNICODE) - free(wdirectory); - #endif - - return -1; - } - - if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { - #if defined(_UNICODE) - free(wdirectory); - #endif - - return -1; - } - - #if defined(_UNICODE) - status = PathIsDirectoryEmptyW(wdirectory); - #else - status = PathIsDirectoryEmptyA(directory); - #endif - - #if defined(_UNICODE) - free(wdirectory); - #endif - - return (int) status; - #else - #if !defined(__serenity__) - long index = 0; - - directory_entry_t item; - directory_entry_t items[3]; - - const int fd = open_dir(directory); - - if (fd == -1) { - return -1; - } - - while (1) { - const ssize_t size = get_directory_entries(fd, (char*) items, sizeof(items)); - - if (size == 0) { - close_dir(fd); - break; - } - - if (size == -1) { - close_dir(fd); - - if (errno == EINVAL) { - return 0; - } - - return -1; - } - - for (index = 0; index < size;) { - const char* const ptr = (((char*) items) + index); - memcpy(&item, ptr, sizeof(item)); - - if (!(strcmp(item.d_name, ".") == 0 || strcmp(item.d_name, "..") == 0)) { - close(fd); - return 0; - } - - index += directory_entry_size(&item); - } - } - #endif - - return 1; - #endif - -} - int file_exists(const char* const filename) { /* Checks if file exists and is a regular file or symlink. diff --git a/src/filesystem.h b/src/filesystem.h index 950b932..d622b33 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -8,7 +8,6 @@ int file_exists(const char* const filename); int create_directory(const char* const directory); int move_file(const char* const source, const char* const destination); int copy_file(const char* const source, const char* const destination); -int directory_empty(const char* const directory); #define remove_directory(directory) remove_recursive(directory, 1) #define remove_directory_contents(directory) remove_recursive(directory, 0) diff --git a/src/getdents.c b/src/getdents.c deleted file mode 100644 index ad42f7c..0000000 --- a/src/getdents.c +++ /dev/null @@ -1,150 +0,0 @@ -#if defined(__linux__) - #define _GNU_SOURCE - #define _POSIX_C_SOURCE 200809L -#endif - -#include - -#if defined(__HAIKU__) || defined(__linux__) || defined(__APPLE__) - #include -#endif - -#if !defined(__HAIKU__) - #include - #include -#endif - -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \ - defined(__OpenBSD__) || (defined(__linux__) && (defined(__GLIBC__) || defined(__MUSL__))) - #include -#endif - -#if defined(__HAIKU__) - #include -#endif - -#include "getdents.h" - -#if defined(__HAIKU__) - int _kern_open_dir(int, const char*); - ssize_t _kern_read_dir(int, struct dirent*, size_t, size_t); - int _kern_close(int); -#endif - -int open_dir(const char* const directory) { - - #ifdef __HAIKU__ - const int fd = _kern_open_dir(-1, directory); - - if (fd < 0) { - __set_errno(fd); - return -1; - } - #else - const int fd = open(directory, O_RDONLY | O_DIRECTORY); - #endif - - return fd; - -} - -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) - ssize_t get_directory_entries(int fd, char* const buffer, const size_t buffer_size) { - - const ssize_t size = (ssize_t) getdents(fd, buffer, buffer_size); - return size; - - } -#endif - -#if defined(__linux__) - #if defined(__GLIBC__) - ssize_t get_directory_entries(int fd, char* const buffer, const size_t buffer_size) { - - #if defined(_LARGEFILE64_SOURCE) - off64_t base = 0; - const ssize_t size = getdirentries64(fd, buffer, buffer_size, &base); - #else - off_t base = 0; - const ssize_t size = getdirentries(fd, buffer, buffer_size, &base); - #endif - - return size; - - } - #elif defined(__MUSL__) - ssize_t get_directory_entries(int fd, char* const buffer, const size_t buffer_size) { - - const ssize_t size = (ssize_t) getdents(fd, (struct dirent*) buffer, buffer_size); - return size; - - } - #else - ssize_t get_directory_entries(int fd, char* const buffer, const size_t buffer_size) { - - #if defined(SYS_getdents64) - const long size = syscall(SYS_getdents64, fd, buffer, buffer_size); - #else - const long size = syscall(SYS_getdents, fd, buffer, buffer_size); - #endif - - return (ssize_t) size; - - } - #endif -#endif - -#if defined(__APPLE__) - int getdirentries64(int, char*, int, long*) __asm("___getdirentries64"); - - ssize_t get_directory_entries(int fd, char* const buffer, const size_t buffer_size) { - - long base = 0; - const ssize_t size = (ssize_t) getdirentries64(fd, buffer, buffer_size, &base); - - return size; - - } -#endif - -#if defined(__HAIKU__) - ssize_t get_directory_entries(int fd, char* const buffer, const size_t buffer_size) { - - const ssize_t size = _kern_read_dir(fd, (struct dirent*) buffer, buffer_size, sizeof(*buffer)); - - if (size < 0) { - __set_errno(size); - return -1; - } - - return size; - - } -#endif - -int close_dir(int fd) { - - #ifdef __HAIKU__ - const int status = _kern_close(fd); - - if (status < 0) { - __set_errno(status); - return -1; - } - #else - const int status = close(fd); - #endif - - return status; - -} - -size_t directory_entry_size(const directory_entry_t* const entry) { - - #if defined(__DragonFly__) - return _DIRENT_DIRSIZ(entry); - #else - return (entry->d_reclen); - #endif - -} \ No newline at end of file diff --git a/src/getdents.h b/src/getdents.h deleted file mode 100644 index 59e3a34..0000000 --- a/src/getdents.h +++ /dev/null @@ -1,62 +0,0 @@ -#include - -#if defined(__linux__) - #include - - #if !defined(__USE_GNU) && !defined(__BIONIC__) - #define __MUSL__ 1 - #endif -#endif - -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \ - defined(__OpenBSD__) || defined(__HAIKU__) || defined(__APPLE__) || \ - (defined(__linux__) && (defined(__GLIBC__) || defined(__MUSL__))) - #include - - #if defined(__GLIBC__) && defined(_LARGEFILE64_SOURCE) - typedef struct dirent64 directory_entry_t; - #else - typedef struct dirent directory_entry_t; - #endif - - #define HAVE_GETDIRENTRIES 1 -#endif - -#if defined(__linux__) && !(defined(__GLIBC__) || defined(__MUSL__)) - #include - #include - - #if defined(SYS_getdents64) - struct linux_dirent64 { - ino64_t d_ino; - off64_t d_off; - unsigned short d_reclen; - unsigned char d_type; - char d_name[]; - }; - - typedef struct linux_dirent64 directory_entry_t; - #else - struct linux_dirent { - unsigned long d_ino; - off_t d_off; - unsigned short d_reclen; - char d_name[]; - }; - - typedef struct linux_dirent directory_entry_t; - #endif - - #define HAVE_GETDIRENTRIES 1 -#endif - -#if !defined(HAVE_GETDIRENTRIES) - #error "This platform lacks a functioning getdents/getdirentries implementation" -#endif - -int open_dir(const char* const directory); -ssize_t get_directory_entries(int fd, char* const buffer, const size_t buffer_size); -size_t directory_entry_size(const directory_entry_t* const entry); -int close_dir(int fd); - -#pragma once diff --git a/src/m3u8.c b/src/m3u8.c index 397a4a6..7aa4e14 100644 --- a/src/m3u8.c +++ b/src/m3u8.c @@ -3818,14 +3818,15 @@ static enum M3U8BaseURIType m3u8baseuri_guess_type(const char* const something) int status = 0; + const unsigned char a = something[0]; + const unsigned char b = something[1]; + if (strncmp(something, "https://", 8) == 0 || strncmp(something, "http://", 7) == 0) { return M3U8_BASE_URI_TYPE_URL; } status = ( - (something[0] == '.' && (something[1] == '/' || something[1] == '\\')) || - (isalpha(something[0]) && something[1] == ':') || - (something[0] == '/' || something[0] == '\\') + (a == '.' && (b == '/' || b == '\\')) || (isalpha(a) && b == ':') || (a == '/' || a == '\\') ); if (!status) { diff --git a/src/m3u8download.c b/src/m3u8download.c index eea2f4f..2fff6db 100644 --- a/src/m3u8download.c +++ b/src/m3u8download.c @@ -123,7 +123,7 @@ static int m3u8download_addqeue( download.item = item; size = ( - strlen(temporary_directory) + strlen(PATHSEP) + uintlen((biguint_t) uri) + 1 + 3 + 1 + strlen(temporary_directory) + strlen(PATHSEP) + uintlen(ptobiguint(uri)) + 1 + 3 + 1 ); download.destination = malloc(size); @@ -136,7 +136,7 @@ static int m3u8download_addqeue( strcpy(download.destination, temporary_directory); strcat(download.destination, PATHSEP); - wsize = snprintf(download.destination + strlen(download.destination), 4096, "%"FORMAT_BIGGEST_INT_T, (biguint_t) uri); + wsize = snprintf(download.destination + strlen(download.destination), 4096, "%"FORMAT_BIGGEST_INT_T, ptobiguint(uri)); if (wsize < 1) { err = M3U8ERR_PRINTF_WRITE_FAILURE; diff --git a/src/m3u8parser.c b/src/m3u8parser.c index ba39102..63d7eef 100644 --- a/src/m3u8parser.c +++ b/src/m3u8parser.c @@ -189,7 +189,13 @@ int m3u8parser_getdtime(const char* const source, void** destination) { return M3U8ERR_PARSER_INVALID_DTIME; } - while (isdigit(source[index])) { + while (1) { + const unsigned char ch = source[index]; + + if (!isdigit(ch)) { + break; + } + index++; } } diff --git a/src/main.c b/src/main.c index 30a2fb4..13340e6 100644 --- a/src/main.c +++ b/src/main.c @@ -899,7 +899,7 @@ int main(int argc, argv_t* argv[]) { const struct M3U8StreamItem* item = NULL; struct M3U8Stream* const resource = selected_streams.items[index]; - name = malloc(strlen(temporary_directory) + strlen(PATHSEP) + uintlen((biguint_t) resource) + 1 + 4 + 1); + name = malloc(strlen(temporary_directory) + strlen(PATHSEP) + uintlen(ptobiguint(resource)) + 1 + 4 + 1); if (name == NULL) { err = M3U8ERR_MEMORY_ALLOCATE_FAILURE; @@ -909,7 +909,7 @@ int main(int argc, argv_t* argv[]) { strcpy(name, temporary_directory); strcat(name, PATHSEP); - wsize = snprintf(name + strlen(name), 4096, "%"FORMAT_BIGGEST_UINT_T, (biguint_t) resource); + wsize = snprintf(name + strlen(name), 4096, "%"FORMAT_BIGGEST_UINT_T, ptobiguint(resource)); if (wsize < 1) { err = M3U8ERR_PRINTF_WRITE_FAILURE; @@ -960,7 +960,7 @@ int main(int argc, argv_t* argv[]) { name = NULL; } - temporary_file = malloc(strlen(temporary_directory) + strlen(PATHSEP) + uintlen((biguint_t) &stream) + 1 + strlen(file_extension) + 1); + temporary_file = malloc(strlen(temporary_directory) + strlen(PATHSEP) + uintlen(ptobiguint(&stream)) + 1 + strlen(file_extension) + 1); if (temporary_file == NULL) { err = M3U8ERR_MEMORY_ALLOCATE_FAILURE; @@ -970,7 +970,7 @@ int main(int argc, argv_t* argv[]) { strcpy(temporary_file, temporary_directory); strcat(temporary_file, PATHSEP); - wsize = snprintf(temporary_file + strlen(temporary_file), 4096, "%"FORMAT_BIGGEST_UINT_T, (biguint_t) &stream); + wsize = snprintf(temporary_file + strlen(temporary_file), 4096, "%"FORMAT_BIGGEST_UINT_T, ptobiguint(&stream)); if (wsize < 1) { err = M3U8ERR_PRINTF_WRITE_FAILURE; diff --git a/src/readlines.c b/src/readlines.c index 9df1b8e..e793ee4 100644 --- a/src/readlines.c +++ b/src/readlines.c @@ -54,7 +54,9 @@ const struct Line* readlines_next(struct ReadLines* const readlines, struct Line } while (end != start) { - if (!isspace(*end)) { + const unsigned char ch = *end; + + if (!isspace(ch)) { break; } diff --git a/src/walkdir.h b/src/walkdir.h index 53a89c5..cf6ec8a 100644 --- a/src/walkdir.h +++ b/src/walkdir.h @@ -1,3 +1,6 @@ +#if !defined(WALKDIR_H) +#define WALKDIR_H + #include #if defined(_WIN32) @@ -22,14 +25,14 @@ struct WalkDirItem { struct WalkDir { struct WalkDirItem item; -#ifdef _WIN32 +#if defined(_WIN32) HANDLE handle; WIN32_FIND_DATA data; #else DIR* dir; #endif -#ifdef __HAIKU__ - const char* directory; +#if defined(__HAIKU__) + char* directory; #endif }; @@ -37,4 +40,4 @@ int walkdir_init(struct WalkDir* const walkdir, const char* const directory); const struct WalkDirItem* walkdir_next(struct WalkDir* const walkdir); void walkdir_free(struct WalkDir* const walkdir); -#pragma once +#endif