a2io.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_IO_H
  44. # include <io.h>
  45. #endif // HAVE_IO_H
  46. // in some platforms following definitions are missing:
  47. #ifndef EINPROGRESS
  48. # define EINPROGRESS (WSAEINPROGRESS)
  49. #endif // EINPROGRESS
  50. #ifndef O_NONBLOCK
  51. # define O_NONBLOCK (O_NDELAY)
  52. #endif // O_NONBLOCK
  53. #ifndef O_BINARY
  54. # define O_BINARY (0)
  55. #endif // O_BINARY
  56. // st_mode flags
  57. #ifndef S_IRUSR
  58. # define S_IRUSR 0000400 /* read permission, owner */
  59. #endif /* S_IRUSR */
  60. #ifndef S_IWUSR
  61. # define S_IWUSR 0000200 /* write permission, owner */
  62. #endif /* S_IWUSR */
  63. #ifndef S_IXUSR
  64. # define S_IXUSR 0000100/* execute/search permission, owner */
  65. #endif /* S_IXUSR */
  66. #ifndef S_IRWXU
  67. # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
  68. #endif /* S_IRWXU */
  69. #ifndef S_IRGRP
  70. # define S_IRGRP 0000040 /* read permission, group */
  71. #endif /* S_IRGRP */
  72. #ifndef S_IWGRP
  73. # define S_IWGRP 0000020 /* write permission, grougroup */
  74. #endif /* S_IWGRP */
  75. #ifndef S_IXGRP
  76. # define S_IXGRP 0000010/* execute/search permission, group */
  77. #endif /* S_IXGRP */
  78. #ifndef S_IRWXG
  79. # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
  80. #endif /* S_IRWXG */
  81. #ifndef S_IROTH
  82. # define S_IROTH 0000004 /* read permission, other */
  83. #endif /* S_IROTH */
  84. #ifndef S_IWOTH
  85. # define S_IWOTH 0000002 /* write permission, other */
  86. #endif /* S_IWOTH */
  87. #ifndef S_IXOTH
  88. # define S_IXOTH 0000001/* execute/search permission, other */
  89. #endif /* S_IXOTH */
  90. #ifndef S_IRWXO
  91. # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
  92. #endif /* S_IRWXO */
  93. // Use 'nul' instead of /dev/null in win32.
  94. #ifdef HAVE_WINSOCK2_H
  95. # define DEV_NULL "nul"
  96. #else
  97. # define DEV_NULL "/dev/null"
  98. #endif // HAVE_WINSOCK2_H
  99. // Use 'con' instead of '/dev/stdin' and '/dev/stdout' in win32.
  100. #ifdef HAVE_WINSOCK2_H
  101. # define DEV_STDIN "con"
  102. # define DEV_STDOUT "con"
  103. #else
  104. # define DEV_STDIN "/dev/stdin"
  105. # define DEV_STDOUT "/dev/stdout"
  106. #endif // HAVE_WINSOCK2_H
  107. #ifdef __MINGW32__
  108. # define a2lseek(fd, offset, origin) _lseeki64(fd, offset, origin)
  109. # define a2fseek(fd, offset, origin) _fseeki64(fd, offset, origin)
  110. # define a2fstat(fd, buf) _fstati64(fd, buf)
  111. # define a2ftell(fd) _ftelli64(fd)
  112. # define a2wstat(path, buf) _wstati64(path, buf)
  113. # ifdef stat
  114. # undef stat
  115. # endif // stat
  116. # define a2_struct_stat struct _stati64
  117. # define a2stat(path, buf) _stati64(path, buf)
  118. # define a2tell(handle) _telli64(handle)
  119. # define a2mkdir(path, openMode) mkdir(path)
  120. #else // !__MINGW32__
  121. # define a2lseek(fd, offset, origin) lseek(fd, offset, origin)
  122. # define a2fseek(fp, offset, origin) fseek(fp, offset, origin)
  123. # define a2fstat(fp, buf) fstat(fp, buf)
  124. # define a2ftell(fp) ftell(fp)
  125. # define a2_struct_stat struct stat
  126. # define a2stat(path, buf) stat(path, buf)
  127. # define a2mkdir(path, openMode) mkdir(path, openMode)
  128. #endif // !__MINGW32__
  129. #if defined HAVE_POSIX_MEMALIGN && defined O_DIRECT
  130. # define ENABLE_DIRECT_IO 1
  131. #endif // HAVE_POSIX_MEMALIGN && O_DIRECT
  132. #define OPEN_MODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
  133. #define DIR_OPEN_MODE S_IRWXU|S_IRWXG|S_IRWXO
  134. #endif // _D_A2IO_H_