Subversion Repositories HelenOS-historic

Rev

Rev 1249 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 jermar 1
/*
2
 * Copyright (C) 2001-2004 Jakub Jermar
1196 cejka 3
 * Copyright (C) 2006 Josef Cejka
1 jermar 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
 
1264 jermar 30
/**
31
 * @file    print.c
32
 * @brief   Printing functions.
33
 */
34
 
1 jermar 35
#include <putchar.h>
36
#include <print.h>
37
#include <synch/spinlock.h>
40 jermar 38
#include <arch/arg.h>
115 jermar 39
#include <arch/asm.h>
228 cejka 40
 
195 vana 41
#include <arch.h>
1 jermar 42
 
1204 jermar 43
SPINLOCK_INITIALIZE(printflock);            /**< printf spinlock */
1 jermar 44
 
1204 jermar 45
#define __PRINTF_FLAG_PREFIX        0x00000001  /* show prefixes 0x or 0 */
1196 cejka 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 */
61 decky 53
 
1196 cejka 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 */
1204 jermar 70
static char digits_big[] = "0123456789ABCDEF";      /* Big hexadecimal characters */
1196 cejka 71
 
72
static inline int isdigit(int c)
228 cejka 73
{
1196 cejka 74
    return ((c >= '0' )&&( c <= '9'));
75
}
1069 cejka 76
 
1196 cejka 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
 
1249 jermar 88
/** Print one string without appending newline to the end.
1204 jermar 89
 *
1229 jermar 90
 * Do not use this function directly - printflock is not locked here.
1204 jermar 91
 *
92
 */
1196 cejka 93
static int putstr(const char *str)
94
{
95
    int count;
1069 cejka 96
    if (str == NULL) {
1196 cejka 97
        str = "(NULL)";
98
    }
452 decky 99
 
1196 cejka 100
    for (count = 0; str[count] != 0; count++) {
101
        putchar(str[count]);
102
    }
103
    return count;
452 decky 104
}
105
 
1229 jermar 106
/** Print count characters from buffer to output.
452 decky 107
 *
1229 jermar 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.
452 decky 112
 */
1196 cejka 113
static int putnchars(const char *buffer, __native count)
452 decky 114
{
115
    int i;
1196 cejka 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;
452 decky 126
}
127
 
1196 cejka 128
/** Print one formatted character
1204 jermar 129
 *
1229 jermar 130
 * @param c Character to print.
1196 cejka 131
 * @param width
132
 * @param flags
1229 jermar 133
 * @return Number of printed characters or EOF.
1196 cejka 134
 */
135
static int print_char(char c, int width, __u64 flags)
136
{
137
    int counter = 0;
138
 
139
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
1204 jermar 140
        while (--width > 0) {   /* one space is consumed by character itself hence the predecrement */
141
            /* FIXME: painfully slow */
1196 cejka 142
            putchar(' ');  
143
            ++counter;
144
        }
145
    }
146
 
147
    putchar(c);
148
    ++counter;
452 decky 149
 
1204 jermar 150
    while (--width > 0) { /* one space is consumed by character itself hence the predecrement */
1196 cejka 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
 
452 decky 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.
1196 cejka 217
 * @param width
218
 * @param precision
452 decky 219
 * @param base Base to print the number in (should
220
 *             be in range 2 .. 16).
1196 cejka 221
 * @param flags output modifiers
1224 cejka 222
 * @return number of written characters or EOF.
452 decky 223
 */
1196 cejka 224
static int print_number(__u64 num, int width, int precision, int base , __u64 flags)
452 decky 225
{
1196 cejka 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;
1226 cejka 230
    int number_size; /* size of plain number */
1196 cejka 231
    int written = 0;
232
    char sgn;
452 decky 233
 
1196 cejka 234
    if (flags & __PRINTF_FLAG_BIGCHARS)
235
        digits = digits_big;   
452 decky 236
 
1196 cejka 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
 
1226 cejka 249
    number_size = size;
250
 
1196 cejka 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)) {
1226 cejka 287
            precision = width - size + number_size;
1196 cejka 288
        }
289
    }
290
 
291
    /* print leading spaces */
1226 cejka 292
    if (number_size > precision) /* We must print whole number not only a part */
293
        precision = number_size;
1196 cejka 294
 
1226 cejka 295
    width -= precision + size - number_size;
1196 cejka 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 */
1226 cejka 340
    precision -= number_size;
1196 cejka 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;
452 decky 359
}
360
 
1229 jermar 361
/** Print formatted string.
61 decky 362
 *
1249 jermar 363
 * Print string formatted according to the fmt parameter
1204 jermar 364
 * and variadic arguments. Each formatting directive
1198 cejka 365
 * must have the following form:
1249 jermar 366
 *
367
 *  \% [ FLAGS ] [ WIDTH ] [ .PRECISION ] [ TYPE ] CONVERSION
61 decky 368
 *
1249 jermar 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.
1198 cejka 383
 *
1249 jermar 384
 * WIDTH:@n
1198 cejka 385
 * Specify minimal width of printed argument. If it is bigger, width is ignored.
1249 jermar 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.
405 jermar 390
 *
1249 jermar 391
 * PRECISION:@n
1198 cejka 392
 * Value precision. For numbers it specifies minimum valid numbers.
393
 * Smaller numbers are printed with leading zeroes. Bigger numbers are not affected.
1204 jermar 394
 * Strings with more than precision characters are cut off.
1249 jermar 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.
1198 cejka 399
 *
1249 jermar 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
1198 cejka 407
 *
408
 *
1249 jermar 409
 * CONVERSION:@n
410
 * %    Print percentile character itself.
405 jermar 411
 *
1198 cejka 412
 * c    Print single character.
405 jermar 413
 *
1198 cejka 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
1249 jermar 417
 *  (as with \%#X or \%#x for 32bit or \%#X / \%#x for 64bit long pointers).
405 jermar 418
 *
1198 cejka 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.
405 jermar 422
 *
1198 cejka 423
 * d,i  Print signed decimal number. There is no difference between d and i conversion.
405 jermar 424
 *
1198 cejka 425
 * u    Print unsigned decimal number.
405 jermar 426
 *
1229 jermar 427
 * X, x Print hexadecimal number with upper- or lower-case. Prefix is not printed by default.
1198 cejka 428
 *
1249 jermar 429
 * All other characters from fmt except the formatting directives
61 decky 430
 * are printed in verbatim.
431
 *
432
 * @param fmt Formatting NULL terminated string.
1229 jermar 433
 * @return Number of printed characters or negative value on failure.
1 jermar 434
 */
1196 cejka 435
int printf(const char *fmt, ...)
1 jermar 436
{
1196 cejka 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 */
40 jermar 442
    va_list ap;
1196 cejka 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;
264 cejka 450
 
1196 cejka 451
    counter = 0;
452
 
40 jermar 453
    va_start(ap, fmt);
1196 cejka 454
 
413 jermar 455
    irqpri = interrupts_disable();
1 jermar 456
    spinlock_lock(&printflock);
40 jermar 457
 
1196 cejka 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
            }
1 jermar 526
 
1196 cejka 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;
1 jermar 554
 
1196 cejka 555
            switch (c = fmt[i]) {
1 jermar 556
 
1196 cejka 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;
1 jermar 579
 
1196 cejka 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
            }
1 jermar 672
 
1196 cejka 673
            if ((retval = print_number(number, width, precision, base, flags)) == EOF ) {
674
                counter = -counter;
675
                goto out;
676
            };
77 jermar 677
 
1196 cejka 678
            counter += retval;
679
            j = i + 1;
680
        }  
681
next_char:
682
 
683
        ++i;
684
    }
674 cejka 685
 
1196 cejka 686
    if (i > j) {
687
        if ((retval = putnchars(&fmt[j], (__native)(i - j))) == EOF) { /* error */
688
            counter = -counter;
689
            goto out;
1 jermar 690
        }
1196 cejka 691
        counter += retval;
1 jermar 692
    }
693
out:
694
    spinlock_unlock(&printflock);
413 jermar 695
    interrupts_restore(irqpri);
40 jermar 696
 
697
    va_end(ap);
1196 cejka 698
    return counter;
1 jermar 699
}