A clone of btpd with my configuration changes.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

92 lignes
2.1 KiB

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