Use strcspn to remove \n from fgets result. Prompted by change by Ray

Lai of OpenBSD via Björn Sandell.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19213 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2006-12-04 23:36:36 +00:00
parent 63579afa99
commit 487bcca4e2
4 changed files with 6 additions and 12 deletions

View File

@@ -57,8 +57,7 @@ read_words (const char *filename, char ***ret_w)
while (fgets (buf, sizeof(buf), f) != NULL) {
size_t len;
if (buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
buf[strcspn(buf, "\r\n")] = '\0';
if (n >= alloc) {
alloc = max(alloc + 16, alloc * 2);
w = erealloc (w, alloc * sizeof(char **));

View File

@@ -161,16 +161,14 @@ main(int argc, char **argv)
printf("Kerberos v5 principal: ");
if(fgets(buf, sizeof(buf), stdin) == NULL)
return 1;
if(buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
buf[strcspn(buf, "\r\n")] = '\0';
principal = estrdup(buf);
}
if(afs && cell == NULL){
printf("AFS cell: ");
if(fgets(buf, sizeof(buf), stdin) == NULL)
return 1;
if(buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
buf[strcspn(buf, "\r\n")] = '\0';
cell = estrdup(buf);
}
if(argv[0])

View File

@@ -158,8 +158,7 @@ parse_list(struct fileptr *f, unsigned *lineno, krb5_config_binding **parent,
char *p;
++*lineno;
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
buf[strcspn(buf, "\r\n")] = '\0';
p = buf;
while(isspace((unsigned char)*p))
++p;
@@ -255,8 +254,7 @@ krb5_config_parse_debug (struct fileptr *f,
char *p;
++*lineno;
if(buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
buf[strcspn(buf, "\r\n")] = '\0';
p = buf;
while(isspace((unsigned char)*p))
++p;

View File

@@ -191,8 +191,7 @@ readline(char *prompt)
fflush (stdout);
if(fgets(buf, sizeof(buf), stdin) == NULL)
return NULL;
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
buf[strcspn(buf, "\r\n")] = '\0';
return strdup(buf);
}