home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / pippy-0.6beta-src.tar.gz / pippy-0.6beta-src.tar / pippy-0.6beta-src / src / Palm / libc / mystdio.c < prev    next >
C/C++ Source or Header  |  2000-12-21  |  1KB  |  83 lines

  1.  
  2. #include "io.h"
  3. #include <stdio.h>
  4. #include "libc_segments.h"
  5.  
  6. #define BUF_LEN 33
  7. static char put_buf[BUF_LEN]; /* roughly one line */
  8. static UInt16 buf_pos = 0;
  9.  
  10. static int flush_buf() {
  11.     if (buf_pos > 0) {
  12.         ioPutS(put_buf);
  13.         buf_pos = 0;
  14.     }
  15.     return 0;
  16. }
  17. int puts(unsigned char *s) {
  18.     flush_buf();
  19.     ioPutS(s);
  20.     return 0;
  21. }
  22.  
  23. int putchar (unsigned int x) {
  24.     if (buf_pos == 0)
  25.         MemSet (put_buf, BUF_LEN, '\0');
  26.     
  27.     put_buf[buf_pos++] = x;
  28.  
  29.     /* flush on \n character or when BUF_LEN-1 (keep last \0 for
  30.        end-of-string indication) is reached */
  31.     if (x == '\n' || buf_pos == BUF_LEN-1) {
  32.         ioPutS(put_buf);
  33.         buf_pos = 0;
  34.     }
  35.  
  36.     return 0;
  37. }
  38.  
  39. int printf(const char *fmt, ...)
  40. {
  41.     va_list args;
  42.     int i;
  43.     char buf[500];
  44.  
  45.     va_start(args, fmt);
  46.     i=vsprintf(buf,fmt,args);
  47.     va_end(args);
  48.  
  49.     flush_buf();
  50.     ioPutS(buf);
  51.  
  52.     return i;
  53. }
  54.  
  55. int fprintf(FILE* f, const char *fmt, ...)
  56. {
  57.     va_list args;
  58.     int i;
  59.     char buf[500];
  60.  
  61.     va_start(args, fmt);
  62.     i=vsprintf(buf,fmt,args);
  63.     va_end(args);
  64.     
  65.     flush_buf();
  66.     ioPutS(buf);
  67.  
  68.     return i;
  69. }
  70.  
  71. int vfprintf(FILE *stream, const char *fmt, va_list ap)
  72. {
  73.     char buf[500];
  74.     int i;
  75.  
  76.     i=vsprintf(buf,fmt,ap);
  77.  
  78.     flush_buf();
  79.     ioPutS(buf);
  80.  
  81.     return i;
  82. }
  83.