Subversion Repositories HelenOS-historic

Rev

Rev 1249 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (C) 2001-2004 Jakub Jermar
  3.  * Copyright (C) 2006 Josef Cejka
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  *
  10.  * - Redistributions of source code must retain the above copyright
  11.  *   notice, this list of conditions and the following disclaimer.
  12.  * - Redistributions in binary form must reproduce the above copyright
  13.  *   notice, this list of conditions and the following disclaimer in the
  14.  *   documentation and/or other materials provided with the distribution.
  15.  * - The name of the author may not be used to endorse or promote products
  16.  *   derived from this software without specific prior written permission.
  17.  *
  18.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  19.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28.  */
  29.  
  30. /**
  31.  * @file    print.c
  32.  * @brief   Printing functions.
  33.  */
  34.  
  35. #include <putchar.h>
  36. #include <print.h>
  37. #include <synch/spinlock.h>
  38. #include <arch/arg.h>
  39. #include <arch/asm.h>
  40.  
  41. #include <arch.h>
  42.  
  43. SPINLOCK_INITIALIZE(printflock);            /**< printf spinlock */
  44.  
  45. #define __PRINTF_FLAG_PREFIX        0x00000001  /* show prefixes 0x or 0 */
  46. #define __PRINTF_FLAG_SIGNED        0x00000002  /* signed / unsigned number */
  47. #define __PRINTF_FLAG_ZEROPADDED    0x00000004  /* print leading zeroes */
  48. #define __PRINTF_FLAG_LEFTALIGNED   0x00000010  /* align to left */
  49. #define __PRINTF_FLAG_SHOWPLUS      0x00000020  /* always show + sign */
  50. #define __PRINTF_FLAG_SPACESIGN     0x00000040  /* print space instead of plus */
  51. #define __PRINTF_FLAG_BIGCHARS      0x00000080  /* show big characters */
  52. #define __PRINTF_FLAG_NEGATIVE      0x00000100  /* number has - sign */
  53.  
  54. #define PRINT_NUMBER_BUFFER_SIZE    (64+5)      /* Buffer big enought for 64 bit number
  55.                              * printed in base 2, sign, prefix and
  56.                              * 0 to terminate string.. (last one is only for better testing
  57.                              * end of buffer by zero-filling subroutine)
  58.                              */
  59. typedef enum {
  60.     PrintfQualifierByte = 0,
  61.     PrintfQualifierShort,
  62.     PrintfQualifierInt,
  63.     PrintfQualifierLong,
  64.     PrintfQualifierLongLong,
  65.     PrintfQualifierNative,
  66.     PrintfQualifierPointer
  67. } qualifier_t;
  68.  
  69. static char digits_small[] = "0123456789abcdef";    /* Small hexadecimal characters */
  70. static char digits_big[] = "0123456789ABCDEF";      /* Big hexadecimal characters */
  71.  
  72. static inline int isdigit(int c)
  73. {
  74.     return ((c >= '0' )&&( c <= '9'));
  75. }
  76.  
  77. static __native strlen(const char *str)
  78. {
  79.     __native counter = 0;
  80.  
  81.     while (str[counter] != 0) {
  82.         counter++;
  83.     }
  84.  
  85.     return counter;
  86. }
  87.  
  88. /** Print one string without appending newline to the end.
  89.  *
  90.  * Do not use this function directly - printflock is not locked here.
  91.  *
  92.  */
  93. static int putstr(const char *str)
  94. {
  95.     int count;
  96.     if (str == NULL) {
  97.         str = "(NULL)";
  98.     }
  99.    
  100.     for (count = 0; str[count] != 0; count++) {
  101.         putchar(str[count]);
  102.     }
  103.     return count;
  104. }
  105.  
  106. /** Print count characters from buffer to output.
  107.  *
  108.  * @param buffer Address of the buffer with charaters to be printed.
  109.  * @param count Number of characters to be printed.
  110.  *
  111.  * @return Number of characters printed.
  112.  */
  113. static int putnchars(const char *buffer, __native count)
  114. {
  115.     int i;
  116.     if (buffer == NULL) {
  117.         buffer = "(NULL)";
  118.         count = 6;
  119.     }
  120.  
  121.     for (i = 0; i < count; i++) {
  122.         putchar(buffer[i]);
  123.     }
  124.    
  125.     return count;
  126. }
  127.  
  128. /** Print one formatted character
  129.  *
  130.  * @param c Character to print.
  131.  * @param width
  132.  * @param flags
  133.  * @return Number of printed characters or EOF.
  134.  */
  135. static int print_char(char c, int width, __u64 flags)
  136. {
  137.     int counter = 0;
  138.    
  139.     if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
  140.         while (--width > 0) {   /* one space is consumed by character itself hence the predecrement */
  141.             /* FIXME: painfully slow */
  142.             putchar(' ');  
  143.             ++counter;
  144.         }
  145.     }
  146.    
  147.     putchar(c);
  148.     ++counter;
  149.  
  150.     while (--width > 0) { /* one space is consumed by character itself hence the predecrement */
  151.         putchar(' ');
  152.         ++counter;
  153.     }
  154.    
  155.     return counter;
  156. }
  157.  
  158. /** Print one string
  159.  * @param s string
  160.  * @param width
  161.  * @param precision
  162.  * @param flags
  163.  * @return number of printed characters or EOF
  164.  */
  165. static int print_string(char *s, int width, int precision, __u64 flags)
  166. {
  167.     int counter = 0;
  168.     __native size;
  169.  
  170.     if (s == NULL) {
  171.         return putstr("(NULL)");
  172.     }
  173.    
  174.     size = strlen(s);
  175.  
  176.     /* print leading spaces */
  177.  
  178.     if (precision == 0)
  179.         precision = size;
  180.  
  181.     width -= precision;
  182.    
  183.     if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
  184.         while (width-- > 0) {  
  185.             putchar(' ');  
  186.             counter++;
  187.         }
  188.     }
  189.  
  190.     while (precision > size) {
  191.         precision--;
  192.         putchar(' ');  
  193.         ++counter;
  194.     }
  195.    
  196.     if (putnchars(s, precision) == EOF) {
  197.         return EOF;
  198.     }
  199.  
  200.     counter += precision;
  201.  
  202.     while (width-- > 0) {
  203.         putchar(' ');  
  204.         ++counter;
  205.     }
  206.    
  207.     return ++counter;
  208. }
  209.  
  210.  
  211. /** Print number in given base
  212.  *
  213.  * Print significant digits of a number in given
  214.  * base.
  215.  *
  216.  * @param num  Number to print.
  217.  * @param width
  218.  * @param precision
  219.  * @param base Base to print the number in (should
  220.  *             be in range 2 .. 16).
  221.  * @param flags output modifiers
  222.  * @return number of written characters or EOF.
  223.  */
  224. static int print_number(__u64 num, int width, int precision, int base , __u64 flags)
  225. {
  226.     char *digits = digits_small;
  227.     char d[PRINT_NUMBER_BUFFER_SIZE];   /* this is good enough even for base == 2, prefix and sign */
  228.     char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
  229.     int size = 0;
  230.     int number_size; /* size of plain number */
  231.     int written = 0;
  232.     char sgn;
  233.    
  234.     if (flags & __PRINTF_FLAG_BIGCHARS)
  235.         digits = digits_big;   
  236.    
  237.     *ptr-- = 0; /* Put zero at end of string */
  238.  
  239.     if (num == 0) {
  240.         *ptr-- = '0';
  241.         size++;
  242.     } else {
  243.         do {
  244.             *ptr-- = digits[num % base];
  245.             size++;
  246.         } while (num /= base);
  247.     }
  248.  
  249.     number_size = size;
  250.    
  251.     /* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
  252.     if (flags & __PRINTF_FLAG_PREFIX) {
  253.         switch(base) {
  254.             case 2: /* Binary formating is not standard, but usefull */
  255.                 size += 2;
  256.                 break;
  257.             case 8:
  258.                 size++;
  259.                 break;
  260.             case 16:
  261.                 size += 2;
  262.                 break;
  263.         }
  264.     }
  265.  
  266.     sgn = 0;
  267.     if (flags & __PRINTF_FLAG_SIGNED) {
  268.         if (flags & __PRINTF_FLAG_NEGATIVE) {
  269.             sgn = '-';
  270.             size++;
  271.         } else if (flags & __PRINTF_FLAG_SHOWPLUS) {
  272.                 sgn = '+';
  273.                 size++;
  274.             } else if (flags & __PRINTF_FLAG_SPACESIGN) {
  275.                     sgn = ' ';
  276.                     size++;
  277.                 }
  278.     }
  279.  
  280.     if (flags & __PRINTF_FLAG_LEFTALIGNED) {
  281.         flags &= ~__PRINTF_FLAG_ZEROPADDED;
  282.     }
  283.  
  284.     /* if number is leftaligned or precision is specified then zeropadding is ignored */
  285.     if (flags & __PRINTF_FLAG_ZEROPADDED) {
  286.         if ((precision == 0) && (width > size)) {
  287.             precision = width - size + number_size;
  288.         }
  289.     }
  290.  
  291.     /* print leading spaces */
  292.     if (number_size > precision) /* We must print whole number not only a part */
  293.         precision = number_size;
  294.  
  295.     width -= precision + size - number_size;
  296.    
  297.     if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
  298.         while (width-- > 0) {  
  299.             putchar(' ');  
  300.             written++;
  301.         }
  302.     }
  303.    
  304.     /* print sign */
  305.     if (sgn) {
  306.         putchar(sgn);
  307.         written++;
  308.     }
  309.    
  310.     /* print prefix */
  311.    
  312.     if (flags & __PRINTF_FLAG_PREFIX) {
  313.         switch(base) {
  314.             case 2: /* Binary formating is not standard, but usefull */
  315.                 putchar('0');
  316.                 if (flags & __PRINTF_FLAG_BIGCHARS) {
  317.                     putchar('B');
  318.                 } else {
  319.                     putchar('b');
  320.                 }
  321.                 written += 2;
  322.                 break;
  323.             case 8:
  324.                 putchar('o');
  325.                 written++;
  326.                 break;
  327.             case 16:
  328.                 putchar('0');
  329.                 if (flags & __PRINTF_FLAG_BIGCHARS) {
  330.                     putchar('X');
  331.                 } else {
  332.                     putchar('x');
  333.                 }
  334.                 written += 2;
  335.                 break;
  336.         }
  337.     }
  338.  
  339.     /* print leading zeroes */
  340.     precision -= number_size;
  341.     while (precision-- > 0) {  
  342.         putchar('0');  
  343.         written++;
  344.     }
  345.  
  346.    
  347.     /* print number itself */
  348.  
  349.     written += putstr(++ptr);
  350.    
  351.     /* print ending spaces */
  352.    
  353.     while (width-- > 0) {  
  354.         putchar(' ');  
  355.         written++;
  356.     }
  357.  
  358.     return written;
  359. }
  360.  
  361. /** Print formatted string.
  362.  *
  363.  * Print string formatted according to the fmt parameter
  364.  * and variadic arguments. Each formatting directive
  365.  * must have the following form:
  366.  *
  367.  *  \% [ FLAGS ] [ WIDTH ] [ .PRECISION ] [ TYPE ] CONVERSION
  368.  *
  369.  * FLAGS:@n
  370.  * "#"  Force to print prefix.
  371.  *  For conversion \%o the prefix is 0, for %x and \%X prefixes are 0x and 0X
  372.  *  and for conversion \%b the prefix is 0b.
  373.  *
  374.  * "-"  Align to left.
  375.  *
  376.  * "+"  Print positive sign just as negative.
  377.  *
  378.  * " "  If the printed number is positive and "+" flag is not set, print space in
  379.  *  place of sign.
  380.  *
  381.  * "0"  Print 0 as padding instead of spaces. Zeroes are placed between sign and the
  382.  *  rest of the number. This flag is ignored if "-" flag is specified.
  383.  *
  384.  * WIDTH:@n
  385.  * Specify minimal width of printed argument. If it is bigger, width is ignored.
  386.  * If width is specified with a "*" character instead of number, width is taken from
  387.  * parameter list. And integer parameter is expected before parameter for processed
  388.  * conversion specification. If this value is negative its absolute value is taken
  389.  * and the "-" flag is set.
  390.  *
  391.  * PRECISION:@n
  392.  * Value precision. For numbers it specifies minimum valid numbers.
  393.  * Smaller numbers are printed with leading zeroes. Bigger numbers are not affected.
  394.  * Strings with more than precision characters are cut off.
  395.  * Just as with width, an "*" can be used used instead of a number.
  396.  * An integer value is then expected in parameters. When both width and precision
  397.  * are specified using "*", the first parameter is used for width and the second one
  398.  * for precision.
  399.  *
  400.  * TYPE:@n
  401.  * "hh" Signed or unsigned char.@n
  402.  * "h"  Signed or usigned short.@n
  403.  * ""   Signed or usigned int (default value).@n
  404.  * "l"  Signed or usigned long int.@n
  405.  * "ll" Signed or usigned long long int.@n
  406.  * "z"  __native (non-standard extension).@n
  407.  *
  408.  *
  409.  * CONVERSION:@n
  410.  * %    Print percentile character itself.
  411.  *
  412.  * c    Print single character.
  413.  *
  414.  * s    Print zero terminated string. If a NULL value is passed as value, "(NULL)" is printed instead.
  415.  *
  416.  * P, p Print value of a pointer. Void * value is expected and it is printed in hexadecimal notation with prefix
  417.  *  (as with \%#X or \%#x for 32bit or \%#X / \%#x for 64bit long pointers).
  418.  *
  419.  * b    Print value as unsigned binary number. Prefix is not printed by default. (Nonstandard extension.)
  420.  *
  421.  * o    Print value as unsigned octal number. Prefix is not printed by default.
  422.  *
  423.  * d,i  Print signed decimal number. There is no difference between d and i conversion.
  424.  *
  425.  * u    Print unsigned decimal number.
  426.  *
  427.  * X, x Print hexadecimal number with upper- or lower-case. Prefix is not printed by default.
  428.  *
  429.  * All other characters from fmt except the formatting directives
  430.  * are printed in verbatim.
  431.  *
  432.  * @param fmt Formatting NULL terminated string.
  433.  * @return Number of printed characters or negative value on failure.
  434.  */
  435. int printf(const char *fmt, ...)
  436. {
  437.     int irqpri;
  438.     int i = 0, j = 0; /* i is index of currently processed char from fmt, j is index to the first not printed nonformating character */
  439.     int end;
  440.     int counter; /* counter of printed characters */
  441.     int retval; /* used to store return values from called functions */
  442.     va_list ap;
  443.     char c;
  444.     qualifier_t qualifier;  /* type of argument */
  445.     int base;   /* base in which will be parameter (numbers only) printed */
  446.     __u64 number; /* argument value */
  447.     __native size; /* byte size of integer parameter */
  448.     int width, precision;
  449.     __u64 flags;
  450.    
  451.     counter = 0;
  452.    
  453.     va_start(ap, fmt);
  454.    
  455.     irqpri = interrupts_disable();
  456.     spinlock_lock(&printflock);
  457.  
  458.    
  459.     while ((c = fmt[i])) {
  460.         /* control character */
  461.         if (c == '%' ) {
  462.             /* print common characters if any processed */ 
  463.             if (i > j) {
  464.                 if ((retval = putnchars(&fmt[j], (__native)(i - j))) == EOF) { /* error */
  465.                     counter = -counter;
  466.                     goto out;
  467.                 }
  468.                 counter += retval;
  469.             }
  470.        
  471.             j = i;
  472.             /* parse modifiers */
  473.             flags = 0;
  474.             end = 0;
  475.            
  476.             do {
  477.                 ++i;
  478.                 switch (c = fmt[i]) {
  479.                     case '#': flags |= __PRINTF_FLAG_PREFIX; break;
  480.                     case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break;
  481.                     case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break;
  482.                     case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break;
  483.                     case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break;
  484.                     default: end = 1;
  485.                 }; 
  486.                
  487.             } while (end == 0);
  488.            
  489.             /* width & '*' operator */
  490.             width = 0;
  491.             if (isdigit(fmt[i])) {
  492.                 while (isdigit(fmt[i])) {
  493.                     width *= 10;
  494.                     width += fmt[i++] - '0';
  495.                 }
  496.             } else if (fmt[i] == '*') {
  497.                 /* get width value from argument list*/
  498.                 i++;
  499.                 width = (int)va_arg(ap, int);
  500.                 if (width < 0) {
  501.                     /* negative width means to set '-' flag */
  502.                     width *= -1;
  503.                     flags |= __PRINTF_FLAG_LEFTALIGNED;
  504.                 }
  505.             }
  506.            
  507.             /* precision and '*' operator */   
  508.             precision = 0;
  509.             if (fmt[i] == '.') {
  510.                 ++i;
  511.                 if (isdigit(fmt[i])) {
  512.                     while (isdigit(fmt[i])) {
  513.                         precision *= 10;
  514.                         precision += fmt[i++] - '0';
  515.                     }
  516.                 } else if (fmt[i] == '*') {
  517.                     /* get precision value from argument list*/
  518.                     i++;
  519.                     precision = (int)va_arg(ap, int);
  520.                     if (precision < 0) {
  521.                         /* negative precision means to ignore it */
  522.                         precision = 0;
  523.                     }
  524.                 }
  525.             }
  526.  
  527.             switch (fmt[i++]) {
  528.                 /** TODO: unimplemented qualifiers:
  529.                  * t ptrdiff_t - ISO C 99
  530.                  */
  531.                 case 'h':   /* char or short */
  532.                     qualifier = PrintfQualifierShort;
  533.                     if (fmt[i] == 'h') {
  534.                         i++;
  535.                         qualifier = PrintfQualifierByte;
  536.                     }
  537.                     break;
  538.                 case 'l':   /* long or long long*/
  539.                     qualifier = PrintfQualifierLong;
  540.                     if (fmt[i] == 'l') {
  541.                         i++;
  542.                         qualifier = PrintfQualifierLongLong;
  543.                     }
  544.                     break;
  545.                 case 'z':   /* __native */
  546.                     qualifier = PrintfQualifierNative;
  547.                     break;
  548.                 default:
  549.                     qualifier = PrintfQualifierInt; /* default type */
  550.                     --i;
  551.             }  
  552.            
  553.             base = 10;
  554.  
  555.             switch (c = fmt[i]) {
  556.  
  557.                 /*
  558.                 * String and character conversions.
  559.                 */
  560.                 case 's':
  561.                     if ((retval = print_string(va_arg(ap, char*), width, precision, flags)) == EOF) {
  562.                         counter = -counter;
  563.                         goto out;
  564.                     };
  565.                    
  566.                     counter += retval;
  567.                     j = i + 1;
  568.                     goto next_char;
  569.                 case 'c':
  570.                     c = va_arg(ap, unsigned int);
  571.                     if ((retval = print_char(c, width, flags )) == EOF) {
  572.                         counter = -counter;
  573.                         goto out;
  574.                     };
  575.                    
  576.                     counter += retval;
  577.                     j = i + 1;
  578.                     goto next_char;
  579.  
  580.                 /*
  581.                  * Integer values
  582.                 */
  583.                 case 'P': /* pointer */
  584.                         flags |= __PRINTF_FLAG_BIGCHARS;
  585.                 case 'p':
  586.                     flags |= __PRINTF_FLAG_PREFIX;
  587.                     base = 16;
  588.                     qualifier = PrintfQualifierPointer;
  589.                     break; 
  590.                 case 'b':
  591.                     base = 2;
  592.                     break;
  593.                 case 'o':
  594.                     base = 8;
  595.                     break;
  596.                 case 'd':
  597.                 case 'i':
  598.                     flags |= __PRINTF_FLAG_SIGNED;  
  599.                 case 'u':
  600.                     break;
  601.                 case 'X':
  602.                     flags |= __PRINTF_FLAG_BIGCHARS;
  603.                 case 'x':
  604.                     base = 16;
  605.                     break;
  606.                 /* percentile itself */
  607.                 case '%':
  608.                     j = i;
  609.                     goto next_char;
  610.                 /*
  611.                 * Bad formatting.
  612.                 */
  613.                 default:
  614.                     /* Unknown format
  615.                      *  now, the j is index of '%' so we will
  616.                      * print whole bad format sequence
  617.                      */
  618.                     goto next_char;    
  619.             }
  620.        
  621.        
  622.         /* Print integers */
  623.             /* print number */
  624.             switch (qualifier) {
  625.                 case PrintfQualifierByte:
  626.                     size = sizeof(unsigned char);
  627.                     number = (__u64)va_arg(ap, unsigned int);
  628.                     break;
  629.                 case PrintfQualifierShort:
  630.                     size = sizeof(unsigned short);
  631.                     number = (__u64)va_arg(ap, unsigned int);
  632.                     break;
  633.                 case PrintfQualifierInt:
  634.                     size = sizeof(unsigned int);
  635.                     number = (__u64)va_arg(ap, unsigned int);
  636.                     break;
  637.                 case PrintfQualifierLong:
  638.                     size = sizeof(unsigned long);
  639.                     number = (__u64)va_arg(ap, unsigned long);
  640.                     break;
  641.                 case PrintfQualifierLongLong:
  642.                     size = sizeof(unsigned long long);
  643.                     number = (__u64)va_arg(ap, unsigned long long);
  644.                     break;
  645.                 case PrintfQualifierPointer:
  646.                     size = sizeof(void *);
  647.                     number = (__u64)(unsigned long)va_arg(ap, void *);
  648.                     break;
  649.                 case PrintfQualifierNative:
  650.                     size = sizeof(__native);
  651.                     number = (__u64)va_arg(ap, __native);
  652.                     break;
  653.                 default: /* Unknown qualifier */
  654.                     counter = -counter;
  655.                     goto out;
  656.                    
  657.             }
  658.            
  659.             if (flags & __PRINTF_FLAG_SIGNED) {
  660.                 if (number & (0x1 << (size*8 - 1))) {
  661.                     flags |= __PRINTF_FLAG_NEGATIVE;
  662.                
  663.                     if (size == sizeof(__u64)) {
  664.                         number = -((__s64)number);
  665.                     } else {
  666.                         number = ~number;
  667.                         number &= (~((0xFFFFFFFFFFFFFFFFll) <<  (size * 8)));
  668.                         number++;
  669.                     }
  670.                 }
  671.             }
  672.  
  673.             if ((retval = print_number(number, width, precision, base, flags)) == EOF ) {
  674.                 counter = -counter;
  675.                 goto out;
  676.             };
  677.  
  678.             counter += retval;
  679.             j = i + 1;
  680.         }  
  681. next_char:
  682.            
  683.         ++i;
  684.     }
  685.    
  686.     if (i > j) {
  687.         if ((retval = putnchars(&fmt[j], (__native)(i - j))) == EOF) { /* error */
  688.             counter = -counter;
  689.             goto out;
  690.         }
  691.         counter += retval;
  692.     }
  693. out:
  694.     spinlock_unlock(&printflock);
  695.     interrupts_restore(irqpri);
  696.    
  697.     va_end(ap);
  698.     return counter;
  699. }
  700.