* libmisc/loginprompt.c: Avoid implicit conversion of pointers / chars to booleans.

* libmisc/loginprompt.c: Add brackets.
	* libmisc/loginprompt.c: Avoid assignments in comparisons.
	* libmisc/loginprompt.c: The return values of fclose and fflush are not checked on purpose.
This commit is contained in:
nekral-guest 2008-05-25 23:57:41 +00:00
parent f7122499a6
commit 3169455653
2 changed files with 32 additions and 13 deletions

View File

@ -1,3 +1,12 @@
2008-05-26 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/loginprompt.c: Avoid implicit conversion of pointers /
chars to booleans.
* libmisc/loginprompt.c: Add brackets.
* libmisc/loginprompt.c: Avoid assignments in comparisons.
* libmisc/loginprompt.c: The return values of fclose and fflush
are not checked on purpose.
2008-05-26 Nicolas François <nicolas.francois@centraliens.net> 2008-05-26 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/setupenv.c: Avoid implicit conversion of chars to * libmisc/setupenv.c: Avoid implicit conversion of chars to

View File

@ -88,15 +88,19 @@ void login_prompt (const char *prompt, char *name, int namesize)
if (prompt) { if (prompt) {
cp = getdef_str ("ISSUE_FILE"); cp = getdef_str ("ISSUE_FILE");
if (cp && (fp = fopen (cp, "r"))) { if (NULL != cp) {
while ((i = getc (fp)) != EOF) fp = fopen (cp, "r");
putc (i, stdout); if (NULL != fp) {
while ((i = getc (fp)) != EOF) {
putc (i, stdout);
}
fclose (fp); (void) fclose (fp);
}
} }
gethostname (buf, sizeof buf); gethostname (buf, sizeof buf);
printf (prompt, buf); printf (prompt, buf);
fflush (stdout); (void) fflush (stdout);
} }
/* /*
@ -105,12 +109,14 @@ void login_prompt (const char *prompt, char *name, int namesize)
*/ */
memzero (buf, sizeof buf); memzero (buf, sizeof buf);
if (fgets (buf, sizeof buf, stdin) != buf) if (fgets (buf, sizeof buf, stdin) != buf) {
exit (1); exit (1);
}
cp = strchr (buf, '\n'); cp = strchr (buf, '\n');
if (!cp) if (NULL == cp) {
exit (1); exit (1);
}
*cp = '\0'; /* remove \n [ must be there ] */ *cp = '\0'; /* remove \n [ must be there ] */
/* /*
@ -122,11 +128,13 @@ void login_prompt (const char *prompt, char *name, int namesize)
for (cp = buf; *cp == ' ' || *cp == '\t'; cp++); for (cp = buf; *cp == ' ' || *cp == '\t'; cp++);
for (i = 0; i < namesize - 1 && isgraph (*cp); name[i++] = *cp++); for (i = 0; i < namesize - 1 && isgraph (*cp); name[i++] = *cp++);
while (isgraph (*cp)) while (isgraph (*cp)) {
cp++; cp++;
}
if (*cp) if ('\0' != *cp) {
cp++; cp++;
}
name[i] = '\0'; name[i] = '\0';
@ -136,15 +144,16 @@ void login_prompt (const char *prompt, char *name, int namesize)
* to do this, and I just take the easy way out. * to do this, and I just take the easy way out.
*/ */
if (*cp != '\0') { /* process new variables */ if ('\0' != *cp) { /* process new variables */
char *nvar; char *nvar;
int count = 1; int count = 1;
for (envc = 0; envc < MAX_ENV; envc++) { for (envc = 0; envc < MAX_ENV; envc++) {
nvar = strtok (envc ? (char *) 0 : cp, " \t,"); nvar = strtok ((0 != envc) ? (char *) 0 : cp, " \t,");
if (!nvar) if (NULL == nvar) {
break; break;
if (strchr (nvar, '=')) { }
if (strchr (nvar, '=') != NULL) {
envp[envc] = nvar; envp[envc] = nvar;
} else { } else {
envp[envc] = xmalloc (strlen (nvar) + 32); envp[envc] = xmalloc (strlen (nvar) + 32);
@ -163,3 +172,4 @@ void login_prompt (const char *prompt, char *name, int namesize)
signal (SIGTSTP, sigtstp); signal (SIGTSTP, sigtstp);
#endif #endif
} }