* 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>
* 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) {
cp = getdef_str ("ISSUE_FILE");
if (cp && (fp = fopen (cp, "r"))) {
while ((i = getc (fp)) != EOF)
if (NULL != cp) {
fp = fopen (cp, "r");
if (NULL != fp) {
while ((i = getc (fp)) != EOF) {
putc (i, stdout);
}
fclose (fp);
(void) fclose (fp);
}
}
gethostname (buf, sizeof 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);
if (fgets (buf, sizeof buf, stdin) != buf)
if (fgets (buf, sizeof buf, stdin) != buf) {
exit (1);
}
cp = strchr (buf, '\n');
if (!cp)
if (NULL == cp) {
exit (1);
}
*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 (i = 0; i < namesize - 1 && isgraph (*cp); name[i++] = *cp++);
while (isgraph (*cp))
while (isgraph (*cp)) {
cp++;
}
if (*cp)
if ('\0' != *cp) {
cp++;
}
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.
*/
if (*cp != '\0') { /* process new variables */
if ('\0' != *cp) { /* process new variables */
char *nvar;
int count = 1;
for (envc = 0; envc < MAX_ENV; envc++) {
nvar = strtok (envc ? (char *) 0 : cp, " \t,");
if (!nvar)
nvar = strtok ((0 != envc) ? (char *) 0 : cp, " \t,");
if (NULL == nvar) {
break;
if (strchr (nvar, '=')) {
}
if (strchr (nvar, '=') != NULL) {
envp[envc] = nvar;
} else {
envp[envc] = xmalloc (strlen (nvar) + 32);
@ -163,3 +172,4 @@ void login_prompt (const char *prompt, char *name, int namesize)
signal (SIGTSTP, sigtstp);
#endif
}