*/
#include <stdarg.h>
-#include <stddef.h>
-#include <stdio.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++;
/* 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;
} else {
int t = 0;
char w = '0';
- size_t i, sz = 0;
+ int i, sz = 0;
void *p = NULL;
/* stamp */
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 {
va_end (ap);
/* output string */
- size_t n = str - buffer;
- if (n < sizeof (buffer) - 1) {
- fwrite (buffer, n, 1, fid);
- return n;
+ int n = str - buffer;
+ if (n < (int)sizeof (buffer) - 1) {
+ return write (fd, buffer, n);
}
return 0;
}