Index: generic/src/printf/printf_core.c
===================================================================
--- generic/src/printf/printf_core.c	(revision 3247f0af2a8915aaac2c08a845d7a8f83bbeb28a)
+++ generic/src/printf/printf_core.c	(revision 4ddeace5764cff68ff26f294be7ead55e4d70796)
@@ -101,13 +101,9 @@
  * @param count 
  * @param ps output method and its data
- * @return 0 on success, EOF on fail
+ * @return number or printed characters
  */
 static int printf_putnchars(const char * buf, size_t count, struct printf_spec *ps)
 {
-	if (ps->write((void *)buf, count, ps->data) == count) {
-		return 0;
-	}
-	
-	return EOF;
+	return ps->write((void *)buf, count, ps->data);
 }
 
@@ -115,5 +111,5 @@
  * @param str string to print
  * @param ps write function specification and support data
- * @return 0 on success or EOF on fail
+ * @return number or printed characters
  */
 static int printf_putstr(const char * str, struct printf_spec *ps)
@@ -127,9 +123,5 @@
 	count = strlen(str);
 
-	if (ps->write((void *) str, count, ps->data) == count) {
-		return 0;
-	}
-	
-	return EOF;
+	return ps->write((void *) str, count, ps->data);
 }
 
@@ -137,5 +129,5 @@
  * @param c one character
  * @param ps output method
- * @return printed character or EOF
+ * @return number or printed characters
  */
 static int printf_putchar(int c, struct printf_spec *ps)
@@ -143,9 +135,5 @@
 	unsigned char ch = c;
 	
-	if (ps->write((void *) &ch, 1, ps->data) == 1) {
-		return c;
-	}
-	
-	return EOF;
+	return ps->write((void *) &ch, 1, ps->data);
 }
 
@@ -154,5 +142,5 @@
  * @param width 
  * @param flags
- * @return number of printed characters or EOF
+ * @return number of printed characters, negative value on fail
  */
 static int print_char(char c, int width, __u64 flags, struct printf_spec *ps)
@@ -163,16 +151,15 @@
 		while (--width > 0) { 	/* one space is consumed by character itself hence predecrement */
 			/* FIXME: painful slow */
-			printf_putchar(' ', ps);	
+			if (printf_putchar(' ', ps) > 0)	
+				++counter;
+		}
+	}
+	
+ 	if (printf_putchar(c, ps) > 0)
+		counter++;
+
+	while (--width > 0) { /* one space is consumed by character itself hence predecrement */
+		if (printf_putchar(' ', ps) > 0)
 			++counter;
-		}
-	}
-	
- 	if (printf_putchar(c, ps) == EOF) {
-		return EOF;
-	}
-
-	while (--width > 0) { /* one space is consumed by character itself hence predecrement */
-		printf_putchar(' ', ps);
-		++counter;
 	}
 	
@@ -185,5 +172,5 @@
  * @param precision
  * @param flags
- * @return number of printed characters or EOF
+ * @return number of printed characters or negative value on fail
  */
 						
@@ -192,4 +179,5 @@
 	int counter = 0;
 	size_t size;
+	int retval;
 
 	if (s == NULL) {
@@ -208,6 +196,6 @@
 	if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
 		while (width-- > 0) { 	
-			printf_putchar(' ', ps);	
-			counter++;
+			if (printf_putchar(' ', ps) == 1)	
+				counter++;
 		}
 	}
@@ -215,20 +203,19 @@
 	while (precision > size) {
 		precision--;
-		printf_putchar(' ', ps);	
-		++counter;
-	}
-	
- 	if (printf_putnchars(s, precision, ps) == EOF) {
-		return EOF;
-	}
-
-	counter += precision;
+		if (printf_putchar(' ', ps) == 1)	
+			++counter;
+	}
+	
+ 	if ((retval = printf_putnchars(s, precision, ps)) < 0) {
+		return -counter;
+	}
+	counter += retval;	
 
 	while (width-- > 0) {
-		printf_putchar(' ', ps);	
-		++counter;
-	}
-	
-	return ++counter;
+		if (printf_putchar(' ', ps) == 1)	
+			++counter;
+	}
+	
+	return counter;
 }
 
@@ -255,6 +242,7 @@
 	int size = 0; /* size of number with all prefixes and signs */
 	int number_size; /* size of plain number */
-	int written = 0;
 	char sgn;
+	int retval;
+	int counter = 0;
 	
 	if (flags & __PRINTF_FLAG_BIGCHARS) 
@@ -323,13 +311,14 @@
 	if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
 		while (width-- > 0) { 	
-			printf_putchar(' ', ps);	
-			written++;
+			if (printf_putchar(' ', ps) == 1)	
+				counter++;
 		}
 	}
+	
 	
 	/* print sign */
 	if (sgn) {
-		printf_putchar(sgn, ps);
-		written++;
+		if (printf_putchar(sgn, ps) == 1)
+			counter++;
 	}
 	
@@ -339,24 +328,28 @@
 		switch(base) {
 			case 2:	/* Binary formating is not standard, but usefull */
-				printf_putchar('0', ps);
+				if (printf_putchar('0', ps) == 1)
+					counter++;
 				if (flags & __PRINTF_FLAG_BIGCHARS) {
-					printf_putchar('B', ps);
+					if (printf_putchar('B', ps) == 1)
+						counter++;
 				} else {
-					printf_putchar('b', ps);
+					if (printf_putchar('b', ps) == 1)
+						counter++;
 				}
-				written += 2;
 				break;
 			case 8:
-				printf_putchar('o', ps);
-				written++;
+				if (printf_putchar('o', ps) == 1)
+					counter++;
 				break;
 			case 16:
-				printf_putchar('0', ps);
+				if (printf_putchar('0', ps) == 1)
+					counter++;
 				if (flags & __PRINTF_FLAG_BIGCHARS) {
-					printf_putchar('X', ps);
+					if (printf_putchar('X', ps) == 1)
+						counter++;
 				} else {
-					printf_putchar('x', ps);
+					if (printf_putchar('x', ps) == 1)
+						counter++;
 				}
-				written += 2;
 				break;
 		}
@@ -366,6 +359,6 @@
 	precision -= number_size;
 	while (precision-- > 0) { 	
-		printf_putchar('0', ps);	
-		written++;
+		if (printf_putchar('0', ps) == 1)
+			counter++;
 	}
 
@@ -373,14 +366,16 @@
 	/* print number itself */
 
-	written += printf_putstr(++ptr, ps);
+	if ((retval = printf_putstr(++ptr, ps)) > 0) {
+		counter += retval;
+	}
 	
 	/* print ending spaces */
 	
 	while (width-- > 0) { 	
-		printf_putchar(' ', ps);	
-		written++;
-	}
-
-	return written;
+		if (printf_putchar(' ', ps) == 1)	
+			counter++;
+	}
+
+	return counter;
 }
 
@@ -485,5 +480,5 @@
 			/* print common characters if any processed */	
 			if (i > j) {
-				if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) == EOF) { /* error */
+				if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) < 0) { /* error */
 					counter = -counter;
 					goto out;
@@ -582,5 +577,5 @@
 				*/
 				case 's':
-					if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) == EOF) {
+					if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) {
 						counter = -counter;
 						goto out;
@@ -592,5 +587,5 @@
 				case 'c':
 					c = va_arg(ap, unsigned int);
-					if ((retval = print_char(c, width, flags, ps)) == EOF) {
+					if ((retval = print_char(c, width, flags, ps)) < 0) {
 						counter = -counter;
 						goto out;
@@ -693,5 +688,5 @@
 			}
 
-			if ((retval = print_number(number, width, precision, base, flags, ps)) == EOF ) {
+			if ((retval = print_number(number, width, precision, base, flags, ps)) < 0) {
 				counter = -counter;
 				goto out;
@@ -707,5 +702,5 @@
 	
 	if (i > j) {
-		if ((retval = printf_putnchars(&fmt[j], (__native)(i - j), ps)) == EOF) { /* error */
+		if ((retval = printf_putnchars(&fmt[j], (__native)(i - j), ps)) < 0) { /* error */
 			counter = -counter;
 			goto out;
Index: generic/src/printf/vsnprintf.c
===================================================================
--- generic/src/printf/vsnprintf.c	(revision 3247f0af2a8915aaac2c08a845d7a8f83bbeb28a)
+++ generic/src/printf/vsnprintf.c	(revision 4ddeace5764cff68ff26f294be7ead55e4d70796)
@@ -51,29 +51,32 @@
 int vsnprintf_write(const char *str, size_t count, struct vsnprintf_data *data)
 {
-	size_t i,j;
+	size_t i;
 	i = data->size - data->len;
-	j = count;
 
-	if (i > 0) {
-		if (i <= j) { 
-			if (i == 1) {
-				/* We have only one free byte left in buffer => write there trailing zero */
-				data->string[data->size - 1] = 0;
-				data->len = data->size;
-			} else {
-				/* We have not enought space for whole string with the trailing zero => print only a part of string */
-				memcpy((void *)(data->string + data->len), (void *)str, i - 1);
-				data->string[data->size - 1] = 0;
-				data->len = data->size;
-			}
-		} else {
-			/* Buffer is big enought to print whole string */
-			memcpy((void *)(data->string + data->len), (void *)str, j);
-			data->len += j;
-			/* Put trailing zero at end, but not count it into data->len so it could be rewritten next time */
-			data->string[data->len] = 0;
-		}
+	if ((count == 0) || (i == 0)) {
+		return 0;
 	}
 	
+	if (i == 1) {
+		/* We have only one free byte left in buffer => write there trailing zero */
+		data->string[data->size - 1] = 0;
+		data->len = data->size;
+		return 1;
+	}
+	
+	if (i <= count) {
+		/* We have not enought space for whole string with the trailing zero => print only a part of string */
+			memcpy((void *)(data->string + data->len), (void *)str, i - 1);
+			data->string[data->size - 1] = 0;
+			data->len = data->size;
+			return i;
+	}
+	
+	/* Buffer is big enought to print whole string */
+	memcpy((void *)(data->string + data->len), (void *)str, count);
+	data->len += count;
+	/* Put trailing zero at end, but not count it into data->len so it could be rewritten next time */
+	data->string[data->len] = 0;
+
 	return count;	
 }
Index: test/print/print1/test.c
===================================================================
--- test/print/print1/test.c	(revision 3247f0af2a8915aaac2c08a845d7a8f83bbeb28a)
+++ test/print/print1/test.c	(revision 4ddeace5764cff68ff26f294be7ead55e4d70796)
@@ -33,7 +33,8 @@
 void test(void)
 {
+	int retval;
 	__native nat = 0x12345678u;
 	
-	unsigned char buffer[BUFFER_SIZE];
+	char buffer[BUFFER_SIZE];
 	
 	printf(" Printf test \n");
@@ -53,11 +54,17 @@
 	printf(" Print to NULL '%s'\n",NULL);
 
+	retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters.");
+	printf("Result is: '%s', retval = %d\n", buffer, retval);
+
+	retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters.");
+	printf("Result is: '%s', retval = %d\n", buffer, retval);
+	
 	printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE);
-	snprintf(buffer, BUFFER_SIZE, "Short %s", "text");
-	printf("Result is: '%s'\n", buffer);
+	retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text");
+	printf("Result is: '%s', retval = %d\n", buffer, retval);
 	
 	printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE);
-	snprintf(buffer, BUFFER_SIZE, "Very long %s. This text`s length is more than %d. We are interested in the result.", "text" , BUFFER_SIZE);
-	printf("Result is: '%s'\n", buffer);
+	retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text`s length is more than %d. We are interested in the result.", "text" , BUFFER_SIZE);
+	printf("Result is: '%s', retval = %d\n", buffer, retval);
 	
 	return;
