Handle \r and \n the same at getchar().

Signed-off-by: Alon Bar-Lev <[EMAIL PROTECTED]>

---

diff -urNp ecryptfs-utils-23/src/utils/io.c 
ecryptfs-utils-24_beta1/src/utils/io.c
--- ecryptfs-utils-23/src/utils/io.c    2007-08-20 14:54:16.000000000 +0300
+++ ecryptfs-utils-24_beta1/src/utils/io.c      2007-10-03 12:15:11.000000000 
+0200
@@ -50,6 +50,14 @@ static int enable_echo(struct termios *s
        return tcsetattr(0, TCSANOW, saved_settings);
 }
 
+int mygetchar()
+{
+       int c = getchar();
+       if (c == '\r')
+               c = '\n';
+       return c;
+}
+
 int get_string_stdin(char **val, char *prompt, int echo)
 {
 #define DEFAULT_STRING_LENGTH 16
@@ -84,7 +92,7 @@ int get_string_stdin(char **val, char *p
                        free(*val);
                        *val = temp;
                }
-               (*val)[count] = getchar();
+               (*val)[count] = mygetchar();
                count++;
        } while((*val)[count-1] != '\n');
        (*val)[count - 1] = '\0';
@@ -108,7 +116,7 @@ int get_string(char *val, int len, int e
                        goto out;
        }
        do {
-               val[count] = getchar();
+               val[count] = mygetchar();
                count++;
        } while(val[count-1] != '\n' && (count < len));
        if (count > len)
@@ -125,9 +133,9 @@ out:
 
 static inline int munch_newline(void)
 {
-       if (getchar() == '\n')
+       if (mygetchar() == '\n')
                return 0;
-       while (getchar() != '\n');
+       while (mygetchar() != '\n');
        return -1;
 }
 
@@ -144,7 +152,7 @@ int manager_menu(void)
        printf("\t%d. Abort management\n", MME_ABORT);
 try_again:
        printf("\nMake selection: ");
-       str[0] = getchar();
+       str[0] = mygetchar();
        if (munch_newline()) {
                printf("Invalid selection\n");
                goto try_again;
@@ -244,7 +252,7 @@ prompt_user:
                 if (!pch) {
                         int ch;
 
-                        while ((ch = getchar()) != '\n');
+                        while ((ch = mygetchar()) != '\n');
                 }
                 goto prompt_user;
         }
diff -urNp ecryptfs-utils-23/src/utils/io.h 
ecryptfs-utils-24_beta1/src/utils/io.h
--- ecryptfs-utils-23/src/utils/io.h    2007-08-20 14:54:16.000000000 +0300
+++ ecryptfs-utils-24_beta1/src/utils/io.h      2007-10-03 12:13:20.000000000 
+0200
@@ -39,3 +39,5 @@ ecryptfs_select_crypto_module(struct ecr
                              char **selected_cipher, int *keysize_bytes);
 int ecryptfs_select_key_mod(struct ecryptfs_key_mod **key_mod,
                            struct ecryptfs_ctx *ctx);
+
+int mygetchar();
diff -urNp ecryptfs-utils-23/src/utils/mount.ecryptfs.c 
ecryptfs-utils-24_beta1/src/utils/mount.ecryptfs.c
--- ecryptfs-utils-23/src/utils/mount.ecryptfs.c        2007-08-20 
14:54:16.000000000 +0300
+++ ecryptfs-utils-24_beta1/src/utils/mount.ecryptfs.c  2007-10-03 
12:58:12.000000000 +0200
@@ -324,11 +328,11 @@ static int process_sig(char *auth_tok_si
                printf("Would you like to proceed with the mount (yes/no)? ");
                i = 0;
                do {
-                       yesno[i++] = getchar();
+                       yesno[i++] = mygetchar();
                } while (yesno[i-1] != '\n' && i < 3);
                yesno[i] = '\0';
                if (yesno[i-1] != '\n')
-                       while (getchar() != '\n');
+                       while (mygetchar() != '\n');
                if (memcmp(yesno, "yes", 3) == 0) {
                        printf("Would you like to append sig [%s] to\n"
                               "[%s] \n"
@@ -336,11 +340,11 @@ static int process_sig(char *auth_tok_si
                               "(yes/no)? ", auth_tok_sig, sig_cache_filename);
                        i = 0;
                        do {
-                               yesno[i++] = getchar();
+                               yesno[i++] = mygetchar();
                        } while (yesno[i-1] != '\n' && i < 3);
                        yesno[i] = '\0';
                        if (yesno[i-1] != '\n')
-                               while (getchar() != '\n');
+                               while (mygetchar() != '\n');
                        if (memcmp(yesno, "yes", 3) == 0) {
                                if ((rc = ecryptfs_append_sig(
                                             auth_tok_sig,

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
eCryptfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ecryptfs-devel

Reply via email to