Index: uspace/lib/libc/generic/io/printf_core.c
===================================================================
--- uspace/lib/libc/generic/io/printf_core.c	(revision 18525c5d2b1b3fc82c58b90a93e456fcb60d2a56)
+++ uspace/lib/libc/generic/io/printf_core.c	(revision 8ecba18be536a7e7a923036b6b1f76b6af2a9a82)
@@ -77,5 +77,6 @@
  * @return number of printed characters
  */
-static int printf_putnchars(const char * buf, size_t count, struct printf_spec *ps)
+static int printf_putnchars(const char * buf, size_t count,
+    struct printf_spec *ps)
 {
 	return ps->write((void *)buf, count, ps->data);
@@ -125,5 +126,9 @@
 	
 	if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
-		while (--width > 0) { 	/* one space is consumed by character itself hence predecrement */
+		/*
+		 * One space is consumed by the character itself, hence the
+		 * predecrement.
+		 */
+		while (--width > 0) {
 			if (printf_putchar(' ', ps) > 0)	
 				++counter;
@@ -133,6 +138,9 @@
 	if (printf_putchar(c, ps) > 0)
 		counter++;
-	
-	while (--width > 0) { /* one space is consumed by character itself hence predecrement */
+	/*
+	 * One space is consumed by the character itself, hence the
+	 * predecrement.
+	 */
+	while (--width > 0) {
 		if (printf_putchar(' ', ps) > 0)
 			++counter;
@@ -149,6 +157,6 @@
  * @return number of printed characters
  */
-						
-static int print_string(char *s, int width, int precision, uint64_t flags, struct printf_spec *ps)
+static int print_string(char *s, int width, int precision, uint64_t flags,
+    struct printf_spec *ps)
 {
 	int counter = 0;
@@ -176,11 +184,6 @@
 	}
 
-	while (precision > size) {
-		precision--;
-		if (printf_putchar(' ', ps) == 1)	
-			++counter;
-	}
-	
- 	if ((retval = printf_putnchars(s, precision, ps)) < 0) {
+ 	if ((retval = printf_putnchars(s, size < precision ? size : precision,
+	    ps)) < 0) {
 		return -counter;
 	}
@@ -211,8 +214,10 @@
  *
  */
-static int print_number(uint64_t num, int width, int precision, int base , uint64_t flags, struct printf_spec *ps)
+static int print_number(uint64_t num, int width, int precision, int base,
+    uint64_t flags, struct printf_spec *ps)
 {
 	char *digits = digits_small;
-	char d[PRINT_NUMBER_BUFFER_SIZE];	/* this is good enough even for base == 2, prefix and sign */
+	char d[PRINT_NUMBER_BUFFER_SIZE];	/* this is good enough even for
+						 * base == 2, prefix and sign */
 	char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
 	int size = 0; /* size of number with all prefixes and signs */
@@ -239,5 +244,8 @@
 	number_size = size;
 
-	/* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
+	/*
+	 * Collect sum of all prefixes/signs/... to calculate padding and
+	 * leading zeroes
+	 */
 	if (flags & __PRINTF_FLAG_PREFIX) {
 		switch(base) {
@@ -260,10 +268,10 @@
 			size++;
 		} else if (flags & __PRINTF_FLAG_SHOWPLUS) {
-				sgn = '+';
-				size++;
-			} else if (flags & __PRINTF_FLAG_SPACESIGN) {
-					sgn = ' ';
-					size++;
-				}
+			sgn = '+';
+			size++;
+		} else if (flags & __PRINTF_FLAG_SPACESIGN) {
+			sgn = ' ';
+			size++;
+		}
 	}
 
@@ -272,5 +280,8 @@
 	}
 
-	/* if number is leftaligned or precision is specified then zeropadding is ignored */
+	/*
+	 * If number is leftaligned or precision is specified then zeropadding
+	 * is ignored.
+	 */
 	if (flags & __PRINTF_FLAG_ZEROPADDED) {
 		if ((precision == 0) && (width > size)) {
@@ -280,5 +291,7 @@
 
 	/* print leading spaces */
-	if (number_size > precision) /* We must print whole number not only a part */
+
+	/* We must print whole number not only a part. */
+	if (number_size > precision)
 		precision = number_size;
 
@@ -358,7 +371,6 @@
 /** Print formatted string.
  *
- * Print string formatted according to the fmt parameter
- * and variadic arguments. Each formatting directive
- * must have the following form:
+ * Print string formatted according to the fmt parameter and variadic arguments.
+ * Each formatting directive must have the following form:
  * 
  * 	\% [ FLAGS ] [ WIDTH ] [ .PRECISION ] [ TYPE ] CONVERSION
@@ -366,6 +378,6 @@
  * FLAGS:@n
  * 	- "#" Force to print prefix.
- * 	For conversion \%o the prefix is 0, for %x and \%X prefixes are 0x and 0X
- *	and for conversion \%b the prefix is 0b.
+ * 	For conversion \%o the prefix is 0, for %x and \%X prefixes are 0x and
+ *	0X and for conversion \%b the prefix is 0b.
  *
  * 	- "-"	Align to left.
@@ -373,25 +385,26 @@
  * 	- "+"	Print positive sign just as negative.
  *
- * 	- " "	If the printed number is positive and "+" flag is not set, print space in
- *	place of sign.
- *
- * 	- "0"	Print 0 as padding instead of spaces. Zeroes are placed between sign and the
- *	rest of the number. This flag is ignored if "-" flag is specified.
+ * 	- " "	If the printed number is positive and "+" flag is not set,
+ *		print space in place of sign.
+ *
+ * 	- "0"	Print 0 as padding instead of spaces. Zeroes are placed between
+ *		sign and the rest of the number. This flag is ignored if "-"
+ *		flag is specified.
  * 
  * WIDTH:@n
- * 	- Specify minimal width of printed argument. If it is bigger, width is ignored.
- * If width is specified with a "*" character instead of number, width is taken from
- * parameter list. And integer parameter is expected before parameter for processed
- * conversion specification. If this value is negative its absolute value is taken
- * and the "-" flag is set.
+ * 	- Specify minimal width of printed argument. If it is bigger, width is
+ *	  ignored. If width is specified with a "*" character instead of number,
+ *	  width is taken from parameter list. And integer parameter is expected
+ *	  before parameter for processed conversion specification. If this value
+ *	  is negative its absolute value is taken and the "-" flag is set.
  *
  * PRECISION:@n
  * 	- Value precision. For numbers it specifies minimum valid numbers.
- * Smaller numbers are printed with leading zeroes. Bigger numbers are not affected.
- * Strings with more than precision characters are cut off.
- * Just as with width, an "*" can be used used instead of a number.
- * An integer value is then expected in parameters. When both width and precision
- * are specified using "*", the first parameter is used for width and the second one
- * for precision.
+ *	  Smaller numbers are printed with leading zeroes. Bigger numbers are
+ *	  not affected. Strings with more than precision characters are cut off.
+ *	  Just as with width, an "*" can be used used instead of a number. An
+ *	  integer value is then expected in parameters. When both width and
+ *	  precision are specified using "*", the first parameter is used for
+ *	  width and the second one for precision.
  * 
  * TYPE:@n
@@ -409,21 +422,27 @@
  * 	- c	Print single character.
  *
- * 	- s	Print zero terminated string. If a NULL value is passed as value, "(NULL)" is printed instead.
+ * 	- s	Print zero terminated string. If a NULL value is passed as
+ *		value, "(NULL)" is printed instead.
  * 
- * 	- P, p	Print value of a pointer. Void * value is expected and it is printed in hexadecimal notation with prefix
- * 	(as with '\%#X' or '\%#x' for 32bit or '\%#X' or '\%#x' for 64bit long pointers).
- *
- * 	- b	Print value as unsigned binary number. Prefix is not printed by default. (Nonstandard extension.)
+ * 	- P, p	Print value of a pointer. Void * value is expected and it is
+ *		printed in hexadecimal notation with prefix (as with '\%#X' or
+ *		'\%#x' for 32bit or '\%#X' or '\%#x' for 64bit long pointers).
+ *
+ * 	- b	Print value as unsigned binary number. Prefix is not printed by
+ *		default. (Nonstandard extension.)
  * 
- * 	- o	Print value as unsigned octal number. Prefix is not printed by default. 
- *
- * 	- d,i	Print signed decimal number. There is no difference between d and i conversion.
+ * 	- o	Print value as unsigned octal number. Prefix is not printed by
+ *		default. 
+ *
+ * 	- d, i	Print signed decimal number. There is no difference between d
+ *		and i conversion.
  *
  * 	- u	Print unsigned decimal number.
  *
- * 	- X, x	Print hexadecimal number with upper- or lower-case. Prefix is not printed by default.
+ * 	- X, x	Print hexadecimal number with upper- or lower-case. Prefix is
+ *		not printed by default.
  * 
- * All other characters from fmt except the formatting directives
- * are printed in verbatim.
+ * All other characters from fmt except the formatting directives are printed in
+ * verbatim.
  *
  * @param fmt Formatting NULL terminated string.
@@ -432,13 +451,17 @@
 int printf_core(const char *fmt, struct printf_spec *ps, va_list ap)
 {
-	int i = 0, j = 0; /* i is index of currently processed char from fmt, j is index to the first not printed nonformating character */
+	/* i is the index of the currently processed char from fmt */
+	int i = 0;
+	/* j is the index to the first not printed nonformating character */
+	int j = 0;
+
 	int end;
-	int counter; /* counter of printed characters */
-	int retval; /* used to store return values from called functions */
+	int counter;	/* counter of printed characters */
+	int retval;	/* used to store return values from called functions */
 	char c;
 	qualifier_t qualifier;	/* type of argument */
-	int base;	/* base in which will be parameter (numbers only) printed */
+	int base;	/* base in which will be a numeric parameter printed */
 	uint64_t number; /* argument value */
-	size_t	size; /* byte size of integer parameter */
+	size_t	size;	/* byte size of integer parameter */
 	int width, precision;
 	uint64_t flags;
@@ -451,5 +474,6 @@
 			/* print common characters if any processed */	
 			if (i > j) {
-				if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) < 0) { /* error */
+				if ((retval = printf_putnchars(&fmt[j],
+				    (size_t)(i - j), ps)) < 0) { /* error */
 					goto minus_out;
 				}
@@ -465,10 +489,21 @@
 				++i;
 				switch (c = fmt[i]) {
-				case '#': flags |= __PRINTF_FLAG_PREFIX; break;
-				case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break;
-				case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break;
-				case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break;
-				case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break;
-				default: end = 1;
+				case '#':
+					flags |= __PRINTF_FLAG_PREFIX;
+					break;
+				case '-':
+					flags |= __PRINTF_FLAG_LEFTALIGNED;
+					break;
+				case '+':
+					flags |= __PRINTF_FLAG_SHOWPLUS;
+					break;
+				case ' ':
+					flags |= __PRINTF_FLAG_SPACESIGN;
+					break;
+				case '0':
+					flags |= __PRINTF_FLAG_ZEROPADDED;
+					break;
+				default:
+					end = 1;
 				};	
 				
@@ -487,5 +522,5 @@
 				width = (int)va_arg(ap, int);
 				if (width < 0) {
-					/* negative width means to set '-' flag */
+					/* negative width sets '-' flag */
 					width *= -1;
 					flags |= __PRINTF_FLAG_LEFTALIGNED;
@@ -503,9 +538,9 @@
 					}
 				} else if (fmt[i] == '*') {
-					/* get precision value from argument list*/
+					/* get precision value from argument */
 					i++;
 					precision = (int)va_arg(ap, int);
 					if (precision < 0) {
-						/* negative precision means to ignore it */
+						/* negative precision ignored */
 						precision = 0;
 					}
@@ -514,5 +549,5 @@
 
 			switch (fmt[i++]) {
-			/** TODO: unimplemented qualifiers:
+			/** @todo unimplemented qualifiers:
 			 * t ptrdiff_t - ISO C 99
 			 */
@@ -535,5 +570,6 @@
 				break;
 			default:
-				qualifier = PrintfQualifierInt; /* default type */
+				/* set default type */
+				qualifier = PrintfQualifierInt;
 				--i;
 			}	
@@ -543,9 +579,10 @@
 			switch (c = fmt[i]) {
 
-				/*
-				* String and character conversions.
-				*/
+			/*
+			 * String and character conversions.
+			 */
 			case 's':
-				if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) {
+				if ((retval = print_string(va_arg(ap, char*),
+				    width, precision, flags, ps)) < 0) {
 					goto minus_out;
 				}
@@ -556,5 +593,6 @@
 			case 'c':
 				c = va_arg(ap, unsigned int);
-				if ((retval = print_char(c, width, flags, ps)) < 0) {
+				retval = print_char(c, width, flags, ps);
+				if (retval < 0) {
 					goto minus_out;
 				}
@@ -566,5 +604,5 @@
 			/* 
 			 * Integer values
-			*/
+			 */
 			case 'P': /* pointer */
 			       	flags |= __PRINTF_FLAG_BIGCHARS;
@@ -595,10 +633,11 @@
 				goto next_char;
 			/*
-			* Bad formatting.
-			*/
+			 * Bad formatting.
+			 */
 			default:
-				/* Unknown format
-				 *  now, the j is index of '%' so we will
-				 * print whole bad format sequence
+				/*
+				 * Unknown format. Now, j is the index of '%',
+				 * so we will print the whole bad format
+				 * sequence.
 				 */
 				goto next_char;		
@@ -606,6 +645,5 @@
 		
 		
-		/* Print integers */
-			/* print number */
+			/* Print integers */
 			switch (qualifier) {
 			case PrintfQualifierByte:
@@ -627,9 +665,11 @@
 			case PrintfQualifierLongLong:
 				size = sizeof(unsigned long long);
-				number = (uint64_t)va_arg(ap, unsigned long long);
+				number = (uint64_t)va_arg(ap,
+				    unsigned long long);
 				break;
 			case PrintfQualifierPointer:
 				size = sizeof(void *);
-				number = (uint64_t)(unsigned long)va_arg(ap, void *);
+				number = (uint64_t)(unsigned long)va_arg(ap,
+				    void *);
 				break;
 			case PrintfQualifierSizeT:
@@ -643,5 +683,5 @@
 			
 			if (flags & __PRINTF_FLAG_SIGNED) {
-				if (number & (0x1 << (size*8 - 1))) {
+				if (number & (0x1 << (size * 8 - 1))) {
 					flags |= __PRINTF_FLAG_NEGATIVE;
 				
@@ -650,5 +690,7 @@
 					} else {
 						number = ~number;
-						number &= (~((0xFFFFFFFFFFFFFFFFll) <<  (size * 8)));
+						number &=
+						    ~(0xFFFFFFFFFFFFFFFFll <<
+						    (size * 8));
 						number++;
 					}
@@ -656,7 +698,8 @@
 			}
 
-			if ((retval = print_number(number, width, precision, base, flags, ps)) < 0 ) {
+			if ((retval = print_number(number, width, precision,
+			    base, flags, ps)) < 0 ) {
 				goto minus_out;
-			};
+			}
 
 			counter += retval;
@@ -669,5 +712,6 @@
 	
 	if (i > j) {
-		if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) < 0) { /* error */
+		retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps);
+		if (retval < 0) { /* error */
 			goto minus_out;
 		}
