Index: uspace/lib/c/generic/stdio/scanf.c
===================================================================
--- uspace/lib/c/generic/stdio/scanf.c	(revision 80f345c2d6df8e54090633e7132fcb9939f93150)
+++ uspace/lib/c/generic/stdio/scanf.c	(revision 0d83cf6f04f9a3bfef021c71a4d4e0c172f9ad79)
@@ -46,4 +46,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+
+#include "../private/scanf.h"
 
 typedef enum {
@@ -348,5 +350,5 @@
  * @return EOK on success, ENOMEM if out of memory
  */
-static int strbuf_init(strbuf_t *strbuf, cvtspec_t *spec, va_encaps_t *va)
+static errno_t strbuf_init(strbuf_t *strbuf, cvtspec_t *spec, va_encaps_t *va)
 {
 	if (spec->noassign) {
@@ -393,5 +395,5 @@
  * @return EOK on sucess, ENOMEM if out of memory
  */
-static int strbuf_write(strbuf_t *strbuf, size_t idx, char c)
+static errno_t strbuf_write(strbuf_t *strbuf, size_t idx, char c)
 {
 	if (strbuf->memalloc && idx >= strbuf->size) {
@@ -449,5 +451,5 @@
 
 /* Skip whitespace in input stream */
-static int vfscanf_skip_ws(FILE *f, int *numchar)
+static errno_t vfscanf_skip_ws(FILE *f, int *numchar)
 {
 	int c;
@@ -471,7 +473,7 @@
 
 /* Match whitespace. */
-static int vfscanf_match_ws(FILE *f, int *numchar, const char **fmt)
-{
-	int rc;
+static errno_t vfscanf_match_ws(FILE *f, int *numchar, const char **fmt)
+{
+	errno_t rc;
 
 	rc = vfscanf_skip_ws(f, numchar);
@@ -492,11 +494,16 @@
  * @return EOK on success, EIO on I/O error, EINVAL if input is not valid
  */
-static int __fstrtoimax(FILE *f, int *numchar, int base, size_t width,
+static errno_t __fstrtoimax(FILE *f, int *numchar, int base, size_t width,
     intmax_t *dest)
 {
+	errno_t rc;
 	int c;
 	intmax_t v;
 	int digit;
 	int sign;
+
+	rc = vfscanf_skip_ws(f, numchar);
+	if (rc == EIO)
+		return EIO;
 
 	c = __fgetc(f, numchar);
@@ -579,10 +586,15 @@
  * @return EOK on success, EIO on I/O error, EINVAL if input is not valid
  */
-static int __fstrtoumax(FILE *f, int *numchar, int base, size_t width,
+static errno_t __fstrtoumax(FILE *f, int *numchar, int base, size_t width,
     uintmax_t *dest)
 {
+	errno_t rc;
 	int c;
 	uintmax_t v;
 	int digit;
+
+	rc = vfscanf_skip_ws(f, numchar);
+	if (rc == EIO)
+		return EIO;
 
 	c = __fgetc(f, numchar);
@@ -653,6 +665,8 @@
  * @return EOK on success, EIO on I/O error, EINVAL if input is not valid
  */
-static int __fstrtold(FILE *f, int *numchar, size_t width, long double *dest)
-{
+errno_t __fstrtold(FILE *f, int *numchar, size_t width,
+    long double *dest)
+{
+	errno_t rc;
 	int c;
 	long double v;
@@ -665,4 +679,8 @@
 	int exp;
 	int expsign;
+
+	rc = vfscanf_skip_ws(f, numchar);
+	if (rc == EIO)
+		return EIO;
 
 	c = __fgetc(f, numchar);
@@ -823,11 +841,12 @@
 
 /* Read characters from stream */
-static int __fgetchars(FILE *f, int *numchar, size_t width, strbuf_t *strbuf,
-    size_t *nread)
+static errno_t __fgetchars(FILE *f, int *numchar, size_t width,
+    strbuf_t *strbuf, size_t *nread)
 {
 	size_t cnt;
 	int c;
-	int rc;
-
+	errno_t rc;
+
+	*nread = 0;
 	for (cnt = 0; cnt < width; cnt++) {
 		c = __fgetc(f, numchar);
@@ -849,11 +868,17 @@
 
 /* Read non-whitespace string from stream */
-static int __fgetstr(FILE *f, int *numchar, size_t width, strbuf_t *strbuf,
+static errno_t __fgetstr(FILE *f, int *numchar, size_t width, strbuf_t *strbuf,
     size_t *nread)
 {
 	size_t cnt;
 	int c;
-	int rc;
-	int rc2;
+	errno_t rc;
+	errno_t rc2;
+
+	*nread = 0;
+
+	rc = vfscanf_skip_ws(f, numchar);
+	if (rc == EIO)
+		return EIO;
 
 	rc = EOK;
@@ -949,11 +974,11 @@
 
 /* Read string of characters from scanset from stream */
-static int __fgetscanstr(FILE *f, int *numchar, size_t width,
+static errno_t __fgetscanstr(FILE *f, int *numchar, size_t width,
     const char *scanset, strbuf_t *strbuf, size_t *nread)
 {
 	size_t cnt;
 	int c;
-	int rc;
-	int rc2;
+	errno_t rc;
+	errno_t rc2;
 
 	rc = EOK;
@@ -990,8 +1015,8 @@
 
 /** Perform a single conversion. */
-static int vfscanf_cvt(FILE *f, const char **fmt, va_encaps_t *va,
+static errno_t vfscanf_cvt(FILE *f, const char **fmt, va_encaps_t *va,
     int *numchar, unsigned *ncvt)
 {
-	int rc;
+	errno_t rc;
 	int c;
 	intmax_t ival;
@@ -1027,14 +1052,4 @@
 	cvtspec_parse(fmt, &cvtspec);
 
-	if (cvtspec.spcr != cs_set && cvtspec.spcr != cs_char &&
-	    cvtspec.spcr != cs_numchar) {
-		/* Skip whitespace */
-		rc = vfscanf_skip_ws(f, numchar);
-		if (rc == EIO)
-			return EIO;
-
-		assert(rc == EOK);
-	}
-
 	width = cvtspec.have_width ? cvtspec.width : SIZE_MAX;
 
@@ -1042,4 +1057,8 @@
 	case cs_percent:
 		/* Match % character */
+		rc = vfscanf_skip_ws(f, numchar);
+		if (rc == EOF)
+			return EIO;
+
 		c = __fgetc(f, numchar);
 		if (c == EOF)
