Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions mz_os_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ int32_t mz_os_is_symlink(const char *path) {
int32_t mz_os_make_symlink(const char *path, const char *target_path) {
#if defined(NO_SYMLINK)
return MZ_SUPPORT_ERROR;
#else
#else
if (symlink(target_path, path) != 0)
return MZ_INTERNAL_ERROR;
return MZ_OK;
Expand All @@ -352,6 +352,7 @@ int32_t mz_os_read_symlink(const char *path, char *target_path, int32_t max_targ

int32_t mz_os_get_temp_path(char *path, int32_t max_path, const char *prefix) {
const char *tmp_dir = NULL;
char *temp_path = (char *)calloc(max_path, sizeof(char));
int32_t result = 0;

if (!path || max_path <= 0)
Expand All @@ -365,15 +366,30 @@ int32_t mz_os_get_temp_path(char *path, int32_t max_path, const char *prefix) {
if (!tmp_dir)
tmp_dir = "/tmp";

/* Build template path for mktemp: <tmp_dir>/<prefix>XXXXXX */
result = snprintf(path, max_path, "%s/%sXXXXXX", tmp_dir, prefix ? prefix : "");
if (result < 0 || result >= max_path)
/* Build template path for mkdtemp: <tmp_dir>/<prefix>XXXXXX */
result = snprintf(temp_path, max_path, "%s/%sXXXXXX", tmp_dir, prefix ? prefix : "");
if (result < 0 || result >= max_path) {
free(temp_path);
return MZ_BUF_ERROR;
}

/* mktemp replaces XXXXXX with unique characters */
if (!mktemp(path))
/* Create a temporary directory.
mkdtemp replaces XXXXXX with unique characters
*/
if (!mkdtemp(temp_path)) {
free(temp_path);
return MZ_INTERNAL_ERROR;
}

/* Create a filename inside the temporary directory */
/* Use current time for the filename */
result = snprintf(path, max_path, "%s/%lux", temp_path, time(NULL));
if (result < 0 || result >= max_path) {
free(temp_path);
return MZ_BUF_ERROR;
}

free(temp_path);
return MZ_OK;
}

Expand Down
Loading