file.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* ----------------------------------------------------------------------- *
  2. *
  3. * Copyright 1996-2017 The NASM Authors - All Rights Reserved
  4. * See the file AUTHORS included with the NASM distribution for
  5. * the specific copyright holders.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following
  9. * conditions are met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials provided
  16. * with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  19. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  20. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * ----------------------------------------------------------------------- */
  33. #ifndef NASMLIB_FILE_H
  34. #define NASMLIB_FILE_H
  35. #include "compiler.h"
  36. #include "nasmlib.h"
  37. #include "error.h"
  38. #include <errno.h>
  39. #ifdef HAVE_FCNTL_H
  40. # include <fcntl.h>
  41. #endif
  42. #ifdef HAVE_SYS_TYPES_H
  43. # include <sys/types.h>
  44. #endif
  45. #ifdef HAVE_SYS_STAT_H
  46. # include <sys/stat.h>
  47. #endif
  48. #ifdef HAVE_IO_H
  49. # include <io.h>
  50. #endif
  51. #ifdef HAVE_UNISTD_H
  52. # include <unistd.h>
  53. #endif
  54. #ifdef HAVE_SYS_MMAN_H
  55. # include <sys/mman.h>
  56. #endif
  57. #if !defined(HAVE_ACCESS) && defined(HAVE__ACCESS)
  58. # define HAVE_ACCESS 1
  59. # define access _access
  60. #endif
  61. #ifndef R_OK
  62. # define R_OK 4 /* Classic Unix constant, same on Windows */
  63. #endif
  64. /* Can we adjust the file size without actually writing all the bytes? */
  65. #ifdef HAVE__CHSIZE_S
  66. # define nasm_ftruncate(fd,size) _chsize_s(fd,size)
  67. #elif defined(HAVE__CHSIZE)
  68. # define nasm_ftruncate(fd,size) _chsize(fd,size)
  69. #elif defined(HAVE_FTRUNCATE)
  70. # define nasm_ftruncate(fd,size) ftruncate(fd,size)
  71. #endif
  72. /*
  73. * On Win32/64, stat has a 32-bit file size but _stati64 has a 64-bit file
  74. * size. Things get complicated because some of these may be macros,
  75. * which autoconf won't pick up on as the standard autoconf tests do
  76. * #undef.
  77. */
  78. #ifdef _stati64
  79. # define HAVE_STRUCT__STATI64 1
  80. # define HAVE__STATI64 1
  81. #endif
  82. #ifdef _fstati64
  83. # define HAVE__FSTATI64 1
  84. #endif
  85. #ifdef HAVE_STRUCT__STATI64
  86. typedef struct _stati64 nasm_struct_stat;
  87. # ifdef HAVE__STATI64
  88. # define nasm_stat _stati64
  89. # endif
  90. # ifdef HAVE__FSTATI64
  91. # define nasm_fstat _fstati64
  92. # endif
  93. #elif defined(HAVE_STRUCT_STAT)
  94. typedef struct stat nasm_struct_stat;
  95. # ifdef HAVE_STAT
  96. # define nasm_stat stat
  97. # endif
  98. # ifdef HAVE_FSTAT
  99. # define nasm_fstat fstat
  100. # endif
  101. #endif
  102. #ifndef HAVE_FILENO
  103. # ifdef fileno /* autoconf doesn't always pick up macros */
  104. # define HAVE_FILENO 1
  105. # elif defined(HAVE__FILENO)
  106. # define HAVE_FILENO 1
  107. # define fileno _fileno
  108. # endif
  109. #endif
  110. /* These functions are utterly useless without fileno() */
  111. #ifndef HAVE_FILENO
  112. # undef nasm_fstat
  113. # undef nasm_ftruncate
  114. # undef HAVE_MMAP
  115. # undef HAVE__FILELENGTHI64
  116. #endif
  117. #endif /* NASMLIB_FILE_H */