MCPcopy Create free account
hub / github.com/coreboot/coreboot / create_temp_file

Function create_temp_file

util/cbfstool/flashrom.c:33–61  ·  view source on GitHub ↗

* Helper to create a temporary file. * * @param path_out An output pointer for the filename. Caller should free. * * @return 0 on success, -1 for file open error, or -2 for write error. */

Source from the content-addressed store, hash-verified

31 * @return 0 on success, -1 for file open error, or -2 for write error.
32 */
33static int create_temp_file(char **path_out)
34{
35 int fd;
36 int rv;
37 char *path;
38 mode_t umask_save;
39
40#if defined(__FreeBSD__)
41#define P_tmpdir "/tmp"
42#endif
43 *path_out = NULL;
44 path = strdup(P_tmpdir "/flashrom.XXXXXX");
45 /* Set the umask before mkstemp for security considerations. */
46 umask_save = umask(077);
47 fd = mkstemp(path);
48 umask(umask_save);
49 if (fd < 0) {
50 rv = -1;
51 goto fail;
52 }
53
54 close(fd);
55 *path_out = path;
56
57 return 0;
58fail:
59 free(path);
60 return rv;
61}
62
63static int run_flashrom(const char *const argv[])
64{

Callers 2

flashrom_host_readFunction · 0.85
flashrom_host_writeFunction · 0.85

Calls 2

strdupFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected