Subversion Repositories Kolibri OS

Rev

Rev 1604 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. #include <types.h>
  3. #include <syscall.h>
  4.  
  5. #pragma pack(push, 1)
  6. typedef struct
  7. {
  8.   char sec;
  9.   char min;
  10.   char hour;
  11.   char rsv;
  12. }detime_t;
  13.  
  14. typedef struct
  15. {
  16.   char  day;
  17.   char  month;
  18.   short year;
  19. }dedate_t;
  20.  
  21. typedef struct
  22. {
  23.   unsigned    attr;
  24.   unsigned    flags;
  25.   union
  26.   {
  27.      detime_t  ctime;
  28.      unsigned  cr_time;
  29.   };
  30.   union
  31.   {
  32.      dedate_t  cdate;
  33.      unsigned  cr_date;
  34.   };
  35.   union
  36.   {
  37.      detime_t  atime;
  38.      unsigned  acc_time;
  39.   };
  40.   union
  41.   {
  42.      dedate_t  adate;
  43.      unsigned  acc_date;
  44.   };
  45.   union
  46.   {
  47.      detime_t  mtime;
  48.      unsigned  mod_time;
  49.   };
  50.   union
  51.   {
  52.      dedate_t  mdate;
  53.      unsigned  mod_date;
  54.   };
  55.   unsigned    size;
  56.   unsigned    size_high;
  57. } FILEINFO;
  58.  
  59. #pragma pack(pop)
  60.  
  61. typedef struct
  62. {
  63.   char *path;
  64.   int  offset;
  65. } dbgfile_t;
  66.  
  67. static dbgfile_t dbgfile;
  68.  
  69. #define va_start(v,l)   __builtin_va_start(v,l)
  70. #define va_end(v)       __builtin_va_end(v)
  71. #define va_arg(v,l)     __builtin_va_arg(v,l)
  72. #define __va_copy(d,s)  __builtin_va_copy(d,s)
  73.  
  74. typedef __builtin_va_list __gnuc_va_list;
  75. typedef __gnuc_va_list    va_list;
  76.  
  77. #define arg(x) va_arg (ap, u32_t)
  78.  
  79. int dbg_open(char *path)
  80. {
  81.     FILEINFO info;
  82.  
  83.     dbgfile.offset = 0;
  84.  
  85.     if(get_fileinfo(path,&info))
  86.     {
  87.         if(!create_file(path))
  88.         {
  89.             dbgfile.path = path;
  90.             return true;
  91.         }
  92.         else return false;
  93.     };
  94.     set_file_size(path, 0);
  95.     dbgfile.path   = path;
  96.     dbgfile.offset = 0;
  97.     return true;
  98. };
  99.  
  100. int vsnprintf(char *s, size_t n, const char *format, va_list arg);
  101.  
  102. int printf(const char* format, ...)
  103. {
  104.     char  txtbuf[256];
  105.     int   len = 0;
  106.  
  107.     va_list ap;
  108.  
  109.     va_start(ap, format);
  110.     if (format)
  111.         len = vsnprintf(txtbuf, 256, format, ap);
  112.     va_end(ap);
  113.  
  114.     if( len )
  115.         SysMsgBoardStr(txtbuf);
  116.  
  117.     return len;
  118. }
  119.  
  120.  
  121. int dbgprintf(const char* format, ...)
  122. {
  123.     char      txtbuf[256];
  124.     unsigned  writes;
  125.     int       len = 0;
  126.  
  127.     va_list   ap;
  128.  
  129.     va_start(ap, format);
  130.     if (format)
  131.       len = vsnprintf(txtbuf, 256, format, ap);
  132.     va_end(ap);
  133.  
  134.     if( len )
  135.     {
  136.         SysMsgBoardStr(txtbuf);
  137.  
  138.         if(dbgfile.path)
  139.         {
  140.             write_file(dbgfile.path,txtbuf,dbgfile.offset,len,&writes);
  141.             dbgfile.offset+=writes;
  142.         };
  143.     };
  144.     return len;
  145. }
  146.  
  147. int xf86DrvMsg(int skip, int code, const char* format, ...)
  148. {
  149.     char      txtbuf[256];
  150.     unsigned  writes;
  151.     va_list   ap;
  152.  
  153.     int       len = 0;
  154.  
  155.     va_start(ap, format);
  156.     if (format)
  157.         len = vsnprintf(txtbuf, 256, format, ap);
  158.     va_end(ap);
  159.  
  160.     if( len )
  161.     {
  162.         SysMsgBoardStr(txtbuf);
  163.  
  164.         if(dbgfile.path)
  165.         {
  166.             write_file(dbgfile.path,txtbuf,dbgfile.offset,len,&writes);
  167.             dbgfile.offset+=writes;
  168.         };
  169.     };
  170.     return len;
  171. }
  172.  
  173. int snprintf(char *s, size_t n, const char *format, ...)
  174. {
  175.         va_list ap;
  176.         int retval;
  177.  
  178.         va_start(ap, format);
  179.         retval = vsnprintf(s, n, format, ap);
  180.         va_end(ap);
  181.  
  182.         return retval;
  183. }
  184.  
  185.  
  186.  
  187.