summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-05-07 22:00:09 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-05-07 22:00:27 (GMT)
commit28e53c2498903090182ebeb128347fcd92896cd9 (patch)
tree0a42fab69404d507b7378e4004228b57fff7c4ce /src/common
parent69f08c8dddca6b31b4b3c334246dbbbdcf501701 (diff)
Appended a suffix to temporary files.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/io.c20
-rw-r--r--src/common/io.h2
2 files changed, 17 insertions, 5 deletions
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 *);