--- a/libpurple/protocols/silc/util.c Fri Feb 12 18:38:08 2021 -0600 +++ b/libpurple/protocols/silc/util.c Fri Feb 12 23:47:53 2021 -0600 @@ -17,13 +17,17 @@ */ -#include "internal.h" -#include <purple.h> +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif -PURPLE_BEGIN_IGNORE_CAST_ALIGN -#include "silc.h" -PURPLE_END_IGNORE_CAST_ALIGN -#include "silcclient.h" +#ifdef HAVE_FCNTL_H +# include <fcntl.h> +#endif + +#include <glib/gi18n-lib.h> +#include <glib/gstdio.h> + #include "silcpurple.h" /**************************** Utility Routines *******************************/ @@ -67,6 +71,23 @@ return FALSE; } +/* A fstat alternative, like g_stat for stat. */ +static int +silcpurple_fstat(int fd, GStatBuf *st) +{ + int ret; + + g_return_val_if_fail(st != NULL, -1); + +#ifdef _WIN32 + ret = _fstat(fd, st); +#else + ret = fstat(fd, st); +#endif + + return ret; +} + /* This checks stats for various SILC files and directories. First it checks if ~/.silc directory exist and is owned by the correct user. If it doesn't exist, it will create the directory. After that it checks if @@ -192,7 +213,7 @@ #endif if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { - if (_purple_fstat(fd, &st) == -1) { + if (silcpurple_fstat(fd, &st) == -1) { purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", file_private_key, g_strerror(errno)); close(fd); @@ -214,7 +235,7 @@ } if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) { - if (_purple_fstat(fd, &st) == -1) { + if (silcpurple_fstat(fd, &st) == -1) { purple_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", file_private_key, g_strerror(errno)); close(fd); @@ -246,7 +267,7 @@ if ((st.st_mode & 0777) != 0600) { purple_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" "Trying to change them ...\n", file_private_key); - if ((fd == -1) || (g_fchmod(fd, S_IRUSR | S_IWUSR)) == -1) { + if ((fd == -1) || (fchmod(fd, S_IRUSR | S_IWUSR) == -1)) { purple_debug_error("silc", "Failed to change permissions for private key file!\n" "Permissions for your private key file must be 0600.\n");