diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2019-05-07 22:00:09 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2019-05-07 22:00:27 (GMT) |
commit | 28e53c2498903090182ebeb128347fcd92896cd9 (patch) | |
tree | 0a42fab69404d507b7378e4004228b57fff7c4ce /src | |
parent | 69f08c8dddca6b31b4b3c334246dbbbdcf501701 (diff) |
Appended a suffix to temporary files.
Diffstat (limited to 'src')
-rw-r--r-- | src/analysis/contents/memory.c | 2 | ||||
-rw-r--r-- | src/common/io.c | 20 | ||||
-rw-r--r-- | src/common/io.h | 2 |
3 files changed, 18 insertions, 6 deletions
diff --git a/src/analysis/contents/memory.c b/src/analysis/contents/memory.c index 7406a3a..70003bf 100644 --- a/src/analysis/contents/memory.c +++ b/src/analysis/contents/memory.c @@ -286,7 +286,7 @@ GBinContent *g_memory_content_new(const bin_t *data, phys_t size) result = g_object_new(G_TYPE_MEMORY_CONTENT, NULL); - fd = make_tmp_file("memcnt", &result->storage); + fd = make_tmp_file("memcnt", ".bin", &result->storage); if (fd == -1) goto gmcn_error; status = safe_write(fd, data, size); diff --git a/src/common/io.c b/src/common/io.c index 3ff8278..cfc6b80 100644 --- a/src/common/io.c +++ b/src/common/io.c @@ -332,7 +332,8 @@ int ensure_path_exists(const char *path) /****************************************************************************** * * -* Paramètres : base = préfixe du nom du fichier temporaire à créer. * +* Paramètres : prefix = préfixe du nom du fichier temporaire à créer. * +* suffix = éventuel suffixe à coller au nom de fichier. * * filename = chemin d'accès complet au nouveau fichier. [OUT] * * * * Description : Met en place un fichier temporaire. * @@ -343,23 +344,34 @@ int ensure_path_exists(const char *path) * * ******************************************************************************/ -int make_tmp_file(const char *base, char **filename) +int make_tmp_file(const char *prefix, const char *suffix, char **filename) { int result; /* Flux ou code à retourner */ const char *tmpdir; /* Répertoire d'accueil */ bool status; /* Bilan d'un consultation */ + size_t slen; /* Taille du suffixe */ status = g_generic_config_get_value(get_main_configuration(), MPK_TMPDIR, &tmpdir); if (!status) return -1; - asprintf(filename, "%s" G_DIR_SEPARATOR_S "%s-%d.XXXXXX", tmpdir, base, getpid()); + slen = strlen(suffix); + + if (slen > 0) + asprintf(filename, "%s" G_DIR_SEPARATOR_S "%s-%d.XXXXXX.%s", tmpdir, prefix, getpid(), suffix); + else + asprintf(filename, "%s" G_DIR_SEPARATOR_S "%s-%d.XXXXXX", tmpdir, prefix, getpid()); result = ensure_path_exists(*filename); if (result == 0) { - result = mkstemp(*filename); + if (slen > 0) + result = mkstemps(*filename, strlen(suffix) + 1); + else + result = mkstemp(*filename); + if (result == -1) perror("mkstemp"); + } if (result == -1) diff --git a/src/common/io.h b/src/common/io.h index f6b7e51..b4e2211 100644 --- a/src/common/io.h +++ b/src/common/io.h @@ -51,7 +51,7 @@ bool safe_send(int, const void *, size_t, int); int ensure_path_exists(const char *); /* Met en place un fichier temporaire. */ -int make_tmp_file(const char *, char **); +int make_tmp_file(const char *, const char *, char **); /* Met en place un canal UNIX temporaire. */ bool build_tmp_socket(const char *, struct sockaddr_un *); |