int ff_tempfile(const char *prefix, char **filename) {

    int fd=-1;

#if !HAVE_MKSTEMP

    *filename = tempnam(".", prefix);

#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(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");

        return -1;

    }

#if !HAVE_MKSTEMP

    fd = avpriv_open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);

#else

    snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);

    fd = mkstemp(*filename);

    if (fd < 0) {

        snprintf(*filename, len, "./%sXXXXXX", prefix);

        fd = mkstemp(*filename);

    }

#endif

    /* -----common section-----*/

    if (fd < 0) {

        av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);

        return -1;

    }

    return fd; /* success */

}

int ff_tempfile(const char *prefix, char **filename) {

    int fd=-1;

#if !HAVE_MKSTEMP

    *filename = tempnam(".", prefix);

#else

    size_t len = strlen(prefix) + 12; 

    *filename = av_malloc(len);

#endif

    

    if (*filename == NULL) {

        av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");

        return -1;

    }

#if !HAVE_MKSTEMP

    fd = avpriv_open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);

#else

    snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);

    fd = mkstemp(*filename);

    if (fd < 0) {

        snprintf(*filename, len, "./%sXXXXXX", prefix);

        fd = mkstemp(*filename);

    }

#endif

    

    if (fd < 0) {

        av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);

        return -1;

    }

    return fd; 

}

int FUNC_0(const char *VAR_0, char **VAR_1) {

    int VAR_2=-1;

#if !HAVE_MKSTEMP

    *VAR_1 = tempnam(".", VAR_0);

#else

    size_t len = strlen(VAR_0) + 12; 

    *VAR_1 = av_malloc(len);

#endif

    

    if (*VAR_1 == NULL) {

        av_log(NULL, AV_LOG_ERROR, "FUNC_0: Cannot allocate file name\n");

        return -1;

    }

#if !HAVE_MKSTEMP

    VAR_2 = avpriv_open(*VAR_1, O_RDWR | O_BINARY | O_CREAT, 0444);

#else

    snprintf(*VAR_1, len, "/tmp/%sXXXXXX", VAR_0);

    VAR_2 = mkstemp(*VAR_1);

    if (VAR_2 < 0) {

        snprintf(*VAR_1, len, "./%sXXXXXX", VAR_0);

        VAR_2 = mkstemp(*VAR_1);

    }

#endif

    

    if (VAR_2 < 0) {

        av_log(NULL, AV_LOG_ERROR, "FUNC_0: Cannot open temporary file %s\n", *VAR_1);

        return -1;

    }

    return VAR_2; 

}

int FUNC_0(const char *VAR_0, char **VAR_1) { int VAR_2=-1; #if !HAVE_MKSTEMP
*VAR_1 = tempnam(".", VAR_0); #else
size_t len = strlen(VAR_0) + 12; *VAR_1 = av_malloc(len); #endif
if (*VAR_1 == NULL) { av_log(NULL, AV_LOG_ERROR, "FUNC_0: Cannot allocate file name\n"); return -1; } #if !HAVE_MKSTEMP
VAR_2 = avpriv_open(*VAR_1, O_RDWR | O_BINARY | O_CREAT, 0444); #else
snprintf(*VAR_1, len, "/tmp/%sXXXXXX", VAR_0); VAR_2 = mkstemp(*VAR_1); if (VAR_2 < 0) { snprintf(*VAR_1, len, "./%sXXXXXX", VAR_0); VAR_2 = mkstemp(*VAR_1); } #endif
if (VAR_2 < 0) { av_log(NULL, AV_LOG_ERROR, "FUNC_0: Cannot open temporary file %s\n", *VAR_1); return -1; } return VAR_2; }