/pidgin/main: 4bba5ea5d08a: Provide a portable alternative for f...

Tomasz Wasilczyk <[email protected]>
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: 4bba5ea5d08ac12863431ac5c8f9e411ce77b112
Author:	 Tomasz Wasilczyk <[email protected]>
Date:	 2014-05-13 13:13 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/4bba5ea5d08a

Description:

Provide a portable alternative for fstat

diffstat:

 libpurple/internal.h            |  11 +++++++++++
 libpurple/log.c                 |   4 ++--
 libpurple/protocols/silc/util.c |  24 ++----------------------
 libpurple/util.c                |  20 ++++++++++++++++++--
 4 files changed, 33 insertions(+), 26 deletions(-)

diffs (132 lines):

diff --git a/libpurple/internal.h b/libpurple/internal.h
--- a/libpurple/internal.h
+++ b/libpurple/internal.h
@@ -354,4 +354,15 @@ const gchar *
 gboolean
 _purple_network_set_common_socket_flags(int fd);
 
+/**
+ * A fstat alternative, like g_stat for stat.
+ *
+ * @param fd The file descriptor.
+ * @param st The stat buffer.
+ *
+ * @return the result just like for fstat.
+ */
+int
+_purple_fstat(int fd, GStatBuf *st);
+
 #endif /* _PURPLE_INTERNAL_H_ */
diff --git a/libpurple/log.c b/libpurple/log.c
--- a/libpurple/log.c
+++ b/libpurple/log.c
@@ -1732,7 +1732,7 @@ static GList *old_logger_list(PurpleLogT
 		g_free(pathstr);
 		return NULL;
 	}
-	if (fstat(file_fd, &st) == -1) {
+	if (_purple_fstat(file_fd, &st) == -1) {
 		purple_stringref_unref(pathref);
 		g_free(pathstr);
 		fclose(file);
@@ -1745,7 +1745,7 @@ static GList *old_logger_list(PurpleLogT
 
 	index_fd = g_open(pathstr, 0, O_RDONLY);
 	if (index_fd != -1) {
-		if (fstat(index_fd, &st) != 0) {
+		if (_purple_fstat(index_fd, &st) != 0) {
 			close(index_fd);
 			index_fd = -1;
 		}
diff --git a/libpurple/protocols/silc/util.c b/libpurple/protocols/silc/util.c
--- a/libpurple/protocols/silc/util.c
+++ b/libpurple/protocols/silc/util.c
@@ -68,26 +68,6 @@ gboolean silcpurple_ip_is_private(const 
 	return FALSE;
 }
 
-/* there is no fstat alternative for GStatBuf */
-static int g_fstat(int fd, GStatBuf *st)
-{
-	struct stat sst;
-	int ret;
-
-	g_return_val_if_fail(st != NULL, -1);
-
-	ret = fstat(fd, &sst);
-	if (ret != 0)
-		return ret;
-
-	memset(st, 0, sizeof(GStatBuf));
-	/* only these two are used here */
-	st->st_uid = sst.st_uid;
-	st->st_mode = sst.st_mode;
-
-	return 0;
-}
-
 /* 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
@@ -213,7 +193,7 @@ gboolean silcpurple_check_silc_dir(Purpl
 #endif
 
 	if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) {
-		if ((g_fstat(fd, &st)) == -1) {
+		if (_purple_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);
@@ -235,7 +215,7 @@ gboolean silcpurple_check_silc_dir(Purpl
 			}
 
 			if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) {
-				if ((g_fstat(fd, &st)) == -1) {
+				if (_purple_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);
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -4961,6 +4961,22 @@ gchar *purple_http_digest_calculate_resp
 	return g_strdup(hash2);
 }
 
+int
+_purple_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;
+}
+
 #if 0
 
 /* Temporarily removed - re-add this when you need ini file support. */
@@ -4975,7 +4991,7 @@ purple_key_file_load_from_ini(GKeyFile *
 	const gchar *header = "[default]\n\n";
 	int header_len = strlen(header);
 	int fd;
-	struct stat st;
+	GStatBuf st;
 	gsize file_size, buff_size;
 	gchar *buff;
 	GError *error = NULL;
@@ -4993,7 +5009,7 @@ purple_key_file_load_from_ini(GKeyFile *
 		return FALSE;
 	}
 
-	if (fstat(fd, &st) != 0) {
+	if (_purple_fstat(fd, &st) != 0) {
 		purple_debug_error("util", "Failed to fstat ini file %s", file);
 		return FALSE;
 	}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.