a2io.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #ifndef D_A2IO_H
  36. #define D_A2IO_H
  37. #include "common.h"
  38. #include <sys/types.h>
  39. #include <sys/stat.h>
  40. #include <unistd.h>
  41. #include <fcntl.h>
  42. #include <cerrno>
  43. #ifdef HAVE_POLL_H
  44. # include <poll.h>
  45. #endif // HAVE_POLL_H
  46. #ifdef HAVE_IO_H
  47. # include <io.h>
  48. #endif // HAVE_IO_H
  49. // in some platforms following definitions are missing:
  50. #ifndef EINPROGRESS
  51. # define EINPROGRESS (WSAEINPROGRESS)
  52. #endif // EINPROGRESS
  53. #ifndef O_NONBLOCK
  54. # define O_NONBLOCK (O_NDELAY)
  55. #endif // O_NONBLOCK
  56. #ifndef O_BINARY
  57. # define O_BINARY (0)
  58. #endif // O_BINARY
  59. // st_mode flags
  60. #ifndef S_IRUSR
  61. # define S_IRUSR 0000400 /* read permission, owner */
  62. #endif /* S_IRUSR */
  63. #ifndef S_IWUSR
  64. # define S_IWUSR 0000200 /* write permission, owner */
  65. #endif /* S_IWUSR */
  66. #ifndef S_IXUSR
  67. # define S_IXUSR 0000100/* execute/search permission, owner */
  68. #endif /* S_IXUSR */
  69. #ifndef S_IRWXU
  70. # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
  71. #endif /* S_IRWXU */
  72. #ifndef S_IRGRP
  73. # define S_IRGRP 0000040 /* read permission, group */
  74. #endif /* S_IRGRP */
  75. #ifndef S_IWGRP
  76. # define S_IWGRP 0000020 /* write permission, grougroup */
  77. #endif /* S_IWGRP */
  78. #ifndef S_IXGRP
  79. # define S_IXGRP 0000010/* execute/search permission, group */
  80. #endif /* S_IXGRP */
  81. #ifndef S_IRWXG
  82. # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
  83. #endif /* S_IRWXG */
  84. #ifndef S_IROTH
  85. # define S_IROTH 0000004 /* read permission, other */
  86. #endif /* S_IROTH */
  87. #ifndef S_IWOTH
  88. # define S_IWOTH 0000002 /* write permission, other */
  89. #endif /* S_IWOTH */
  90. #ifndef S_IXOTH
  91. # define S_IXOTH 0000001/* execute/search permission, other */
  92. #endif /* S_IXOTH */
  93. #ifndef S_IRWXO
  94. # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
  95. #endif /* S_IRWXO */
  96. // Use 'nul' instead of /dev/null in win32.
  97. #ifdef HAVE_WINSOCK2_H
  98. # define DEV_NULL "nul"
  99. #else
  100. # define DEV_NULL "/dev/null"
  101. #endif // HAVE_WINSOCK2_H
  102. // Use 'con' instead of '/dev/stdin' and '/dev/stdout' in win32.
  103. #ifdef HAVE_WINSOCK2_H
  104. # define DEV_STDIN "con"
  105. # define DEV_STDOUT "con"
  106. #else
  107. # define DEV_STDIN "/dev/stdin"
  108. # define DEV_STDOUT "/dev/stdout"
  109. #endif // HAVE_WINSOCK2_H
  110. #ifdef __MINGW32__
  111. # define a2lseek(fd, offset, origin) _lseeki64(fd, offset, origin)
  112. # define a2fseek(fd, offset, origin) _fseeki64(fd, offset, origin)
  113. # define a2fstat(fd, buf) _fstati64(fd, buf)
  114. # define a2ftell(fd) _ftelli64(fd)
  115. # define a2wstat(path, buf) _wstati64(path, buf)
  116. # ifdef stat
  117. # undef stat
  118. # endif // stat
  119. # define a2_struct_stat struct _stati64
  120. # define a2stat(path, buf) _wstati64(path, buf)
  121. # define a2tell(handle) _telli64(handle)
  122. # define a2mkdir(path, openMode) _wmkdir(path)
  123. # define a2utimbuf _utimbuf
  124. # define a2utime(path, times) _wutime(path, times)
  125. # define a2unlink(path) _wunlink(path)
  126. # define a2rmdir(path) _wrmdir(path)
  127. # define a2rename(src, dest) _wrename(src, dest)
  128. # define a2open(path, flags, mode) _wopen(path, flags, mode)
  129. # define a2fopen(path, mode) _wfopen(path, mode)
  130. #else // !__MINGW32__
  131. # define a2lseek(fd, offset, origin) lseek(fd, offset, origin)
  132. # define a2fseek(fp, offset, origin) fseek(fp, offset, origin)
  133. # define a2fstat(fp, buf) fstat(fp, buf)
  134. # define a2ftell(fp) ftell(fp)
  135. # define a2_struct_stat struct stat
  136. # define a2stat(path, buf) stat(path, buf)
  137. # define a2mkdir(path, openMode) mkdir(path, openMode)
  138. # define a2utimbuf utimbuf
  139. # define a2utime(path, times) ::utime(path, times)
  140. # define a2unlink(path) unlink(path)
  141. # define a2rmdir(path) rmdir(path)
  142. # define a2rename(src, dest) rename(src, dest)
  143. # define a2open(path, flags, mode) open(path, flags, mode)
  144. # define a2fopen(path, mode) fopen(path, mode)
  145. #endif // !__MINGW32__
  146. #define OPEN_MODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
  147. #define DIR_OPEN_MODE S_IRWXU|S_IRWXG|S_IRWXO
  148. #endif // D_A2IO_H