| 24 | namespace tensorflow { |
| 25 | |
| 26 | int GetPlatformStrings(const std::string& path, |
| 27 | std::vector<std::string>* found) { |
| 28 | int result; |
| 29 | FILE* ifp = fopen(path.c_str(), "rb"); |
| 30 | if (ifp != nullptr) { |
| 31 | static const char prefix[] = TF_PLAT_STR_MAGIC_PREFIX_; |
| 32 | int first_char = prefix[1]; |
| 33 | int last_char = -1; |
| 34 | int c; |
| 35 | while ((c = getc(ifp)) != EOF) { |
| 36 | if (c == first_char && last_char == 0) { |
| 37 | int i = 2; |
| 38 | while (prefix[i] != 0 && (c = getc(ifp)) == prefix[i]) { |
| 39 | i++; |
| 40 | } |
| 41 | if (prefix[i] == 0) { |
| 42 | std::string str; |
| 43 | while ((c = getc(ifp)) != EOF && c != 0) { |
| 44 | str.push_back(c); |
| 45 | } |
| 46 | if (!str.empty()) { |
| 47 | found->push_back(str); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | last_char = c; |
| 52 | } |
| 53 | |
| 54 | result = (ferror(ifp) == 0) ? 0 : errno; |
| 55 | fclose(ifp); |
| 56 | } else { |
| 57 | result = errno; |
| 58 | } |
| 59 | return result; |
| 60 | } |
| 61 | |
| 62 | } // namespace tensorflow |