tmpfile_windows.cc
Go to the documentation of this file.
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 
20 
21 #ifdef GPR_WINDOWS_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>
31 
34 
35 FILE* gpr_tmpfile(const char* prefix, char** tmp_filename_out) {
36  FILE* result = NULL;
37  LPTSTR template_string = NULL;
38  TCHAR tmp_path[MAX_PATH];
39  TCHAR tmp_filename[MAX_PATH];
40  DWORD status;
41  UINT success;
42 
43  if (tmp_filename_out != NULL) *tmp_filename_out = NULL;
44 
45  /* Convert our prefix to TCHAR. */
46  template_string = gpr_char_to_tchar(prefix);
47  GPR_ASSERT(template_string);
48 
49  /* Get the path to the best temporary folder available. */
50  status = GetTempPath(MAX_PATH, tmp_path);
51  if (status == 0 || status > MAX_PATH) goto end;
52 
53  /* Generate a unique filename with our template + temporary path. */
54  success = GetTempFileName(tmp_path, template_string, 0, tmp_filename);
55  if (!success) goto end;
56 
57  /* Open a file there. */
58  if (_tfopen_s(&result, tmp_filename, TEXT("wb+")) != 0) goto end;
59 
60 end:
61  if (result && tmp_filename_out) {
62  *tmp_filename_out = gpr_tchar_to_char(tmp_filename);
63  }
64 
65  gpr_free(template_string);
66  return result;
67 }
68 
69 #endif /* GPR_WINDOWS_TMPFILE */
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
log.h
string.h
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
gpr_tmpfile
FILE * gpr_tmpfile(const char *prefix, char **tmp_filename)
status
absl::Status status
Definition: rls.cc:251
string_util.h
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
PE_SECTION_TYPES::TEXT
@ TEXT
GetTempFileName
static std::string GetTempFileName()
Definition: benchmark/test/output_test_helper.cc:487
tmpfile.h
string_windows.h
benchmark.FILE
FILE
Definition: benchmark.py:21
alloc.h
prefix
static const char prefix[]
Definition: head_of_line_blocking.cc:28
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:40