1 //===- AutoConvert.cpp - Auto conversion between ASCII/EBCDIC -------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains functions used for auto conversion between
10 // ASCII/EBCDIC codepages specific to z/OS.
12 //===----------------------------------------------------------------------===//
16 #include "llvm/Support/AutoConvert.h"
20 std::error_code
llvm::disableAutoConversion(int FD
) {
21 static const struct f_cnvrt Convert
= {
24 (short)FT_BINARY
, // fccsid
26 if (fcntl(FD
, F_CONTROL_CVT
, &Convert
) == -1)
27 return std::error_code(errno
, std::generic_category());
28 return std::error_code();
31 std::error_code
llvm::enableAutoConversion(int FD
) {
32 struct f_cnvrt Query
= {
38 if (fcntl(FD
, F_CONTROL_CVT
, &Query
) == -1)
39 return std::error_code(errno
, std::generic_category());
41 Query
.cvtcmd
= SETCVTALL
;
43 (FD
== STDIN_FILENO
|| FD
== STDOUT_FILENO
|| FD
== STDERR_FILENO
)
46 // Assume untagged files to be IBM-1047 encoded.
47 Query
.fccsid
= (Query
.fccsid
== FT_UNTAGGED
) ? CCSID_IBM_1047
: Query
.fccsid
;
48 if (fcntl(FD
, F_CONTROL_CVT
, &Query
) == -1)
49 return std::error_code(errno
, std::generic_category());
50 return std::error_code();
53 std::error_code
llvm::setFileTag(int FD
, int CCSID
, bool Text
) {
54 assert((!Text
|| (CCSID
!= FT_UNTAGGED
&& CCSID
!= FT_BINARY
)) &&
55 "FT_UNTAGGED and FT_BINARY are not allowed for text files");
58 Tag
.ft_txtflag
= Text
;
62 if (fcntl(FD
, F_SETTAG
, &Tag
) == -1)
63 return std::error_code(errno
, std::generic_category());
64 return std::error_code();