You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.0KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include "internal.h"
  20. #include "mem.h"
  21. #include <stdarg.h>
  22. #include <fcntl.h>
  23. #include <sys/stat.h>
  24. #if HAVE_UNISTD_H
  25. #include <unistd.h>
  26. #endif
  27. #if HAVE_IO_H
  28. #include <io.h>
  29. #endif
  30. #if defined(_WIN32) && !defined(__MINGW32CE__)
  31. #undef open
  32. #undef lseek
  33. #undef stat
  34. #undef fstat
  35. #include <windows.h>
  36. #include <share.h>
  37. #include <errno.h>
  38. #include "wchar_filename.h"
  39. static int win32_open(const char *filename_utf8, int oflag, int pmode)
  40. {
  41. int fd;
  42. wchar_t *filename_w;
  43. /* convert UTF-8 to wide chars */
  44. if (utf8towchar(filename_utf8, &filename_w))
  45. return -1;
  46. if (!filename_w)
  47. goto fallback;
  48. fd = _wsopen(filename_w, oflag, SH_DENYNO, pmode);
  49. av_freep(&filename_w);
  50. if (fd != -1 || (oflag & O_CREAT))
  51. return fd;
  52. fallback:
  53. /* filename may be be in CP_ACP */
  54. return _sopen(filename_utf8, oflag, SH_DENYNO, pmode);
  55. }
  56. #define open win32_open
  57. #endif
  58. int avpriv_open(const char *filename, int flags, ...)
  59. {
  60. int fd;
  61. unsigned int mode = 0;
  62. va_list ap;
  63. va_start(ap, flags);
  64. if (flags & O_CREAT)
  65. mode = va_arg(ap, unsigned int);
  66. va_end(ap);
  67. #ifdef O_CLOEXEC
  68. flags |= O_CLOEXEC;
  69. #endif
  70. fd = open(filename, flags, mode);
  71. #if HAVE_FCNTL
  72. if (fd != -1)
  73. fcntl(fd, F_SETFD, FD_CLOEXEC);
  74. #endif
  75. return fd;
  76. }