[gtk-vnc-devel] [patch] boolean functions must return FALSE on failure



Hi. This patch changes behavior of boolean functions in gvnc.c (which
uses gvnc_has_error() ) to return FALSE (instead of TRUE) in case of
failure. 

I think it's better to read (and understand):
if (!gvnc_initialize())
  handle_error();

than:
if (gvnc_initialize())
  handle_error();

What do you think?

Bye,
-- 
Jonh Wendell
jonh wendell gmail com (MSN / Google Talk)

Linux User #114432
https://launchpad.net/~wendell
# HG changeset patch
# User Jonh Wendell <wendell bani com br>
# Date 1185987032 10800
# Node ID 2f8878799f3cd76899cce755be6435f6902d4d54
# Parent  4c3599147f531b143ff4e92b3f85d975cc6275fc
Changed boolean functions (which use gvnc_has_error) to return FALSE when failure

diff -r 4c3599147f53 -r 2f8878799f3c src/gvnc.c
--- a/src/gvnc.c	Mon Jul 30 20:12:10 2007 -0400
+++ b/src/gvnc.c	Wed Aug 01 13:50:32 2007 -0300
@@ -711,7 +711,7 @@ gboolean gvnc_set_pixel_format(struct gv
 	gvnc_flush(gvnc);
 	memcpy(&gvnc->fmt, fmt, sizeof(*fmt));
 
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 gboolean gvnc_set_shared_buffer(struct gvnc *gvnc, int line_size, int shmid)
@@ -722,7 +722,7 @@ gboolean gvnc_set_shared_buffer(struct g
 	gvnc_write_u32(gvnc, shmid);
 	gvnc_flush(gvnc);
 
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 gboolean gvnc_set_encodings(struct gvnc *gvnc, int n_encoding, int32_t *encoding)
@@ -736,7 +736,7 @@ gboolean gvnc_set_encodings(struct gvnc 
 	for (i = 0; i < n_encoding; i++)
 		gvnc_write_s32(gvnc, encoding[i]);
 	gvnc_flush(gvnc);
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 gboolean gvnc_framebuffer_update_request(struct gvnc *gvnc,
@@ -751,7 +751,7 @@ gboolean gvnc_framebuffer_update_request
 	gvnc_write_u16(gvnc, width);
 	gvnc_write_u16(gvnc, height);
 	gvnc_flush(gvnc);
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 static void gvnc_buffered_write(struct gvnc *gvnc, const void *data, size_t size)
@@ -803,7 +803,7 @@ gboolean gvnc_key_event(struct gvnc *gvn
 	gvnc_buffered_write(gvnc, pad, 2);
 	gvnc_buffered_write_u32(gvnc, key);
 	gvnc_buffered_flush(gvnc);
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 gboolean gvnc_pointer_event(struct gvnc *gvnc, uint8_t button_mask,
@@ -814,7 +814,7 @@ gboolean gvnc_pointer_event(struct gvnc 
 	gvnc_buffered_write_u16(gvnc, x);
 	gvnc_buffered_write_u16(gvnc, y);
 	gvnc_buffered_flush(gvnc);
-	return gvnc_has_error(gvnc);	
+	return !gvnc_has_error(gvnc);	
 }
 
 gboolean gvnc_client_cut_text(struct gvnc *gvnc,
@@ -827,7 +827,7 @@ gboolean gvnc_client_cut_text(struct gvn
 	gvnc_write_u32(gvnc, length);
 	gvnc_write(gvnc, data, length);
 	gvnc_flush(gvnc);
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 static inline uint8_t *gvnc_get_local(struct gvnc *gvnc, int x, int y)
@@ -1168,7 +1168,7 @@ gboolean gvnc_server_message(struct gvnc
 		break;
 	}
 
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 static gboolean gvnc_check_auth_result(struct gvnc *gvnc)
@@ -1383,7 +1383,7 @@ static gboolean gvnc_gather_credentials(
 		g_condition_wait(gvnc_has_credentials, gvnc);
 		GVNC_DEBUG("Got all credentials\n");
 	}
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 static gboolean gvnc_has_auth_subtype(gpointer data)
@@ -1451,7 +1451,7 @@ static gboolean gvnc_perform_auth_vencry
 
 	GVNC_DEBUG("Choose auth %d\n", gvnc->auth_subtype);
 
-	if (gvnc_gather_credentials(gvnc))
+	if (!gvnc_gather_credentials(gvnc))
 		return FALSE;
 
 #if !DEBUG
@@ -1556,7 +1556,7 @@ static gboolean gvnc_perform_auth(struct
 		return FALSE;
 
 	GVNC_DEBUG("Choose auth %d\n", gvnc->auth_type);
-	if (gvnc_gather_credentials(gvnc))
+	if (!gvnc_gather_credentials(gvnc))
 		return FALSE;
 
 	if (gvnc->minor > 6) {
@@ -1721,31 +1721,31 @@ gboolean gvnc_initialize(struct gvnc *gv
 	GVNC_DEBUG("Display name '%s'\n", gvnc->name);
 
 	gvnc_resize(gvnc, gvnc->width, gvnc->height);
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 
  fail:
 	gvnc->has_error = 1;
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 gboolean gvnc_open_fd(struct gvnc *gvnc, int fd)
 {
 	int flags;
 	if (gvnc_is_open(gvnc))
-		return TRUE;
+		return FALSE;
 
 	GVNC_DEBUG("Connecting to FD %d\n", fd);
 	if ((flags = fcntl(fd, F_GETFL)) < 0)
-		return TRUE;
+		return FALSE;
 	flags |= O_NONBLOCK;
 	if (fcntl(fd, F_SETFL, flags) < 0)
-		return TRUE;
+		return FALSE;
 
 	if (!(gvnc->channel = g_io_channel_unix_new(fd)))
-		return TRUE;
+		return FALSE;
 	gvnc->fd = fd;
 
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 gboolean gvnc_open_host(struct gvnc *gvnc, const char *host, const char *port)
@@ -1753,7 +1753,7 @@ gboolean gvnc_open_host(struct gvnc *gvn
         struct addrinfo *ai, *runp, hints;
         int ret;
 	if (gvnc_is_open(gvnc))
-		return TRUE;
+		return FALSE;
 
 	gvnc->host = g_strdup(host);
 	gvnc->port = g_strdup(port);
@@ -1765,7 +1765,7 @@ gboolean gvnc_open_host(struct gvnc *gvn
         hints.ai_protocol = IPPROTO_TCP;
 
         if ((ret = getaddrinfo(host, port, &hints, &ai)) != 0)
-		return TRUE;
+		return FALSE;
 
         runp = ai;
         while (runp != NULL) {
@@ -1797,7 +1797,7 @@ gboolean gvnc_open_host(struct gvnc *gvn
                         gvnc->channel = chan;
                         gvnc->fd = fd;
                         freeaddrinfo(ai);
-                        return gvnc_has_error(gvnc);
+                        return !gvnc_has_error(gvnc);
                 }
 
                 if (errno == EINPROGRESS) {
@@ -1814,7 +1814,7 @@ gboolean gvnc_open_host(struct gvnc *gvn
                 runp = runp->ai_next;
         }
         freeaddrinfo (ai);
-	return TRUE;
+	return FALSE;
 }
 
 
@@ -1823,18 +1823,18 @@ gboolean gvnc_set_auth_type(struct gvnc 
         GVNC_DEBUG("Requested auth type %d\n", type);
         if (gvnc->auth_type != GVNC_AUTH_INVALID) {
                 gvnc->has_error = TRUE;
-                return gvnc_has_error(gvnc);
+                return !gvnc_has_error(gvnc);
         }
         if (type != GVNC_AUTH_NONE &&
             type != GVNC_AUTH_VNC &&
             type != GVNC_AUTH_VENCRYPT) {
                 gvnc->has_error = TRUE;
-                return gvnc_has_error(gvnc);
+                return !gvnc_has_error(gvnc);
         }
         gvnc->auth_type = type;
         gvnc->auth_subtype = GVNC_AUTH_INVALID;
 
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 gboolean gvnc_set_auth_subtype(struct gvnc *gvnc, unsigned int type)
@@ -1842,15 +1842,15 @@ gboolean gvnc_set_auth_subtype(struct gv
         GVNC_DEBUG("Requested auth subtype %d\n", type);
         if (gvnc->auth_type != GVNC_AUTH_VENCRYPT) {
                 gvnc->has_error = TRUE;
-		return gvnc_has_error(gvnc);
+		return !gvnc_has_error(gvnc);
         }
         if (gvnc->auth_subtype != GVNC_AUTH_INVALID) {
                 gvnc->has_error = TRUE;
-		return gvnc_has_error(gvnc);
+		return !gvnc_has_error(gvnc);
         }
         gvnc->auth_subtype = type;
 
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 gboolean gvnc_set_credential_password(struct gvnc *gvnc, const char *password)
@@ -1928,7 +1928,7 @@ gboolean gvnc_set_local(struct gvnc *gvn
 	if (gvnc->perfect_match)
 		gvnc->blt = gvnc_blt_fast;
 
-	return gvnc_has_error(gvnc);
+	return !gvnc_has_error(gvnc);
 }
 
 gboolean gvnc_shared_memory_enabled(struct gvnc *gvnc)
diff -r 4c3599147f53 -r 2f8878799f3c src/vncdisplay.c
--- a/src/vncdisplay.c	Mon Jul 30 20:12:10 2007 -0400
+++ b/src/vncdisplay.c	Wed Aug 01 13:50:32 2007 -0300
@@ -570,10 +570,10 @@ static void *vnc_coroutine(void *opaque)
 		return NULL;
 
 	if (priv->fd != -1) {
-		if (gvnc_open_fd(priv->gvnc, priv->fd))
+		if (!gvnc_open_fd(priv->gvnc, priv->fd))
 			goto cleanup;
 	} else {
-		if (gvnc_open_host(priv->gvnc, priv->host, priv->port))
+		if (!gvnc_open_host(priv->gvnc, priv->host, priv->port))
 			goto cleanup;
 	}
 
@@ -581,21 +581,21 @@ static void *vnc_coroutine(void *opaque)
 		       signals[VNC_CONNECTED],
 		       0);
 
-	if (gvnc_initialize(priv->gvnc, FALSE))
+	if (!gvnc_initialize(priv->gvnc, FALSE))
 		goto cleanup;
 
 	g_signal_emit (G_OBJECT (obj),
 		       signals[VNC_INITIALIZED],
 		       0);
 
-	if (gvnc_set_encodings(priv->gvnc, 6, encodings))
+	if (!gvnc_set_encodings(priv->gvnc, 6, encodings))
 		goto cleanup;
 
-	if (gvnc_framebuffer_update_request(priv->gvnc, 0, 0, 0, priv->fb.width, priv->fb.height))
+	if (!gvnc_framebuffer_update_request(priv->gvnc, 0, 0, 0, priv->fb.width, priv->fb.height))
 		goto cleanup;
 
-	while (!(ret = gvnc_server_message(priv->gvnc))) {
-		if (gvnc_framebuffer_update_request(priv->gvnc, 1, 0, 0,
+	while ((ret = gvnc_server_message(priv->gvnc))) {
+		if (!gvnc_framebuffer_update_request(priv->gvnc, 1, 0, 0,
 						     priv->fb.width, priv->fb.height))
 			goto cleanup;
 	}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]