FFmpeg
libavformat
tests
rename.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2026 Christopher Decker
3
*
4
* This file is part of FFmpeg.
5
*
6
* FFmpeg is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
10
*
11
* FFmpeg is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with FFmpeg; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
#include "config.h"
22
23
#include <stdio.h>
24
25
#if HAVE_UNISTD_H
26
#include <unistd.h>
27
#endif
28
29
#include "
libavutil/random_seed.h
"
30
31
#include "
libavformat/os_support.h
"
32
33
static
int
create_file
(
const
char
*path)
34
{
35
FILE *
f
= fopen(path,
"wb"
);
36
if
(!
f
)
37
return
-1;
38
fputs(
"ffmpeg rename test\n"
,
f
);
39
fclose(
f
);
40
return
0;
41
}
42
43
static
int
file_exists
(
const
char
*path)
44
{
45
FILE *
f
= fopen(path,
"rb"
);
46
if
(!
f
)
47
return
0;
48
fclose(
f
);
49
return
1;
50
}
51
52
int
main
(
void
)
53
{
54
char
src
[64];
55
char
dst
[64];
56
unsigned
seed
=
av_get_random_seed
();
57
int
ret
= 0;
58
59
snprintf
(
src
,
sizeof
(
src
),
"ff-rename-test-%08x.src"
,
seed
);
60
snprintf
(
dst
,
sizeof
(
dst
),
"ff-rename-test-%08x.dst"
,
seed
);
61
62
if
(
create_file
(
src
) < 0) {
63
perror(
"create src"
);
64
return
1;
65
}
66
67
/* rename() must follow POSIX semantics and return 0 on success. */
68
if
(rename(
src
,
dst
) != 0) {
69
perror(
"rename"
);
70
ret
= 1;
71
goto
cleanup
;
72
}
73
74
if
(
file_exists
(
src
)) {
75
fprintf(stderr,
"source still exists after rename\n"
);
76
ret
= 1;
77
goto
cleanup
;
78
}
79
80
if
(!
file_exists
(
dst
)) {
81
fprintf(stderr,
"destination missing after rename\n"
);
82
ret
= 1;
83
goto
cleanup
;
84
}
85
86
/* Renaming a nonexistent source must fail with a -1 return. */
87
if
(rename(
src
,
dst
) != -1) {
88
fprintf(stderr,
"rename of nonexistent source unexpectedly succeeded\n"
);
89
ret
= 1;
90
goto
cleanup
;
91
}
92
93
cleanup
:
94
unlink(
src
);
95
unlink(
dst
);
96
return
ret
;
97
}
create_file
static int create_file(const char *path)
Definition:
rename.c:33
main
int main(void)
Definition:
rename.c:52
file_exists
static int file_exists(const char *path)
Definition:
rename.c:43
cleanup
static av_cold void cleanup(FlashSV2Context *s)
Definition:
flashsv2enc.c:130
os_support.h
av_get_random_seed
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
Definition:
random_seed.c:196
seed
static unsigned int seed
Definition:
videogen.c:78
f
f
Definition:
af_crystalizer.c:122
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition:
dsp.h:87
ret
ret
Definition:
filter_design.txt:187
random_seed.h
snprintf
#define snprintf
Definition:
snprintf.h:34
src
#define src
Definition:
vp8dsp.c:248
Generated on Sat Aug 15 2026 03:27:43 for FFmpeg by
1.8.17