Merge commit 'a76d0cdf21c3d9e464623cc0ad1c005abf952afa'
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 10 Aug 2013 08:36:18 +0000 (10:36 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 10 Aug 2013 08:37:20 +0000 (10:37 +0200)
* commit 'a76d0cdf21c3d9e464623cc0ad1c005abf952afa':
  libavutil: Move avpriv_open to a new file, file_open.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavutil/Makefile
libavutil/file.c
libavutil/file_open.c

diff --combined libavutil/Makefile
@@@ -1,5 -1,3 +1,5 @@@
 +include $(SUBDIR)../config.mak
 +
  NAME = avutil
  
  HEADERS = adler32.h                                                     \
@@@ -12,7 -10,6 +12,7 @@@
            avutil.h                                                      \
            base64.h                                                      \
            blowfish.h                                                    \
 +          bprint.h                                                      \
            bswap.h                                                       \
            buffer.h                                                      \
            channel_layout.h                                              \
@@@ -34,7 -31,6 +34,7 @@@
            mathematics.h                                                 \
            md5.h                                                         \
            mem.h                                                         \
 +          murmur3.h                                                     \
            dict.h                                                        \
            old_pix_fmts.h                                                \
            opt.h                                                         \
            pixfmt.h                                                      \
            random_seed.h                                                 \
            rational.h                                                    \
 +          ripemd.h                                                      \
            samplefmt.h                                                   \
            sha.h                                                         \
 +          sha512.h                                                      \
            time.h                                                        \
 +          timecode.h                                                    \
 +          timestamp.h                                                   \
            version.h                                                     \
            xtea.h                                                        \
  
  HEADERS-$(CONFIG_LZO)                   += lzo.h
  
 +HEADERS-$(CONFIG_OPENCL)                += opencl.h
 +
  ARCH_HEADERS = bswap.h                                                  \
                 intmath.h                                                \
                 intreadwrite.h                                           \
@@@ -71,7 -61,6 +71,7 @@@ OBJS = adler32.
         avstring.o                                                       \
         base64.o                                                         \
         blowfish.o                                                       \
 +       bprint.o                                                         \
         buffer.o                                                         \
         channel_layout.o                                                 \
         cpu.o                                                            \
         eval.o                                                           \
         fifo.o                                                           \
         file.o                                                           \
+        file_open.o                                                      \
         float_dsp.o                                                      \
         frame.o                                                          \
 +       hash.o                                                           \
         hmac.o                                                           \
         imgutils.o                                                       \
         intfloat_readwrite.o                                             \
@@@ -95,7 -84,6 +96,7 @@@
         mathematics.o                                                    \
         md5.o                                                            \
         mem.o                                                            \
 +       murmur3.o                                                        \
         dict.o                                                           \
         opt.o                                                            \
         parseutils.o                                                     \
         random_seed.o                                                    \
         rational.o                                                       \
         rc4.o                                                            \
 +       ripemd.o                                                         \
         samplefmt.o                                                      \
         sha.o                                                            \
 +       sha512.o                                                         \
         time.o                                                           \
 +       timecode.o                                                       \
         tree.o                                                           \
         utils.o                                                          \
 +       xga_font_data.o                                                  \
         xtea.o                                                           \
  
  OBJS-$(CONFIG_LZO)                      += lzo.o
 +OBJS-$(CONFIG_OPENCL)                   += opencl.o opencl_internal.o
  
  OBJS += $(COMPAT_OBJS:%=../compat/%)
  
@@@ -124,7 -107,6 +125,7 @@@ SKIPHEADERS          = old_pix_fmts.
  SKIPHEADERS-$(HAVE_ATOMICS_GCC)        += atomic_gcc.h
  SKIPHEADERS-$(HAVE_ATOMICS_SUNCC)      += atomic_suncc.h
  SKIPHEADERS-$(HAVE_ATOMICS_WIN32)      += atomic_win32.h
 +SKIPHEADERS-$(CONFIG_OPENCL)           += opencl.h
  
  TESTPROGS = adler32                                                     \
              aes                                                         \
              avstring                                                    \
              base64                                                      \
              blowfish                                                    \
 +            bprint                                                      \
              cpu                                                         \
              crc                                                         \
              des                                                         \
 +            error                                                       \
              eval                                                        \
 +            file                                                        \
              fifo                                                        \
              hmac                                                        \
              lfg                                                         \
              lls                                                         \
              md5                                                         \
 +            murmur3                                                     \
              opt                                                         \
 +            pca                                                         \
              parseutils                                                  \
 +            random_seed                                                 \
 +            rational                                                    \
 +            ripemd                                                      \
              sha                                                         \
 +            sha512                                                      \
              tree                                                        \
              xtea                                                        \
 +
 +TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo
 +
 +TOOLS = ffhash ffeval ffescape
 +
 +$(SUBDIR)lzo-test$(EXESUF): ELIBS = -llzo2
diff --combined libavutil/file.c
@@@ -1,18 -1,18 +1,18 @@@
  /*
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -21,7 -21,6 +21,6 @@@
  #include "internal.h"
  #include "log.h"
  #include "mem.h"
- #include <stdarg.h>
  #include <fcntl.h>
  #include <sys/stat.h>
  #if HAVE_UNISTD_H
  #include <windows.h>
  #endif
  
- #if defined(_WIN32) && !defined(__MINGW32CE__)
- #undef open
- #undef lseek
- #undef stat
- #undef fstat
- #include <windows.h>
- #include <share.h>
- #include <errno.h>
- static int win32_open(const char *filename_utf8, int oflag, int pmode)
- {
-     int fd;
-     int num_chars;
-     wchar_t *filename_w;
-     /* convert UTF-8 to wide chars */
-     num_chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename_utf8, -1, NULL, 0);
-     if (num_chars <= 0)
-         goto fallback;
-     filename_w = av_mallocz(sizeof(wchar_t) * num_chars);
-     if (!filename_w) {
-         errno = ENOMEM;
-         return -1;
-     }
-     MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, filename_w, num_chars);
-     fd = _wsopen(filename_w, oflag, SH_DENYNO, pmode);
-     av_freep(&filename_w);
-     if (fd != -1 || (oflag & O_CREAT))
-         return fd;
- fallback:
-     /* filename may be be in CP_ACP */
-     return _sopen(filename_utf8, oflag, SH_DENYNO, pmode);
- }
- #define open win32_open
- #endif
- int avpriv_open(const char *filename, int flags, ...)
- {
-     int fd;
-     unsigned int mode = 0;
-     va_list ap;
-     va_start(ap, flags);
-     if (flags & O_CREAT)
-         mode = va_arg(ap, unsigned int);
-     va_end(ap);
- #ifdef O_CLOEXEC
-     flags |= O_CLOEXEC;
- #endif
-     fd = open(filename, flags, mode);
- #if HAVE_FCNTL
-     if (fd != -1)
-         fcntl(fd, F_SETFD, FD_CLOEXEC);
- #endif
-     return fd;
- }
  typedef struct {
      const AVClass *class;
      int   log_offset;
@@@ -200,69 -136,3 +136,69 @@@ void av_file_unmap(uint8_t *bufptr, siz
      av_free(bufptr);
  #endif
  }
 +
 +int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx) {
 +    FileLogContext file_log_ctx = { &file_log_ctx_class, log_offset, log_ctx };
 +    int fd=-1;
 +#if !HAVE_MKSTEMP
 +    void *ptr= tempnam(NULL, prefix);
 +    if(!ptr)
 +        ptr= tempnam(".", prefix);
 +    *filename = av_strdup(ptr);
 +#undef free
 +    free(ptr);
 +#else
 +    size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
 +    *filename = av_malloc(len);
 +#endif
 +    /* -----common section-----*/
 +    if (*filename == NULL) {
 +        av_log(&file_log_ctx, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
 +        return AVERROR(ENOMEM);
 +    }
 +#if !HAVE_MKSTEMP
 +#   ifndef O_BINARY
 +#       define O_BINARY 0
 +#   endif
 +#   ifndef O_EXCL
 +#       define O_EXCL 0
 +#   endif
 +    fd = open(*filename, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600);
 +#else
 +    snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
 +    fd = mkstemp(*filename);
 +#ifdef _WIN32
 +    if (fd < 0) {
 +        snprintf(*filename, len, "./%sXXXXXX", prefix);
 +        fd = mkstemp(*filename);
 +    }
 +#endif
 +#endif
 +    /* -----common section-----*/
 +    if (fd < 0) {
 +        int err = AVERROR(errno);
 +        av_log(&file_log_ctx, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
 +        av_freep(filename);
 +        return err;
 +    }
 +    return fd; /* success */
 +}
 +
 +#ifdef TEST
 +
 +#undef printf
 +
 +int main(void)
 +{
 +    uint8_t *buf;
 +    size_t size;
 +    if (av_file_map("file.c", &buf, &size, 0, NULL) < 0)
 +        return 1;
 +
 +    buf[0] = 's';
 +    printf("%s", buf);
 +    av_file_unmap(buf, size);
 +    return 0;
 +}
 +#endif
 +
diff --combined libavutil/file_open.c
index 0000000,765eb60..8a65117
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,93 +1,93 @@@
 - * This file is part of Libav.
+ /*
 - * Libav is free software; you can redistribute it and/or
++ * This file is part of FFmpeg.
+  *
 - * Libav is distributed in the hope that it will be useful,
++ * FFmpeg is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Lesser General Public
+  * License as published by the Free Software Foundation; either
+  * version 2.1 of the License, or (at your option) any later version.
+  *
 - * License along with Libav; if not, write to the Free Software
++ * FFmpeg is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
++ * License along with FFmpeg; if not, write to the Free Software
+  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+  */
+ #include "config.h"
+ #include "internal.h"
+ #include "mem.h"
+ #include <stdarg.h>
+ #include <fcntl.h>
+ #include <sys/stat.h>
+ #if HAVE_UNISTD_H
+ #include <unistd.h>
+ #endif
+ #if HAVE_IO_H
+ #include <io.h>
+ #endif
+ #if defined(_WIN32) && !defined(__MINGW32CE__)
+ #undef open
+ #undef lseek
+ #undef stat
+ #undef fstat
+ #include <windows.h>
+ #include <share.h>
+ #include <errno.h>
+ static int win32_open(const char *filename_utf8, int oflag, int pmode)
+ {
+     int fd;
+     int num_chars;
+     wchar_t *filename_w;
+     /* convert UTF-8 to wide chars */
+     num_chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename_utf8, -1, NULL, 0);
+     if (num_chars <= 0)
+         goto fallback;
+     filename_w = av_mallocz(sizeof(wchar_t) * num_chars);
+     if (!filename_w) {
+         errno = ENOMEM;
+         return -1;
+     }
+     MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, filename_w, num_chars);
+     fd = _wsopen(filename_w, oflag, SH_DENYNO, pmode);
+     av_freep(&filename_w);
+     if (fd != -1 || (oflag & O_CREAT))
+         return fd;
+ fallback:
+     /* filename may be be in CP_ACP */
+     return _sopen(filename_utf8, oflag, SH_DENYNO, pmode);
+ }
+ #define open win32_open
+ #endif
+ int avpriv_open(const char *filename, int flags, ...)
+ {
+     int fd;
+     unsigned int mode = 0;
+     va_list ap;
+     va_start(ap, flags);
+     if (flags & O_CREAT)
+         mode = va_arg(ap, unsigned int);
+     va_end(ap);
+ #ifdef O_CLOEXEC
+     flags |= O_CLOEXEC;
+ #endif
+     fd = open(filename, flags, mode);
+ #if HAVE_FCNTL
+     if (fd != -1)
+         fcntl(fd, F_SETFD, FD_CLOEXEC);
+ #endif
+     return fd;
+ }