MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
misc.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <windows.h>
4 #include <sys/timeb.h>
5 #include <time.h>
6 
7 #ifdef __GNUC__
8 /*our prototypes for timeval and timezone are in here, just in case the above
9  headers don't have them*/
10 #include "misc.h"
11 #endif
12 
13 /****************************************************************************
14  *
15  * Function: gettimeofday(struct timeval *, struct timezone *)
16  *
17  * Purpose: Get current time of day.
18  *
19  * Arguments: tv => Place to store the curent time of day.
20  * tz => Ignored.
21  *
22  * Returns: 0 => Success.
23  *
24  ****************************************************************************/
25 
26 #ifndef HAVE_GETTIMEOFDAY
27 int gettimeofday(struct timeval *tv, struct timezone *tz) {
28  struct _timeb tb;
29 
30  if(tv == NULL)
31  return -1;
32 
33  _ftime(&tb);
34  tv->tv_sec = (long) tb.time;
35  tv->tv_usec = ((int) tb.millitm) * 1000;
36  return 0;
37 }
38 #endif
39 
40 #if 0
41 int
42 win_read(int fd, void *buf, unsigned int length)
43 {
44  DWORD dwBytesRead;
45  int res = ReadFile((HANDLE) fd, buf, length, &dwBytesRead, NULL);
46  if (res == 0) {
47  DWORD error = GetLastError();
48  if (error == ERROR_NO_DATA)
49  return (0);
50  return (-1);
51  } else
52  return (dwBytesRead);
53 }
54 
55 int
56 win_write(int fd, void *buf, unsigned int length)
57 {
58  DWORD dwBytesWritten;
59  int res = WriteFile((HANDLE) fd, buf, length, &dwBytesWritten, NULL);
60  if (res == 0) {
61  DWORD error = GetLastError();
62  if (error == ERROR_NO_DATA)
63  return (0);
64  return (-1);
65  } else
66  return (dwBytesWritten);
67 }
68 
69 int
70 socketpair(int d, int type, int protocol, int *sv)
71 {
72  static int count;
73  char buf[64];
74  HANDLE fd;
75  DWORD dwMode;
76  sprintf(buf, "\\\\.\\pipe\\levent-%d", count++);
77  /* Create a duplex pipe which will behave like a socket pair */
78  fd = CreateNamedPipe(buf, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_NOWAIT,
79  PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, NULL);
80  if (fd == INVALID_HANDLE_VALUE)
81  return (-1);
82  sv[0] = (int)fd;
83 
84  fd = CreateFile(buf, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
85  if (fd == INVALID_HANDLE_VALUE)
86  return (-1);
87  dwMode = PIPE_NOWAIT;
88  SetNamedPipeHandleState(fd, &dwMode, NULL, NULL);
89  sv[1] = (int)fd;
90 
91  return (0);
92 }
93 #endif