Subversion Repositories Kolibri OS

Rev

Rev 1604 | Rev 1869 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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