]> diplodocus.org Git - nmh/blobdiff - uip/mhlogin.c
Alter HasSuffixC()'s char * to be const.
[nmh] / uip / mhlogin.c
index aabe9a3d87cd7c87c8de5f304a631a6015208ae1..ffa44f3f0a3bee6ea0d499a34631c85e4d206513 100644 (file)
@@ -11,6 +11,7 @@
 #include <string.h>
 
 #include <h/mh.h>
 #include <string.h>
 
 #include <h/mh.h>
+#include <h/utils.h>
 #include <h/oauth.h>
 
 #define MHLOGIN_SWITCHES \
 #include <h/oauth.h>
 
 #define MHLOGIN_SWITCHES \
@@ -35,13 +36,12 @@ DEFINE_SWITCH_ARRAY(MHLOGIN, switches);
 static char *
 geta (void)
 {
 static char *
 geta (void)
 {
-    char *cp;
     static char line[BUFSIZ];
 
     if (fgets(line, sizeof(line), stdin) == NULL)
        done (1);
     static char line[BUFSIZ];
 
     if (fgets(line, sizeof(line), stdin) == NULL)
        done (1);
-    if ((cp = strchr(line, '\n')))
-       *cp = 0;
+    TrimSuffixC(line, '\n');
+
     return line;
 }
 
     return line;
 }
 
@@ -71,7 +71,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
         mh_oauth_log_to(stderr, ctx);
     }
 
         mh_oauth_log_to(stderr, ctx);
     }
 
-    fn = getcpy(mh_oauth_cred_fn(svc));
+    fn = mh_xstrdup(mh_oauth_cred_fn(svc));
 
     if ((url = mh_oauth_get_authorize_url(ctx)) == NULL) {
       adios(NULL, mh_oauth_get_err_string(ctx));
 
     if ((url = mh_oauth_get_authorize_url(ctx)) == NULL) {
       adios(NULL, mh_oauth_get_err_string(ctx));
@@ -101,10 +101,10 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
     fflush(stdout);
     code = geta();
 
     fflush(stdout);
     code = geta();
 
-    while (strlen(code) == 0 ||
+    while (!*code ||
            ((cred = mh_oauth_authorize(code, ctx)) == NULL
             && mh_oauth_get_err_code(ctx) == MH_OAUTH_BAD_GRANT)) {
            ((cred = mh_oauth_authorize(code, ctx)) == NULL
             && mh_oauth_get_err_code(ctx) == MH_OAUTH_BAD_GRANT)) {
-      printf(strlen(code) == 0  ?  "Empty code; try again? "  :  "Code rejected; try again? ");
+      printf(!*code  ?  "Empty code; try again? "  :  "Code rejected; try again? ");
       fflush(stdout);
       code = geta();
     }
       fflush(stdout);
       code = geta();
     }