Skip to content
Snippets Groups Projects
Commit 2757982c authored by Craig Tiller's avatar Craig Tiller
Browse files

C++ compatibility fix for tmpfile_posix.c

parent f5a1b750
No related branches found
No related tags found
No related merge requests found
...@@ -50,34 +50,34 @@ ...@@ -50,34 +50,34 @@
FILE *gpr_tmpfile(const char *prefix, char **tmp_filename) { FILE *gpr_tmpfile(const char *prefix, char **tmp_filename) {
FILE *result = NULL; FILE *result = NULL;
char *template; char *filename_template;
int fd; int fd;
if (tmp_filename != NULL) *tmp_filename = NULL; if (tmp_filename != NULL) *tmp_filename = NULL;
gpr_asprintf(&template, "/tmp/%s_XXXXXX", prefix); gpr_asprintf(&filename_template, "/tmp/%s_XXXXXX", prefix);
GPR_ASSERT(template != NULL); GPR_ASSERT(filename_template != NULL);
fd = mkstemp(template); fd = mkstemp(filename_template);
if (fd == -1) { if (fd == -1) {
gpr_log(GPR_ERROR, "mkstemp failed for template %s with error %s.", gpr_log(GPR_ERROR, "mkstemp failed for filename_template %s with error %s.",
template, strerror(errno)); filename_template, strerror(errno));
goto end; goto end;
} }
result = fdopen(fd, "w+"); result = fdopen(fd, "w+");
if (result == NULL) { if (result == NULL) {
gpr_log(GPR_ERROR, "Could not open file %s from fd %d (error = %s).", gpr_log(GPR_ERROR, "Could not open file %s from fd %d (error = %s).",
template, fd, strerror(errno)); filename_template, fd, strerror(errno));
unlink(template); unlink(filename_template);
close(fd); close(fd);
goto end; goto end;
} }
end: end:
if (result != NULL && tmp_filename != NULL) { if (result != NULL && tmp_filename != NULL) {
*tmp_filename = template; *tmp_filename = filename_template;
} else { } else {
gpr_free(template); gpr_free(filename_template);
} }
return result; return result;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment