top: correct, improve and otherwise tweak configs_read

This patch addresses the four '-Wunused-result' errors
generated whenever an optimized compile is invoked. It
also made the configs_read() guy a little more robust.

In the process, some logic was rearranged slightly and
some comments were re-indented simply for consistency.

Reference(s):
warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result]
warning: ignoring return value of 'fscanf', declared with attribute warn_unused_result [-Wunused-result]

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2013-08-20 00:00:00 -05:00 committed by Craig Small
parent 80e6783436
commit 819ede1a6b

View File

@ -3394,20 +3394,19 @@ static void configs_read (void) {
fp = fopen(SYS_RCFILESPEC, "r"); fp = fopen(SYS_RCFILESPEC, "r");
if (fp) { if (fp) {
fbuf[0] = '\0'; if (fgets(fbuf, sizeof(fbuf), fp)) { // sys rc file, line 1
fgets(fbuf, sizeof(fbuf), fp); // sys rc file, line 1 Secure_mode = 1;
if (strchr(fbuf, 's')) Secure_mode = 1; if (fgets(fbuf, sizeof(fbuf), fp)) // sys rc file, line 2
fbuf[0] = '\0';
fgets(fbuf, sizeof(fbuf), fp); // sys rc file, line 2
sscanf(fbuf, "%f", &Rc.delay_time); sscanf(fbuf, "%f", &Rc.delay_time);
}
fclose(fp); fclose(fp);
} }
fp = fopen(Rc_name, "r"); fp = fopen(Rc_name, "r");
if (fp) { if (fp) {
int tmp_whole, tmp_fract; int tmp_whole, tmp_fract;
fbuf[0] = '\0'; if (fgets(fbuf, sizeof(fbuf), fp)) // ignore eyecatcher
fgets(fbuf, sizeof(fbuf), fp); // ignore eyecatcher ; // avoid -Wunused-result
if (6 != fscanf(fp if (6 != fscanf(fp
, "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%d.%d, Curwin=%d\n" , "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%d.%d, Curwin=%d\n"
, &Rc.id, &Rc.mode_altscr, &Rc.mode_irixps, &tmp_whole, &tmp_fract, &i)) { , &Rc.id, &Rc.mode_altscr, &Rc.mode_irixps, &tmp_whole, &tmp_fract, &i)) {
@ -3442,6 +3441,10 @@ static void configs_read (void) {
goto default_or_error; goto default_or_error;
switch (Rc.id) { switch (Rc.id) {
case 'a': // 3.2.8 (former procps)
if (config_cvt(w))
goto default_or_error;
break;
case 'f': // 3.3.0 thru 3.3.3 (procps-ng) case 'f': // 3.3.0 thru 3.3.3 (procps-ng)
SETw(w, Show_JRNUMS); // fall through ! SETw(w, Show_JRNUMS); // fall through !
case 'g': // current RCF_VERSION_ID case 'g': // current RCF_VERSION_ID
@ -3452,10 +3455,6 @@ static void configs_read (void) {
if (P_MAXPFLGS <= FLDget(w, x)) if (P_MAXPFLGS <= FLDget(w, x))
goto default_or_error; goto default_or_error;
break; break;
case 'a': // 3.2.8 (former procps)
if (config_cvt(w))
goto default_or_error;
break;
} }
#ifndef USE_X_COLHDR #ifndef USE_X_COLHDR
OFFw(w, NOHIFND_xxx | NOHISEL_xxx); OFFw(w, NOHIFND_xxx | NOHISEL_xxx);
@ -3463,8 +3462,9 @@ static void configs_read (void) {
} // end: for (GROUPSMAX) } // end: for (GROUPSMAX)
// any new addition(s) last, for older rcfiles compatibility... // any new addition(s) last, for older rcfiles compatibility...
fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n" if (fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n"
, &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale, &Rc.zero_suppress); , &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale, &Rc.zero_suppress))
; // avoid -Wunused-result
try_inspect_entries: try_inspect_entries:
// we'll start off Inspect stuff with 1 'potential' blank line // we'll start off Inspect stuff with 1 'potential' blank line