boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

printf-int-promo.after (1234B)


      1         /* boot2: track the `l` length modifier so %d/%c read the
      2            correct width. amd64 SysV stores int varargs as a 32-bit
      3            write into an 8-byte reg-save slot — upper bits unspecified.
      4            Reading via va_arg(ap, long) for plain %d / %c picks up
      5            garbage. long==int64 on all our LP64 targets, so `ll` and
      6            `l` collapse to one case. */
      7         int long_p = 0;
      8         if (c == 'l')
      9           {
     10             long_p = 1;
     11             c = *++p;
     12           }
     13         if (c == 'l')
     14           c = *++p;
     15         switch (c)
     16           {
     17           case '%':
     18             {
     19               fputc (*p, f);
     20               count++;
     21               break;
     22             }
     23           case 'c':
     24             {
     25               char _c;
     26               _c = va_arg (ap, int);
     27               fputc (_c, f);
     28               break;
     29             }
     30           case 'd':
     31           case 'i':
     32           case 'o':
     33           case 'u':
     34           case 'x':
     35           case 'X':
     36             {
     37               long d;
     38               if (long_p)
     39                 d = va_arg (ap, long);
     40               else if (c == 'd' || c == 'i' || c == 'o')
     41                 d = va_arg (ap, int);
     42               else
     43                 d = va_arg (ap, unsigned int);