-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcestdio.c
153 lines (120 loc) · 2.68 KB
/
cestdio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// cestdio.c
//
// Time-stamp: <02/02/01 18:28:15 keuchel@lightning>
#include "celib.h"
#include "sys/stat.h"
// we need to fix path...
FILE *
xcefopen(const char *path, const char *mode)
{
char newpath[MAX_PATH];
wchar_t wpath[MAX_PATH];
wchar_t wpathnew[MAX_PATH];
wchar_t wmode[10];
FILE *f;
int fd;
_initfds();
// WinCE has no NUL!
if(xcestricmp(path, "nul") == 0 ||
xcestricmp(path, "null:") == 0 ||
xcestricmp(path, "/dev/null") == 0)
{
#if 0
strcpy(newpath, "nul:");
#else
strcpy(newpath, (char *) XCEGetUnixPath("/dev/null"));
#endif
}
else
{
strcpy(newpath, path);
}
MultiByteToWideChar(CP_ACP, 0, newpath, -1, wpath, COUNTOF(wpath));
MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, COUNTOF(wmode));
XCEFixPathW(wpath, wpathnew);
//wprintf(L"xcefopen(%s)\n", wpathnew);
if((f = _wfopen(wpathnew, wmode)) == NULL)
{
XCETRACEW((L"xcefopen(%s): oserr = %d\n", wpathnew, GetLastError()));
return NULL;
}
// needed for xcefileno...
fd = _getnewfd();
_fdtab[fd].fd = fd;
_fdtab[fd].type = XCE_FILE_TYPE_FILE;
// seems to be os handle...
_fdtab[fd].hFile = fileno(f);
return f;
}
// there is only a wide version!
FILE *
xcefreopen(const char *path, const char *mode, FILE *stream)
{
wchar_t wpath[MAX_PATH];
wchar_t wpathnew[MAX_PATH];
wchar_t wmode[10];
MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, COUNTOF(wpath));
MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, COUNTOF(wmode));
XCEFixPathW(wpath, wpathnew);
//wprintf(L"xcefopen(%s)\n", wpathnew);
return _wfreopen(wpathnew, wmode, stream);
}
void
xcefclose(FILE *f)
{
int fd;
for(fd = 0; fd < MAXFDS; fd++)
{
if(_fdtab[fd].hFile == fileno(f))
{
_fdtab[fd].fd = -1;
break;
}
}
fclose(f);
}
int
xcefileno(FILE *f)
{
int fd;
for(fd = 0; fd < MAXFDS; fd++)
{
if(_fdtab[fd].hFile == fileno(f))
{
return _fdtab[fd].fd;
}
}
fprintf(stderr, "Cannot get fileno for file %x\n", f);
return -1;
}
void
xcerewind(FILE *f)
{
fseek(f, 0L, SEEK_SET);
}
FILE *
xcefdopen(int fd, const char *mode)
{
wchar_t wmode[10];
if(fd < 0 || _fdtab[fd].fd == -1)
return NULL;
if(_fdtab[fd].type == XCE_FILE_TYPE_SOCKET)
{
errno = EINVAL;
return NULL;
}
MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, COUNTOF(wmode));
return _wfdopen(_fdtab[fd].hFile, wmode);
}
FILE *
xcepopen(const char *command, const char *mode)
{
errno = ENOSYS;
return NULL;
}
int
xcepclose(FILE *f)
{
errno = ENOSYS;
return -1;
}