Mercurial > libavcodec.hg
comparison utils.c @ 3233:18af2f7788c6 libavcodec
- Add new file internal.h for common internal-use-only functions.
- Add new function av_tempfile() for creating temporary files; contains
workaround for MinGW.
- Make XviD stuff use av_tempfile().
author | corey |
---|---|
date | Thu, 30 Mar 2006 04:33:05 +0000 |
parents | 47f2f56a6a28 |
children | f1bcb9ae510b |
comparison
equal
deleted
inserted
replaced
3232:b9f906a0b0f8 | 3233:18af2f7788c6 |
---|---|
31 #include "opt.h" | 31 #include "opt.h" |
32 #include "crc.h" | 32 #include "crc.h" |
33 #include <stdarg.h> | 33 #include <stdarg.h> |
34 #include <limits.h> | 34 #include <limits.h> |
35 #include <float.h> | 35 #include <float.h> |
36 #ifdef CONFIG_WIN32 | |
37 #include <fcntl.h> | |
38 #endif | |
36 | 39 |
37 const uint8_t ff_reverse[256]={ | 40 const uint8_t ff_reverse[256]={ |
38 0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0, | 41 0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0, |
39 0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8, | 42 0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8, |
40 0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4, | 43 0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4, |
1347 } | 1350 } |
1348 *s = v; | 1351 *s = v; |
1349 n++; | 1352 n++; |
1350 return n; | 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 } |