25static int savedStdHandleAutoConversionMode[3] = {-1, -1, -1};
27int disablezOSAutoConversion(
int FD) {
28 static const struct f_cnvrt Convert = {
34 return fcntl(FD, F_CONTROL_CVT, &Convert);
37int restorezOSStdHandleAutoConversion(
int FD) {
38 assert(FD == STDIN_FILENO || FD == STDOUT_FILENO || FD == STDERR_FILENO);
39 if (savedStdHandleAutoConversionMode[FD] == -1)
41 struct f_cnvrt Cvt = {
42 savedStdHandleAutoConversionMode[FD],
46 return (fcntl(FD, F_CONTROL_CVT, &Cvt));
49int enablezOSAutoConversion(
int FD) {
50 struct f_cnvrt Query = {
56 if (fcntl(FD, F_CONTROL_CVT, &Query) == -1)
63 if (Query.pccsid == CCSID_ISO8859_1 &&
64 (Query.fccsid == CCSID_UTF_8 || Query.fccsid == CCSID_ISO8859_1))
68 if ((FD == STDIN_FILENO || FD == STDOUT_FILENO || FD == STDERR_FILENO) &&
69 savedStdHandleAutoConversionMode[FD] == -1)
70 savedStdHandleAutoConversionMode[FD] = Query.cvtcmd;
72 if (FD == STDOUT_FILENO || FD == STDERR_FILENO)
73 Query.cvtcmd = SETCVTON;
75 Query.cvtcmd = SETCVTALL;
78 (FD == STDIN_FILENO || FD == STDOUT_FILENO || FD == STDERR_FILENO)
82 Query.fccsid = (Query.fccsid == FT_UNTAGGED) ? CCSID_IBM_1047 : Query.fccsid;
83 return fcntl(FD, F_CONTROL_CVT, &Query);
86std::error_code llvm::disablezOSAutoConversion(
int FD) {
87 if (::disablezOSAutoConversion(FD) == -1)
90 return std::error_code();
93std::error_code llvm::enablezOSAutoConversion(
int FD) {
94 if (::enablezOSAutoConversion(FD) == -1)
97 return std::error_code();
100std::error_code llvm::restorezOSStdHandleAutoConversion(
int FD) {
101 if (::restorezOSStdHandleAutoConversion(FD) == -1)
104 return std::error_code();
107std::error_code llvm::setzOSFileTag(
int FD,
int CCSID,
bool Text) {
108 assert((!Text || (CCSID != FT_UNTAGGED && CCSID != FT_BINARY)) &&
109 "FT_UNTAGGED and FT_BINARY are not allowed for text files");
111 Tag.ft_ccsid = CCSID;
116 if (fcntl(FD, F_SETTAG, &Tag) == -1)
118 return std::error_code();
125 struct f_cnvrt Query = {
130 if (fcntl(FD, F_CONTROL_CVT, &Query) == -1)
131 return std::error_code(errno, std::generic_category());
135 if (stat(FileName, &Attr) == -1)
136 return std::error_code(errno, std::generic_category());
137 return Attr.st_tag.ft_ccsid;
140ErrorOr<bool> llvm::needzOSConversion(
const char *FileName,
const int FD) {
142 if (std::error_code EC = Ccsid.
getError())
149 case CCSID_ISO8859_1:
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represents either an error or a value T.
std::error_code getError() const
This is an optimization pass for GlobalISel generic memory operations.
std::error_code errnoAsErrorCode()
Helper to get errno as an std::error_code.