C++ compatibility fix for tmpfile_posix.c

pull/10777/head
Craig Tiller 8 years ago
parent f5a1b75065
commit 2757982c63
  1. 20
      src/core/lib/support/tmpfile_posix.c

@ -50,34 +50,34 @@
FILE *gpr_tmpfile(const char *prefix, char **tmp_filename) {
FILE *result = NULL;
char *template;
char *filename_template;
int fd;
if (tmp_filename != NULL) *tmp_filename = NULL;
gpr_asprintf(&template, "/tmp/%s_XXXXXX", prefix);
GPR_ASSERT(template != NULL);
gpr_asprintf(&filename_template, "/tmp/%s_XXXXXX", prefix);
GPR_ASSERT(filename_template != NULL);
fd = mkstemp(template);
fd = mkstemp(filename_template);
if (fd == -1) {
gpr_log(GPR_ERROR, "mkstemp failed for template %s with error %s.",
template, strerror(errno));
gpr_log(GPR_ERROR, "mkstemp failed for filename_template %s with error %s.",
filename_template, strerror(errno));
goto end;
}
result = fdopen(fd, "w+");
if (result == NULL) {
gpr_log(GPR_ERROR, "Could not open file %s from fd %d (error = %s).",
template, fd, strerror(errno));
unlink(template);
filename_template, fd, strerror(errno));
unlink(filename_template);
close(fd);
goto end;
}
end:
if (result != NULL && tmp_filename != NULL) {
*tmp_filename = template;
*tmp_filename = filename_template;
} else {
gpr_free(template);
gpr_free(filename_template);
}
return result;
}

Loading…
Cancel
Save