1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // 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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // 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.
16 //
17 //
18 
19 #include <grpc/support/port_platform.h>
20 
21 #ifdef GPR_MSYS_TMPFILE
22 
23 #include <io.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <tchar.h>
27 
28 #include <grpc/support/alloc.h>
29 #include <grpc/support/log.h>
30 #include <grpc/support/string_util.h>
31 
32 #include "src/core/lib/gpr/string_windows.h"
33 #include "src/core/lib/gpr/tmpfile.h"
34 #include "src/core/lib/gprpp/crash.h"
35 
gpr_tmpfile(const char * prefix,char ** tmp_filename_out)36 FILE* gpr_tmpfile(const char* prefix, char** tmp_filename_out) {
37   FILE* result = NULL;
38   char tmp_filename[MAX_PATH];
39   UINT success;
40 
41   if (tmp_filename_out != NULL) *tmp_filename_out = NULL;
42 
43   // Generate a unique filename with our template + temporary path.
44   success = GetTempFileNameA(".", prefix, 0, tmp_filename);
45   fprintf(stderr, "success = %d\n", success);
46 
47   if (success) {
48     // Open a file there.
49     result = fopen(tmp_filename, "wb+");
50     fprintf(stderr, "result = %p\n", result);
51   }
52   if (result != NULL && tmp_filename_out) {
53     *tmp_filename_out = gpr_strdup(tmp_filename);
54   }
55 
56   return result;
57 }
58 
59 #endif  // GPR_MSYS_TMPFILE
60