]> granicus.if.org Git - procps-ng/commitdiff
top: make rcfile immune from a potential locale change
authorJim Warner <james.warner@comcast.net>
Mon, 17 Dec 2012 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@enc.com.au>
Sat, 22 Dec 2012 06:07:42 +0000 (17:07 +1100)
The delay interval is kept in the rcfile in a floating
point format and is thus susceptible to changes in the
locale between invocations. So values written as #,###
could not be read if a new locale uses decimal points.

This commit takes control of our own decimal point and
will henceforth make top immune to locale switcharoos.

(now that we know a '.' + 2 spaces is squeezed to one)
(everything's perfectly justified, but it's just luck)

Reference(s):
http://www.freelists.org/post/procps/top-has-a-localedpendent-config-file-toprc
http://lists.opensuse.org/opensuse-bugs/2012-12/msg01466.html

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c

index 0dadc870c7be8093a03bd1a8bb5e414ff201a46d..3d35ab2200e1fc6ca123d55ed7a1377aa68eceb2 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -3061,17 +3061,20 @@ static void configs_read (void) {
 
    fp = fopen(Rc_name, "r");
    if (fp) {
+      int tmp_whole, tmp_fract;
       fbuf[0] = '\0';
       fgets(fbuf, sizeof(fbuf), fp);             // ignore eyecatcher
-      if (5 != fscanf(fp
-         , "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%f, Curwin=%d\n"
-         , &Rc.id, &Rc.mode_altscr, &Rc.mode_irixps, &tmp_delay, &i)) {
+      if (6 != fscanf(fp
+         , "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)) {
             p = fmtmk(N_fmt(RC_bad_files_fmt), Rc_name);
             Rc_questions = -1;
             goto try_inspect_entries;            // maybe a faulty 'inspect' echo
       }
       // you saw that, right?  (fscanf stickin' it to 'i')
       Curwin = &Winstk[i];
+      // this may be ugly, but it keeps us locale independent...
+      tmp_delay = (float)tmp_whole + (float)tmp_fract / 1000;
 
       for (i = 0 ; i < GROUPSMAX; i++) {
          int x;
@@ -3686,9 +3689,12 @@ static void file_writerc (void) {
       return;
    }
    fprintf(fp, "%s's " RCF_EYECATCHER, Myname);
-   fprintf(fp, "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%.3f, Curwin=%d\n"
+   fprintf(fp, "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%d.%d, Curwin=%d\n"
       , RCF_VERSION_ID
-      , Rc.mode_altscr, Rc.mode_irixps, Rc.delay_time, (int)(Curwin - Winstk));
+      , Rc.mode_altscr, Rc.mode_irixps
+        // this may be ugly, but it keeps us locale independent...
+      , (int)Rc.delay_time, (int)((Rc.delay_time - (int)Rc.delay_time) * 1000)
+      , (int)(Curwin - Winstk));
 
    for (i = 0 ; i < GROUPSMAX; i++) {
       fprintf(fp, "%s\tfieldscur=%s\n"