Revision 1005f542 libavcodec/utils.c

View differences:

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
}

Also available in: Unified diff