5 #include "prototypes.h"
9 int checkRecv(SOCKET s
);
11 int checkRecv(SOCKET s
)
15 struct timeval timeout
;
22 testVal
= select(0, &sSet
, NULL
, NULL
, &timeout
);
24 if (testVal
== SOCKET_ERROR
)
25 fprintf(stderr
, "Socket Error");
30 void blkfree(char **av0
)
32 register char **av
= av0
;
38 char *glob(register char *v
)
49 int herror(char *string
)
55 int gettimeofday(struct timeval
*timenow
,
56 struct timezone
*zone
)
63 timenow
->tv_sec
= t
/ CLK_TCK
;
68 int fgetcSocket(int s
)
75 c
= recv(s
, buffer
, 1, 0);
78 printf("%c", buffer
[0]);
81 if (c
== INVALID_SOCKET
)
92 int fgetcSocket(int s
)
96 static char buffer
[4096];
101 total
= recv(s
, buffer
, sizeof(buffer
), 0);
103 if (total
== SOCKET_ERROR
)
112 return buffer
[index
++];
117 char *fprintfSocket(int s
, char *format
, ...)
122 va_start(argptr
, format
);
123 vsprintf(buffer
, format
, argptr
);
126 send(s
, buffer
, strlen(buffer
), 0);
131 char *fputsSocket(char *format
, int s
)
133 send(s
, format
, strlen(format
), 0);
138 int fputcSocket(int s
, char putChar
)
145 if(SOCKET_ERROR
==send(s
, buffer
, 1, 0)) {
146 int iret
=WSAGetLastError ();
147 fprintf(stdout
,"fputcSocket: %d\n",iret
);
154 int fputSocket(int s
, char *buffer
, int len
)
158 if(SOCKET_ERROR
==(iret
=send(s
, buffer
, len
, 0)))
160 iret
=WSAGetLastError ();
161 fprintf(stdout
,"fputcSocket: %d\n",iret
);
171 char *fgetsSocket(int s
, char *string
)
173 char buffer
[2] = {0};
176 for (i
= 0, count
= 1; count
!= 0 && buffer
[0] != '\n'; i
++)
180 count
= recv(s
, buffer
, 1, 0);
182 if (count
== SOCKET_ERROR
)
184 printf("Error in fgetssocket");
190 string
[i
] = buffer
[0];
192 if (i
== MAX_ASCII
- 3)
206 string
[i
+ 1] = '\0'; // This is risky
216 printf("%s", string
);
223 char *getpass(const char *prompt
)
225 static char string
[64];
227 printf("%s", prompt
);
234 char *getpass (const char * prompt
)
236 static char input
[256];
241 in
= GetStdHandle (STD_INPUT_HANDLE
);
242 err
= GetStdHandle (STD_ERROR_HANDLE
);
244 if (in
== INVALID_HANDLE_VALUE
|| err
== INVALID_HANDLE_VALUE
)
247 if (WriteFile (err
, prompt
, strlen (prompt
), &count
, NULL
))
249 int istty
= (GetFileType (in
) == FILE_TYPE_CHAR
);
255 if (GetConsoleMode (in
, &old_flags
))
256 SetConsoleMode (in
, ENABLE_LINE_INPUT
| ENABLE_PROCESSED_INPUT
);
260 /* Need to read line one byte at time to avoid blocking, if not a
261 tty, so always do it this way. */
268 rc
= ReadFile (in
, &one_char
, 1, &dummy
, NULL
);
271 if (one_char
== '\r')
273 /* CR is always followed by LF if reading from tty. */
279 if (one_char
== '\n')
281 /* Silently truncate password string if overly long. */
282 if (count
< sizeof (input
) - 1)
283 input
[count
++] = one_char
;
287 WriteFile (err
, "\r\n", 2, &count
, NULL
);
289 SetConsoleMode (in
, old_flags
);
297 // Stubbed out here. Should be changed in Source code...
298 int access(const char *filename
, int accessmethod
)
304 #define EPOCHFILETIME (116444736000000000i64)
306 #define EPOCHFILETIME (116444736000000000LL)
309 int gettimeofday(struct timeval
*tv
, struct timezone
*tz
)
318 GetSystemTimeAsFileTime(&ft
);
319 //li.LowPart = ft.dwLowDateTime;
320 //li.HighPart = ft.dwHighDateTime;
321 t
= li
.QuadPart
; /* In 100-nanosecond intervals */
322 t
-= EPOCHFILETIME
; /* Offset to the Epoch time */
323 t
/= 10; /* In microseconds */
324 tv
->tv_sec
= (long)(t
/ 1000000);
325 tv
->tv_usec
= (long)(t
% 1000000);
335 tz
->tz_minuteswest
= _timezone
/ 60;
336 tz
->tz_dsttime
= _daylight
;