Browse Source

libcompat: Use the return value from vfprintf instead of fstat

Guillem Jover 18 years ago
parent
commit
66cac9c364
2 changed files with 10 additions and 8 deletions
  1. 6 0
      ChangeLog
  2. 4 8
      libcompat/vsnprintf.c

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2008-09-14  Guillem Jover  <guillem@debian.org>
+
+	* libcompat/vsnprintf.c (vsnprintf): Use the return value from
+	vfprintf as the formatted string size instead of using fstat to get
+	the file size.
+
 2008-09-14  Guillem Jover  <guillem@debian.org>
 
 	* libcompat/vsnprintf.c (vsnprintf): Check for negative return error

+ 4 - 8
libcompat/vsnprintf.c

@@ -20,8 +20,6 @@
 
 #include <config.h>
 
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -32,9 +30,8 @@ vsnprintf(char *buf, size_t maxsize, const char *fmt, va_list al)
 {
 	static FILE *file = NULL;
 
-	struct stat stab;
 	unsigned long want, nr;
-	int retval;
+	int total, retval;
 
 	if (maxsize == 0)
 		return -1;
@@ -50,16 +47,15 @@ vsnprintf(char *buf, size_t maxsize, const char *fmt, va_list al)
 			return -1;
 	}
 
-	if (vfprintf(file, fmt, al) < 0)
+	total = vfprintf(file, fmt, al);
+	if (total < 0)
 		return -1;
 	if (fflush(file))
 		return -1;
-	if (fstat(fileno(file), &stab))
-		return -1;
 	if (fseek(file, 0, 0))
 		return -1;
 
-	want = stab.st_size;
+	want = total;
 	if (want >= maxsize) {
 		want = maxsize - 1;
 		retval = -1;