/pidgin/main: b44d15793c83: Use GStatBuf instead of struct stat

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sat May 18 10:02:34 EDT 2013


Changeset: b44d15793c838336f8b80b773f0f8be292a9df61
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-05-18 16:02 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/b44d15793c83

Description:

Use GStatBuf instead of struct stat

diffstat:

 finch/finch.c                    |   2 +-
 finch/libgnt/gntfilesel.c        |  10 ++++++----
 libpurple/ft.c                   |   4 ++--
 libpurple/internal.h             |   1 -
 libpurple/log.c                  |   8 ++++----
 libpurple/plugins/filectl.c      |   6 +++---
 libpurple/plugins/log_reader.c   |   6 +++---
 libpurple/plugins/tcl/tcl.c      |   1 -
 libpurple/prefs.c                |   1 -
 libpurple/protocols/silc/buddy.c |   2 +-
 libpurple/protocols/silc/pk.c    |   2 +-
 libpurple/protocols/silc/util.c  |  26 +++++++++++++++++++++++---
 libpurple/util.c                 |   2 +-
 pidgin/gtkmain.c                 |   2 +-
 pidgin/gtkutils.c                |   4 ++--
 pidgin/plugins/mailchk.c         |   8 ++++----
 pidgin/plugins/spellchk.c        |   1 -
 17 files changed, 52 insertions(+), 34 deletions(-)

diffs (truncated from 359 to 300 lines):

diff --git a/finch/finch.c b/finch/finch.c
--- a/finch/finch.c
+++ b/finch/finch.c
@@ -265,7 +265,7 @@ init_libpurple(int argc, char **argv)
 	gboolean opt_version = FALSE;
 	char *opt_config_dir_arg = NULL;
 	gboolean debug_enabled = FALSE;
-	struct stat st;
+	GStatBuf st;
 
 	struct option long_options[] = {
 		{"config",   required_argument, NULL, 'c'},
diff --git a/finch/libgnt/gntfilesel.c b/finch/libgnt/gntfilesel.c
--- a/finch/libgnt/gntfilesel.c
+++ b/finch/libgnt/gntfilesel.c
@@ -37,6 +37,8 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include <glib/gstdio.h>
+
 #if 0
 #include <glob.h>
 #endif
@@ -159,9 +161,9 @@ local_read_fn(const char *path, GList **
 
 	while ((str = g_dir_read_name(dir)) != NULL) {
 		char *fp = g_build_filename(path, str, NULL);
-		struct stat st;
+		GStatBuf st;
 
-		if (stat(fp, &st)) {
+		if (g_stat(fp, &st)) {
 			gnt_warning("Error stating location %s", fp);
 		} else {
 			if (S_ISDIR(st.st_mode)) {
@@ -281,7 +283,7 @@ location_key_pressed(GntTree *tree, cons
 #if 0
 	int count;
 	glob_t gl;
-	struct stat st;
+	GStatBuf st;
 	int glob_ret;
 #endif
 	if (strcmp(key, "\r") && strcmp(key, "\n"))
@@ -313,7 +315,7 @@ location_key_pressed(GntTree *tree, cons
 	if (!glob_ret) {  /* XXX: do something with the return value */
 		char *loc = g_path_get_dirname(gl.gl_pathv[0]);
 
-		stat(gl.gl_pathv[0], &st);
+		g_stat(gl.gl_pathv[0], &st);
 		gnt_file_sel_set_current_location(sel, loc);  /* XXX: check the return value */
 		g_free(loc);
 		if (!S_ISDIR(st.st_mode) && !sel->dirsonly) {
diff --git a/libpurple/ft.c b/libpurple/ft.c
--- a/libpurple/ft.c
+++ b/libpurple/ft.c
@@ -368,7 +368,7 @@ purple_xfer_choose_file_ok_cb(void *user
 {
 	PurpleXfer *xfer;
 	PurpleXferType type;
-	struct stat st;
+	GStatBuf st;
 	gchar *dir;
 
 	xfer = (PurpleXfer *)user_data;
@@ -624,7 +624,7 @@ void
 purple_xfer_request_accepted(PurpleXfer *xfer, const char *filename)
 {
 	PurpleXferType type;
-	struct stat st;
+	GStatBuf st;
 	char *msg, *utf8, *base;
 	PurpleAccount *account;
 	PurpleBuddy *buddy;
diff --git a/libpurple/internal.h b/libpurple/internal.h
--- a/libpurple/internal.h
+++ b/libpurple/internal.h
@@ -75,7 +75,6 @@
 #define BUF_LEN MSG_LEN
 #define BUF_LONG BUF_LEN * 2
 
-#include <sys/stat.h>
 #include <sys/types.h>
 #ifndef _WIN32
 #include <sys/time.h>
diff --git a/libpurple/log.c b/libpurple/log.c
--- a/libpurple/log.c
+++ b/libpurple/log.c
@@ -1017,7 +1017,7 @@ int purple_log_common_total_sizer(Purple
 		    strlen(filename) >= (17 + strlen(ext)))
 		{
 			char *tmp = g_build_filename(path, filename, NULL);
-			struct stat st;
+			GStatBuf st;
 			if (g_stat(tmp, &st))
 			{
 				purple_debug_error("log", "Error stating log file: %s\n", tmp);
@@ -1035,7 +1035,7 @@ int purple_log_common_total_sizer(Purple
 
 int purple_log_common_sizer(PurpleLog *log)
 {
-	struct stat st;
+	GStatBuf st;
 	PurpleLogCommonLoggerData *data = log->logger_data;
 
 	g_return_val_if_fail(data != NULL, 0);
@@ -1675,7 +1675,7 @@ static GList *old_logger_list(PurpleLogT
 	char *logfile = g_strdup_printf("%s.log", purple_normalize(account, sn));
 	char *pathstr = g_build_filename(purple_user_dir(), "logs", logfile, NULL);
 	PurpleStringref *pathref = purple_stringref_new(pathstr);
-	struct stat st;
+	GStatBuf st;
 	time_t log_last_modified;
 	FILE *index;
 	FILE *file;
@@ -1926,7 +1926,7 @@ static int old_logger_total_size(PurpleL
 	char *logfile = g_strdup_printf("%s.log", purple_normalize(account, name));
 	char *pathstr = g_build_filename(purple_user_dir(), "logs", logfile, NULL);
 	int size;
-	struct stat st;
+	GStatBuf st;
 
 	if (g_stat(pathstr, &st))
 		size = 0;
diff --git a/libpurple/plugins/filectl.c b/libpurple/plugins/filectl.c
--- a/libpurple/plugins/filectl.c
+++ b/libpurple/plugins/filectl.c
@@ -39,7 +39,7 @@ char *getarg(char *, int, int);
 void
 run_commands()
 {
-	struct stat finfo;
+	GStatBuf finfo;
 	char filename[MAXPATHLEN];
 	char buffer[1024];
 	char *command, *arg1, *arg2;
@@ -143,7 +143,7 @@ void
 init_file()
 {
 	/* most of this was taken from Bash v2.04 by the FSF */
-	struct stat finfo;
+	GStatBuf finfo;
 	char filename[MAXPATHLEN];
 
 	snprintf(filename, MAXPATHLEN, "%s" G_DIR_SEPARATOR_S "control", purple_user_dir());
@@ -159,7 +159,7 @@ gboolean
 check_file()
 {
 	/* most of this was taken from Bash v2.04 by the FSF */
-	struct stat finfo;
+	GStatBuf finfo;
 	char filename[MAXPATHLEN];
 
 	snprintf(filename, MAXPATHLEN, "%s" G_DIR_SEPARATOR_S "control", purple_user_dir());
diff --git a/libpurple/plugins/log_reader.c b/libpurple/plugins/log_reader.c
--- a/libpurple/plugins/log_reader.c
+++ b/libpurple/plugins/log_reader.c
@@ -297,9 +297,9 @@ static int adium_logger_size (PurpleLog 
 	data = log->logger_data;
 
 	if (purple_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) {
-		struct stat st;
-
-		if (!data->path || stat(data->path, &st))
+		GStatBuf st;
+
+		if (!data->path || g_stat(data->path, &st))
 			st.st_size = 0;
 
 		return st.st_size;
diff --git a/libpurple/plugins/tcl/tcl.c b/libpurple/plugins/tcl/tcl.c
--- a/libpurple/plugins/tcl/tcl.c
+++ b/libpurple/plugins/tcl/tcl.c
@@ -30,7 +30,6 @@
 
 #include <stdio.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <string.h>
 
diff --git a/libpurple/prefs.c b/libpurple/prefs.c
--- a/libpurple/prefs.c
+++ b/libpurple/prefs.c
@@ -28,7 +28,6 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/stat.h>
 #include <sys/types.h>
 #include <glib.h>
 #include "internal.h"
diff --git a/libpurple/protocols/silc/buddy.c b/libpurple/protocols/silc/buddy.c
--- a/libpurple/protocols/silc/buddy.c
+++ b/libpurple/protocols/silc/buddy.c
@@ -922,7 +922,7 @@ silcpurple_add_buddy_save(SilcBool succe
 
 	if (usign_success || ssign_success) {
 		struct passwd *pw;
-		struct stat st;
+		GStatBuf st;
 
 		memset(filename2, 0, sizeof(filename2));
 
diff --git a/libpurple/protocols/silc/pk.c b/libpurple/protocols/silc/pk.c
--- a/libpurple/protocols/silc/pk.c
+++ b/libpurple/protocols/silc/pk.c
@@ -126,7 +126,7 @@ void silcpurple_verify_public_key(SilcCl
 	char file[256], filename[256], filename2[256], *ipf, *hostf = NULL;
 	char *fingerprint, *babbleprint;
 	struct passwd *pw;
-	struct stat st;
+	GStatBuf st;
 	char *entity = ((conn_type == SILC_CONN_SERVER ||
 			 conn_type == SILC_CONN_ROUTER) ?
 			"server" : "client");
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
@@ -64,6 +64,26 @@ 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
@@ -74,7 +94,7 @@ gboolean silcpurple_check_silc_dir(Purpl
 	char filename[256], file_public_key[256], file_private_key[256];
 	char servfilename[256], clientfilename[256], friendsfilename[256];
 	char pkd[256], prd[256];
-	struct stat st;
+	GStatBuf st;
 	struct passwd *pw;
 	int fd;
 
@@ -238,7 +258,7 @@ gboolean silcpurple_check_silc_dir(Purpl
 #endif
 
 	if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) {
-		if ((fstat(fd, &st)) == -1) {
+		if ((g_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);
@@ -260,7 +280,7 @@ gboolean silcpurple_check_silc_dir(Purpl
 			}
 
 			if ((fd = g_open(file_private_key, O_RDONLY, 0)) != -1) {
-				if ((fstat(fd, &st)) == -1) {
+				if ((g_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
@@ -2967,7 +2967,7 @@ purple_util_write_data_to_file_absolute(
 	gchar *filename_temp;
 	FILE *file;
 	size_t real_size, byteswritten;
-	struct stat st;
+	GStatBuf st;
 #ifndef HAVE_FILENO
 	int fd;
 #endif
diff --git a/pidgin/gtkmain.c b/pidgin/gtkmain.c
--- a/pidgin/gtkmain.c
+++ b/pidgin/gtkmain.c
@@ -452,7 +452,7 @@ int main(int argc, char *argv[])
 	gboolean gui_check;
 	gboolean debug_enabled;
 	GList *active_accounts;
-	struct stat st;
+	GStatBuf st;
 
 	struct option long_options[] = {
 		{"config",       required_argument, NULL, 'c'},
diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c
--- a/pidgin/gtkutils.c



More information about the Commits mailing list