size optimization
[compress.git] / fprintf.c
index 7b3b097b753cdb4828d73676ff5105cda5b7d8f6..ff4f0353d1f947cd79e4bbba8690d0254efb3976 100644 (file)
--- a/fprintf.c
+++ b/fprintf.c
   - initial version
 */
 
-#include <fcntl.h>
 #include <stdarg.h>
+#include <stdint.h>
 #include <unistd.h>
 
-inline unsigned int nextpow (unsigned int x, int base) {
+#include "fprintf.h"
+
+int _fdout = STDOUT_FILENO;
+int _fderr = STDERR_FILENO;
+
+unsigned int nextpow (unsigned int x, int base) {
     unsigned int n = 0;
     while (x) {
         n++;
@@ -90,13 +95,14 @@ int fdprintf (int fd, const char *fmt, ...)
             case 'x': /* integer hexa */
                 if (!p) {
                     u = va_arg (ap, unsigned int);
-                    p = (void *)u;
                     if (sz == 0) {
                         sz = nextpow (u, 16);
                     }
+                } else {
+                    u = (uintptr_t)p;
                 }
                 for (i = sz, t = 1; i > 0; i--) {
-                    char x = (char)(((uintptr_t)p >> (i * 4 - 4)) & 0xf);
+                    char x = (char)((u >> (i * 4 - 4)) & 0xf);
                     if ((t == 1) && (x == 0)) {
                         *str++ = w;
                     } else {
@@ -120,8 +126,7 @@ int fdprintf (int fd, const char *fmt, ...)
     /* output string */
     int n = str - buffer;
     if (n < (int)sizeof (buffer) - 1) {
-        write (fd, buffer, n);
-        return n;
+        return write (fd, buffer, n);
     }
     return 0;
 }