blob: 614c0a4a1884f2e2432ac70cd43de489ef086793 [file] [log] [blame]
Julien Boeufcd9b1c82015-02-20 17:40:41 -08001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Julien Boeufcd9b1c82015-02-20 17:40:41 -08004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Julien Boeufcd9b1c82015-02-20 17:40:41 -08008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Julien Boeufcd9b1c82015-02-20 17:40:41 -080010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Julien Boeufcd9b1c82015-02-20 17:40:41 -080016 *
17 */
18
19#include <grpc/support/port_platform.h>
20
Nicolas "Pixel" Noblec4b18a52016-04-15 04:53:54 +020021#ifdef GPR_MSYS_TMPFILE
Julien Boeufcd9b1c82015-02-20 17:40:41 -080022
Nicolas "Pixel" Noblec4b18a52016-04-15 04:53:54 +020023#include <io.h>
24#include <stdio.h>
25#include <string.h>
26#include <tchar.h>
Julien Boeufcd9b1c82015-02-20 17:40:41 -080027
28#include <grpc/support/alloc.h>
29#include <grpc/support/log.h>
Masood Malekghassemi701af602015-06-03 15:01:17 -070030#include <grpc/support/string_util.h>
Julien Boeufcd9b1c82015-02-20 17:40:41 -080031
Yuchen Zeng4594bd92016-05-31 14:06:01 -070032#include "src/core/lib/support/string_windows.h"
Nicolas "Pixel" Noblec4b18a52016-04-15 04:53:54 +020033#include "src/core/lib/support/tmpfile.h"
Julien Boeufcd9b1c82015-02-20 17:40:41 -080034
Nicolas "Pixel" Noblec4b18a52016-04-15 04:53:54 +020035FILE *gpr_tmpfile(const char *prefix, char **tmp_filename_out) {
36 FILE *result = NULL;
37 char tmp_filename[MAX_PATH];
38 UINT success;
39
40 if (tmp_filename_out != NULL) *tmp_filename_out = NULL;
41
42 /* Generate a unique filename with our template + temporary path. */
43 success = GetTempFileNameA(".", prefix, 0, tmp_filename);
44 fprintf(stderr, "success = %d\n", success);
Nicolas "Pixel" Noblec4b18a52016-04-15 04:53:54 +020045
Nicolas "Pixel" Noblef5df6472016-04-23 01:53:46 +020046 if (success) {
47 /* Open a file there. */
48 result = fopen(tmp_filename, "wb+");
49 fprintf(stderr, "result = %p\n", result);
Julien Boeufcd9b1c82015-02-20 17:40:41 -080050 }
Nicolas "Pixel" Noblef5df6472016-04-23 01:53:46 +020051 if (result != NULL && tmp_filename_out) {
Nicolas "Pixel" Noblec4b18a52016-04-15 04:53:54 +020052 *tmp_filename_out = gpr_strdup(tmp_filename);
53 }
54
Julien Boeufcd9b1c82015-02-20 17:40:41 -080055 return result;
56}
57
Nicolas "Pixel" Noblec4b18a52016-04-15 04:53:54 +020058#endif /* GPR_MSYS_TMPFILE */