23static int savedStdHandleAutoConversionMode[3] = {-1, -1, -1};
25int disableAutoConversion(
int FD) {
26 static const struct f_cnvrt Convert = {
32 return fcntl(FD, F_CONTROL_CVT, &Convert);
35int restoreStdHandleAutoConversion(
int FD) {
36 assert(FD == STDIN_FILENO || FD == STDOUT_FILENO || FD == STDERR_FILENO);
37 if (savedStdHandleAutoConversionMode[FD] == -1)
39 struct f_cnvrt Cvt = {
40 savedStdHandleAutoConversionMode[FD],
44 return (fcntl(FD, F_CONTROL_CVT, &Cvt));
47int enableAutoConversion(
int FD) {
48 struct f_cnvrt Query = {
54 if (fcntl(FD, F_CONTROL_CVT, &Query) == -1)
61 if (Query.pccsid == CCSID_ISO8859_1 &&
62 (Query.fccsid == CCSID_UTF_8 || Query.fccsid == CCSID_ISO8859_1))
66 if ((FD == STDIN_FILENO || FD == STDOUT_FILENO || FD == STDERR_FILENO) &&
67 savedStdHandleAutoConversionMode[FD] == -1)
68 savedStdHandleAutoConversionMode[FD] = Query.cvtcmd;
70 if (FD == STDOUT_FILENO || FD == STDERR_FILENO)
71 Query.cvtcmd = SETCVTON;
73 Query.cvtcmd = SETCVTALL;
76 (FD == STDIN_FILENO || FD == STDOUT_FILENO || FD == STDERR_FILENO)
80 Query.fccsid = (Query.fccsid == FT_UNTAGGED) ? CCSID_IBM_1047 : Query.fccsid;
81 return fcntl(FD, F_CONTROL_CVT, &Query);
84std::error_code llvm::disableAutoConversion(
int FD) {
85 if (::disableAutoConversion(FD) == -1)
88 return std::error_code();
91std::error_code llvm::enableAutoConversion(
int FD) {
92 if (::enableAutoConversion(FD) == -1)
95 return std::error_code();
98std::error_code llvm::restoreStdHandleAutoConversion(
int FD) {
99 if (::restoreStdHandleAutoConversion(FD) == -1)
102 return std::error_code();
105std::error_code llvm::setFileTag(
int FD,
int CCSID,
bool Text) {
106 assert((!Text || (CCSID != FT_UNTAGGED && CCSID != FT_BINARY)) &&
107 "FT_UNTAGGED and FT_BINARY are not allowed for text files");
109 Tag.ft_ccsid = CCSID;
114 if (fcntl(FD, F_SETTAG, &Tag) == -1)
116 return std::error_code();
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::error_code errnoAsErrorCode()
Helper to get errno as an std::error_code.