• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/core/platform/platform_strings.h"
17 
18 #include <cstdio>
19 #include <cstring>
20 
21 #include <string>
22 #include <vector>
23 
24 #include "tensorflow/core/lib/core/status.h"
25 
26 namespace tensorflow {
27 
GetPlatformStrings(const std::string & path,std::vector<std::string> * found)28 int GetPlatformStrings(const std::string& path,
29                        std::vector<std::string>* found) {
30   int result;
31   FILE* ifp = fopen(path.c_str(), "rb");
32   if (ifp != nullptr) {
33     static const char prefix[] = TF_PLAT_STR_MAGIC_PREFIX_;
34     int first_char = prefix[1];
35     int last_char = -1;
36     int c;
37     while ((c = getc(ifp)) != EOF) {
38       if (c == first_char && last_char == 0) {
39         int i = 2;
40         while (prefix[i] != 0 && (c = getc(ifp)) == prefix[i]) {
41           i++;
42         }
43         if (prefix[i] == 0) {
44           std::string str;
45           while ((c = getc(ifp)) != EOF && c != 0) {
46             str.push_back(c);
47           }
48           if (!str.empty()) {
49             found->push_back(str);
50           }
51         }
52       }
53       last_char = c;
54     }
55 
56     result = (ferror(ifp) == 0) ? 0 : errno;
57     fclose(ifp);
58   } else {
59     result = errno;
60   }
61   return result;
62 }
63 
64 }  // namespace tensorflow
65