Ignore:
Timestamp:
Apr 28, 2011, 7:41:44 PM (14 years ago)
Author:
chris
Message:
  • Cosmetic changes to comments
  • Fix number to string conversion for negative [decimal] numbers (the minus sign was at the wrong location and the two's complement was not respected). This functionality was unused so far but popped up during a code review.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/os2ahci/libc.c

    r82 r86  
    715715static void long_to_asc(long val, char _far *buf, int base, int zero, int flen)
    716716{
    717   register unsigned long abs_val = (unsigned long) val;
     717  register unsigned long abs_val;
    718718  char tmp[80];
    719719  char _far *ptmp = tmp;
     
    725725  }
    726726
     727  abs_val = (unsigned long) ((val < 0 && base <= 10) ? -val : val);
    727728  tmp[sizeof(tmp) - 1] = '\0';
     729
    728730  for (s = ptmp + sizeof(tmp) - 2; s > ptmp; s--) {
    729731    *s = hex_digits[abs_val % base];
     
    734736  }
    735737
     738  /* left-pad the resulting number with zeros or spaces up to 'flen' */
     739  while (flen > 0) {
     740    *(--s) = (zero) ? '0' : ' ';
     741    flen--;
     742  }
     743
    736744  /* prepend minus sign if val was negative and base is decimal or less */
    737745  if (val < 0 && base <= 0) {
     
    740748  }
    741749
    742   /* left-pad the resulting number with zeros or spaces up to 'flen' */
    743   while (flen > 0) {
    744     *(--s) = (zero) ? '0' : ' ';
    745     flen--;
    746   }
    747 
    748750  strcpy(buf, s);
    749751}
Note: See TracChangeset for help on using the changeset viewer.