ReactOS 0.4.15-dev-8109-gd7be748
fake.c
Go to the documentation of this file.
1#include "precomp.h"
2
3#include <wincon.h>
4
5#define MAX_ASCII 100
6
8
10{
11 int testVal;
12 fd_set sSet;
13 struct timeval timeout;
14 timeout.tv_sec = 60;
15
16 FD_ZERO(&sSet);
17
18 FD_SET(s, &sSet);
19
20 testVal = select(0, &sSet, NULL, NULL, &timeout);
21
22 if (testVal == SOCKET_ERROR)
23 fprintf(stderr, "Socket Error");
24
25 return testVal;
26}
27
28void blkfree(char **av0)
29{
30 register char **av = av0;
31
32 while (*av)
33 free(*av++);
34}
35
36char **glob(const char *v)
37{
38 return NULL;
39}
40
41int sleep(int time)
42{
43 return time;
44}
45
46int herror(char *string)
47{
48 return 0;
49}
50
51#if 0
52int gettimeofday(struct timeval *timenow,
53 struct timezone *zone)
54{
55 time_t t;
56
57 t = clock();
58
59 timenow->tv_usec = t;
60 timenow->tv_sec = t / CLK_TCK;
61
62 return 0;
63}
64
65int fgetcSocket(int s)
66{
67 int c;
68 char buffer[10];
69
70// checkRecv(s);
71
72 c = recv(s, buffer, 1, 0);
73
74#ifdef DEBUG_IN
75 printf("%c", buffer[0]);
76#endif
77
78 if (c == INVALID_SOCKET)
79 return c;
80
81 if (c == 0)
82 return EOF;
83
84 return buffer[0];
85}
86
87#else
88
89int fgetcSocket(int s)
90{
91 static int index = 0;
92 static int total = 0;
93 static char buffer[4096];
94
95 if (index == total)
96 {
97 index = 0;
98 total = recv(s, buffer, sizeof(buffer), 0);
99
100 if (total == SOCKET_ERROR)
101 {
102 total = 0;
103 return ERROR;
104 }
105
106 if (total == 0)
107 return EOF;
108 }
109 return buffer[index++];
110}
111
112#endif
113
114const char *fprintfSocket(int s, const char *format, ...)
115{
116 va_list argptr;
117 char buffer[10009];
118
119 va_start(argptr, format);
120 vsprintf(buffer, format, argptr);
121 va_end(argptr);
122
123 send(s, buffer, strlen(buffer), 0);
124
125 return NULL;
126}
127
128const char *fputsSocket(const char *format, int s)
129{
130 send(s, format, strlen(format), 0);
131
132 return NULL;
133}
134
135int fputcSocket(int s, char putChar)
136{
137 char buffer[2];
138
139 buffer[0] = putChar;
140 buffer[1] = '\0';
141
142 if(SOCKET_ERROR==send(s, buffer, 1, 0)) {
143 int iret=WSAGetLastError ();
144 fprintf(stdout,"fputcSocket: %d\n",iret);
145 return 0;
146 }
147 else {
148 return putChar;
149 }
150}
151int fputSocket(int s, char *buffer, int len)
152{
153 int iret;
154 while(len) {
155 if(SOCKET_ERROR==(iret=send(s, buffer, len, 0)))
156 {
157 iret=WSAGetLastError ();
158 fprintf(stdout,"fputcSocket: %d\n",iret);
159 return 0;
160 }
161 else {
162 return len-=iret;
163 }
164 }
165 return 0;
166}
167
168char *fgetsSocket(int s, char *string)
169{
170 char buffer[2] = {0};
171 int i, count;
172
173 for (i = 0, count = 1; count != 0 && buffer[0] != '\n'; i++)
174 {
175 checkRecv(s);
176
177 count = recv(s, buffer, 1, 0);
178
179 if (count == SOCKET_ERROR)
180 {
181 printf("Error in fgetssocket");
182 return NULL;
183 }
184
185 if (count == 1)
186 {
187 string[i] = buffer[0];
188
189 if (i == MAX_ASCII - 3)
190 {
191 count = 0;
192 string[++i] = '\n';
193 string[++i] = '\0';
194 }
195 }
196 else
197 {
198 if (i == 0)
199 return NULL;
200 else
201 {
202 string[i] = '\n';
203 string[i + 1] = '\0'; // This is risky
204 return string;
205 }
206
207 }
208
209 }
210 string[i] = '\0';
211
212#ifdef DEBUG_IN
213 printf("%s", string);
214#endif
215 return string;
216}
217
218
219#if 0
220char *getpass(const char *prompt)
221{
222 static char string[64];
223
224 printf("%s", prompt);
225
226 gets(string);
227
228 return string;
229}
230#endif
231char *getpass (const char * prompt)
232{
233 static char input[256];
234 HANDLE in;
235 HANDLE err;
236 DWORD count;
237
240
242 return NULL;
243
244 if (WriteFile (err, prompt, strlen (prompt), &count, NULL))
245 {
246 int istty = (GetFileType (in) == FILE_TYPE_CHAR);
247 DWORD old_flags;
248 int rc;
249
250 if (istty)
251 {
252 if (GetConsoleMode (in, &old_flags))
254 else
255 istty = 0;
256 }
257 /* Need to read line one byte at time to avoid blocking, if not a
258 tty, so always do it this way. */
259 count = 0;
260 while (1)
261 {
262 DWORD dummy;
263 char one_char;
264
265 rc = ReadFile (in, &one_char, 1, &dummy, NULL);
266 if (rc == 0)
267 break;
268 if (one_char == '\r')
269 {
270 /* CR is always followed by LF if reading from tty. */
271 if (istty)
272 continue;
273 else
274 break;
275 }
276 if (one_char == '\n')
277 break;
278 /* Silently truncate password string if overly long. */
279 if (count < sizeof (input) - 1)
280 input[count++] = one_char;
281 }
282 input[count] = '\0';
283
284 WriteFile (err, "\r\n", 2, &count, NULL);
285 if (istty)
286 SetConsoleMode (in, old_flags);
287 if (rc)
288 return input;
289 }
290
291 return NULL;
292}
293
294#if 0
295// Stubbed out here. Should be changed in Source code...
296int access(const char *filename, int accessmethod)
297{
298 return 0;
299}
300#endif
301
302#ifndef __GNUC__
303#define EPOCHFILETIME (116444736000000000i64)
304#else
305#define EPOCHFILETIME (116444736000000000LL)
306#endif
307
308int gettimeofday(struct timeval *tv, struct timezone *tz)
309{
310 FILETIME ft;
312 __int64 t;
313 static int tzflag;
314
315 if (tv)
316 {
320 t = li.QuadPart; /* In 100-nanosecond intervals */
321 t -= EPOCHFILETIME; /* Offset to the Epoch time */
322 t /= 10; /* In microseconds */
323 tv->tv_sec = (long)(t / 1000000);
324 tv->tv_usec = (long)(t % 1000000);
325 }
326
327 if (tz)
328 {
329 if (!tzflag)
330 {
331 _tzset();
332 tzflag++;
333 }
334 tz->tz_minuteswest = _timezone / 60;
335 tz->tz_dsttime = _daylight;
336 }
337
338 return 0;
339}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define gettimeofday(tv, tz)
Definition: adns_win32.h:159
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
#define __int64
Definition: basetyps.h:16
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1569
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1606
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:269
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
__kernel_time_t time_t
Definition: linux.h:252
#define ERROR(name)
Definition: error_private.h:53
#define EPOCHFILETIME
Definition: fake.c:303
void blkfree(char **av0)
Definition: fake.c:28
char * fgetsSocket(int s, char *string)
Definition: fake.c:168
#define MAX_ASCII
Definition: fake.c:5
char ** glob(const char *v)
Definition: fake.c:36
int fputSocket(int s, char *buffer, int len)
Definition: fake.c:151
const char * fputsSocket(const char *format, int s)
Definition: fake.c:128
char * getpass(const char *prompt)
Definition: fake.c:231
int herror(char *string)
Definition: fake.c:46
const char * fprintfSocket(int s, const char *format,...)
Definition: fake.c:114
int checkRecv(SOCKET s)
Definition: fake.c:9
int fputcSocket(int s, char putChar)
Definition: fake.c:135
int fgetcSocket(int s)
Definition: fake.c:89
unsigned long DWORD
Definition: ntddk_ex.h:95
#define printf
Definition: freeldr.h:97
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
size_t total
const GLdouble * v
Definition: gl.h:2040
GLdouble s
Definition: gl.h:2039
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLdouble GLdouble t
Definition: gl.h:2047
GLbyte GLbyte tz
Definition: glext.h:8756
GLuint buffer
Definition: glext.h:5915
const GLubyte * c
Definition: glext.h:8905
GLuint index
Definition: glext.h:6031
GLuint in
Definition: glext.h:9616
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
GLenum GLsizei len
Definition: glext.h:6722
GLenum GLenum GLenum input
Definition: glext.h:9031
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define stdout
Definition: stdio.h:99
#define EOF
Definition: stdio.h:24
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_CRTIMP char *__cdecl gets(char *_Buffer)
Definition: file.c:3645
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
const char * filename
Definition: ioapi.h:137
#define c
Definition: ke_i.h:80
#define sleep
Definition: syshdrs.h:37
__u16 time
Definition: mkdosfs.c:8
char string[160]
Definition: util.h:11
DWORD zone
Definition: sec_mgr.c:1754
#define long
Definition: qsort.c:33
#define err(...)
#define CLK_TCK
Definition: time.h:425
_Check_return_ _CRTIMP clock_t __cdecl clock(void)
Definition: clock.c:23
_CRTIMP void __cdecl _tzset(void)
Definition: timezone.c:92
int _daylight
Definition: timezone.c:30
long _timezone
Definition: timezone.c:46
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65
Definition: winsock.h:66
Definition: dhcpd.h:245
unsigned long tv_sec
Definition: linux.h:1738
unsigned long tv_usec
Definition: linux.h:1739
Definition: fake.h:14
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
#define STD_INPUT_HANDLE
Definition: winbase.h:267
#define STD_ERROR_HANDLE
Definition: winbase.h:269
#define FILE_TYPE_CHAR
Definition: winbase.h:260
#define ENABLE_LINE_INPUT
Definition: wincon.h:79
#define ENABLE_PROCESSED_INPUT
Definition: wincon.h:78
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
#define FD_ZERO(set)
Definition: winsock.h:96
#define INVALID_SOCKET
Definition: winsock.h:332
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOCKET_ERROR
Definition: winsock.h:333
#define FD_SET(fd, set)
Definition: winsock.h:89