remove stdout/stderr calls
[compress.git] / fprintf.c
index 6d60b82daa63e15fe64b665675674c1c888967f5..7b3b097b753cdb4828d73676ff5105cda5b7d8f6 100644 (file)
--- a/fprintf.c
+++ b/fprintf.c
@@ -11,9 +11,9 @@
   - initial version
 */
 
+#include <fcntl.h>
 #include <stdarg.h>
-#include <stddef.h>
-#include <stdio.h>
+#include <unistd.h>
 
 inline unsigned int nextpow (unsigned int x, int base) {
     unsigned int n = 0;
@@ -26,7 +26,7 @@ inline unsigned int nextpow (unsigned int x, int base) {
 
 /* simple fprintf function */
 
-size_t myfprintf (FILE *fid, const char *fmt, ...)
+int fdprintf (int fd, const char *fmt, ...)
 {
     char buffer[1024 + 1] = { 0 };
     char *str = buffer;
@@ -45,7 +45,7 @@ size_t myfprintf (FILE *fid, const char *fmt, ...)
         } else {
             int t = 0;
                char w = '0';
-            size_t i, sz = 0;
+            int i, sz = 0;
             void *p = NULL;
 
             /* stamp */
@@ -118,9 +118,9 @@ size_t myfprintf (FILE *fid, const char *fmt, ...)
     va_end (ap);
 
     /* output string */
-    size_t n = str - buffer;
-    if (n < sizeof (buffer) - 1) {
-        fwrite (buffer, n, 1, fid);
+    int n = str - buffer;
+    if (n < (int)sizeof (buffer) - 1) {
+        write (fd, buffer, n);
         return n;
     }
     return 0;