================
@@ -114,6 +115,31 @@ inline ErrorOr<bool> needConversion(const Twine &FileName, 
const int FD = -1) {
   return false;
 }
 
+inline ErrorOr<SmallString<32>>
+getEncodingNameFromFileTag(const Twine &FileName, const int FD = -1) {
+#ifdef __MVS__
+  ErrorOr<__ccsid_t> TagOrErr = getzOSFileTag(FileName, FD);
+  if (!TagOrErr)
+    return TagOrErr.getError();
+
+  __ccsid_t Tag = *TagOrErr;
+  if (Tag == 0)
+    return SmallString<32>(); // Return empty string for no tag
+
+  if (Tag == 1208)
+    return SmallString<32>("utf-8");
+
+  if (Tag == 1047)
+    return SmallString<32>("ibm-1047");
+
+  SmallString<32> Result;
+  raw_svector_ostream(Result) << Tag;
+  return Result;
----------------
cor3ntin wrote:

That does not feel like a good default behavior.

I'm not fsuper familiar with IBM platforms but according to some docs

- There may be constant you can use
```
_CSTYPE_EBCDIC
_CSTYPE_ASCII
_CSTYPE_UCS2
_CSTYPE_UTF8
_CSTYPE_UTF16
_CSTYPE_UTF32
```

- It would probably be reasonable to map ASCII to UTF-8.
- UCS2, UTF-16, UTF32 should be mapped to empty string - I don't think we have 
any desire to support double width input encodings.

https://github.com/llvm/llvm-project/pull/206519
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to