3 extern int at91_dbgu_putc(int ch
);
5 FILE *stdout
= (FILE *)0;
6 FILE *stdin
= (FILE *)0;
8 FILE __filedesc
[FILEDESCS
];
10 FILE *fopen(int (*put
)(int), int (*get
)())
16 for(int i
= 0; i
< FILEDESCS
; i
++)
18 __filedesc
[i
].active
= false;
19 __filedesc
[i
].put
= 0;
20 __filedesc
[i
].get
= 0;
26 for(int i
= 0; i
< FILEDESCS
; i
++)
28 if(!__filedesc
[i
].active
)
30 __filedesc
[i
].put
= put
;
31 __filedesc
[i
].get
= get
;
33 __filedesc
[i
].active
= true;
35 return &__filedesc
[i
];
44 for(int i
= 0; i
< FILEDESCS
; i
++)
45 if(&__filedesc
[i
] == fp
|| fp
->active
)
58 int fputs(const char *str
, FILE *fp
)
63 if(fp
->put
== (void *)0)
74 int fputc(int c
, FILE *fp
)
79 if(fp
->put
== (void *)0)
90 if(fp
->get
== (void *)0)
97 int puts(const char *str
)
99 return fputs(str
, stdout
);
104 return fputc(c
, stdout
);
109 return fputc(c
, stdout
);
117 int strlen(const char *str
)
130 #define ZEROPAD 1 /* pad with zero */
131 #define SIGN 2 /* unsigned/signed long */
132 #define LEFT 4 /* left justified */
133 #define LARGE 8 /* use 'ABCDEF' instead of 'abcdef' */
135 #define do_div(n,base) ({ \
137 __res = ((unsigned) n) % (unsigned) base; \
138 n = ((unsigned) n) / (unsigned) base; \
142 int number(FILE *fp
, int num
, int base
, int size
, int precision
, int type
)
144 char c
, sign
, tmp
[66];
145 const char *digits
="0123456789abcdef";
149 digits
= "0123456789ABCDEF";
152 if (base
< 2 || base
> 16)
154 c
= (type
& ZEROPAD
) ? '0' : ' ';
157 if(type
& SIGN
&& num
< 0)
166 tmp
[i
++] = digits
[0];
168 tmp
[i
++] = digits
[do_div(num
, base
)];
174 if(!(type
&(ZEROPAD
+LEFT
)))
185 while (i
< precision
--)
197 int vfprintf(FILE *fp
, const char *fmt
, va_list va
)
227 precision
= precision
* 10 + (*fmt
- '0');
232 s
= va_arg(va
, char *);
240 fputc(va_arg(va
, int), fp
);
244 number(fp
, va_arg(va
, int), 10, 0, precision
, type
);
248 number(fp
, va_arg(va
, int), 16, 0, precision
, type
);
252 number(fp
, va_arg(va
, int), 16, 0, precision
, type
| LARGE
);
277 int fprintf(FILE *fp
, const char *fmt
, ...)
283 i
= fprintf(fp
, fmt
, ap
);
289 int printf(const char *fmt
, ...)
295 i
= vfprintf(stdout
, fmt
, ap
);