Revision 1005f542

View differences:

libavcodec/internal.h
1
#ifndef INTERNAL_H
2
#define INTERNAL_H
3

  
4
/**
5
 * @file internal.h
6
 * common functions for internal libavcodec use
7
 */
8

  
9

  
10
int av_tempfile(char *prefix, char **filename);
11

  
12
#endif /* INTERNAL_H */
libavcodec/utils.c
33 33
#include <stdarg.h>
34 34
#include <limits.h>
35 35
#include <float.h>
36
#ifdef CONFIG_WIN32
37
#include <fcntl.h>
38
#endif
36 39

  
37 40
const uint8_t ff_reverse[256]={
38 41
0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
......
1349 1352
    n++;
1350 1353
    return n;
1351 1354
}
1355

  
1356
/* Wrapper to work around the lack of mkstemp() on mingw/cygin.
1357
 * Also, tries to create file in /tmp first, if possible.
1358
 * *prefix can be a character constant; *filename will be allocated internally.
1359
 * Returns file descriptor of opened file (or -1 on error)
1360
 * and opened file name in **filename. */
1361
int av_tempfile(char *prefix, char **filename) {
1362
    int fd=-1;
1363
#ifdef CONFIG_WIN32
1364
    *filename = tempnam(".", prefix);
1365
#else
1366
    size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
1367
    *filename = av_malloc(len * sizeof(char));
1368
#endif
1369
    /* -----common section-----*/
1370
    if (*filename == NULL) {
1371
        av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
1372
        return -1;
1373
    }
1374
#ifdef CONFIG_WIN32
1375
    fd = open(*filename, _O_RDWR | _O_BINARY | _O_CREAT, 0444);
1376
#else
1377
    snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
1378
    fd = mkstemp(*filename);
1379
    if (fd < 0) {
1380
        snprintf(*filename, len, "./%sXXXXXX", prefix);
1381
        fd = mkstemp(*filename);
1382
    }
1383
#endif
1384
    /* -----common section-----*/
1385
    if (fd < 0) {
1386
        av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
1387
        return -1;
1388
    }
1389
    return fd; /* success */
1390
}
libavcodec/xvid_rc.c
21 21
#include <xvid.h>
22 22
#include <unistd.h>
23 23
#include "avcodec.h"
24
#include "internal.h"
24 25
//#include "dsputil.h"
25 26
#include "mpegvideo.h"
26 27

  
......
37 38

  
38 39
//xvid_debug=-1;
39 40

  
40
    tmp_name= av_strdup("/tmp/xvidrc.XXXXXX");
41
    fd = mkstemp(tmp_name);
42
    if(fd < 0){
43
        strcpy(tmp_name, "./xvidrc.XXXXXX");
44
        fd = mkstemp(tmp_name);
41
    fd=av_tempfile("xvidrc.", &tmp_name);
42
    if (fd == -1) {
43
        av_log(NULL, AV_LOG_ERROR, "Can't create temporary pass2 file.\n");
44
        return -1;
45 45
    }
46 46

  
47 47
    for(i=0; i<s->rc_context.num_entries; i++){
libavcodec/xvidff.c
27 27
#include <unistd.h>
28 28
#include "common.h"
29 29
#include "avcodec.h"
30
#ifdef CONFIG_WIN32
31
#include <fcntl.h>
32
#endif
30
#include "internal.h"
33 31

  
34 32
/**
35 33
 * Buffer management macros.
......
229 227
        rc2pass2.version = XVID_VERSION;
230 228
        rc2pass2.bitrate = avctx->bit_rate;
231 229

  
232
#ifdef CONFIG_WIN32 /* Ugly work around */
233
        {
234
           char *tempname;
235

  
236
           tempname = tempnam(".", "xvidff");
237
            fd = -1;
238
            if( tempname &&
239
                (fd = open(tempname, _O_RDWR | _O_BINARY)) != -1 ) {
240
                x->twopassfile = av_strdup(tempname);
241
#undef free
242
                free(tempname);
243
#define free please_use_av_free
244
                if( x->twopassfile == NULL ) {
245
                    av_log(avctx, AV_LOG_ERROR,
246
                        "XviD: Cannot allocate 2-pass buffer\n");
247
                    return -1;
248
                }
249
            }
250
       }
251
#else
252
        x->twopassfile = av_malloc(BUFFER_SIZE);
253
        if( x->twopassfile == NULL ) {
254
            av_log(avctx, AV_LOG_ERROR,
255
                "XviD: Cannot allocate 2-pass buffer\n");
256
            return -1;
257
        }
258
        strcpy(x->twopassfile, "/tmp/xvidff.XXXXXX");
259
        fd = mkstemp(x->twopassfile);
260
        if(fd < 0){
261
            strcpy(x->twopassfile, "./xvidff.XXXXXX");
262
            fd = mkstemp(x->twopassfile);
263
        }
264
#endif
230
        fd = av_tempfile("xvidff.", &(x->twopassfile));
265 231
        if( fd == -1 ) {
266 232
            av_log(avctx, AV_LOG_ERROR,
267 233
                "XviD: Cannot write 2-pass pipe\n");

Also available in: Unified diff