[gtk-vnc] Replace getline with fgets for win32 portability



commit 1dd60db13b298c83aa1339b9a141ac232c693b09
Author: Daniel P. Berrange <dan berrange com>
Date:   Sun Jul 11 18:32:11 2010 +0100

    Replace getline with fgets for win32 portability
    
    The getline function is gnu specific. Replace with use of fgets
    for portability to win32

 tools/gvnccapture.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/tools/gvnccapture.c b/tools/gvnccapture.c
index 5617b6b..787089d 100644
--- a/tools/gvnccapture.c
+++ b/tools/gvnccapture.c
@@ -141,8 +141,9 @@ do_vnc_get_credential(const gchar *prompt, gboolean doecho)
 #ifdef HAVE_TERMIOS_H
 	struct termios old, new;
 #endif
-	gchar *res = NULL;
-	size_t n;
+	gchar buf[100];
+	gchar *res;
+	int n = sizeof(buf);
 	ssize_t len;
 
 	printf("%s", prompt);
@@ -161,11 +162,11 @@ do_vnc_get_credential(const gchar *prompt, gboolean doecho)
 #endif
 
 	/* Read the password. */
-	if ((len = getline(&res, &n, stdin)) < 0)
-		res = NULL;
-
-	if (res && res[len-1] == '\n')
-		res[len-1] = '\0';
+	if ((res = fgets(buf, n, stdin)) != NULL) {
+		len = strlen(res);
+		if (res[len-1] == '\n')
+			res[len-1] = '\0';
+	}
 
 #ifdef HAVE_TERMIOS_H
 	/* Restore terminal. */
@@ -175,7 +176,7 @@ do_vnc_get_credential(const gchar *prompt, gboolean doecho)
 	}
 #endif
 
-	return res;
+	return res ? g_strdup(res) : NULL;
 }
 
 



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