1 /*===- AutoConvert.h - Auto conversion between ASCII/EBCDIC -----*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file contains functions used for auto conversion between 10 // ASCII/EBCDIC codepages specific to z/OS. 11 // 12 //===----------------------------------------------------------------------===*/ 13 14 #ifndef LLVM_SUPPORT_AUTOCONVERT_H 15 #define LLVM_SUPPORT_AUTOCONVERT_H 16 17 #ifdef __MVS__ 18 #include <_Ccsid.h> 19 #ifdef __cplusplus 20 #include "llvm/Support/ErrorOr.h" 21 #include <system_error> 22 #endif /* __cplusplus */ 23 24 #define CCSID_IBM_1047 1047 25 #define CCSID_UTF_8 1208 26 #define CCSID_ISO8859_1 819 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif /* __cplusplus */ 31 int enablezOSAutoConversion(int FD); 32 int disablezOSAutoConversion(int FD); 33 int restorezOSStdHandleAutoConversion(int FD); 34 #ifdef __cplusplus 35 } 36 #endif /* __cplusplus */ 37 38 #ifdef __cplusplus 39 namespace llvm { 40 41 /** \brief Disable the z/OS enhanced ASCII auto-conversion for the file 42 * descriptor. 43 */ 44 std::error_code disablezOSAutoConversion(int FD); 45 46 /** \brief Query the z/OS enhanced ASCII auto-conversion status of a file 47 * descriptor and force the conversion if the file is not tagged with a 48 * codepage. 49 */ 50 std::error_code enablezOSAutoConversion(int FD); 51 52 /** Restore the z/OS enhanced ASCII auto-conversion for the std handle. */ 53 std::error_code restorezOSStdHandleAutoConversion(int FD); 54 55 /** \brief Set the tag information for a file descriptor. */ 56 std::error_code setzOSFileTag(int FD, int CCSID, bool Text); 57 58 // Get the the tag ccsid for a file name or a file descriptor. 59 ErrorOr<__ccsid_t> getzOSFileTag(const char *FileName, const int FD = -1); 60 61 // Query the file tag to determine if it needs conversion to UTF-8 codepage. 62 ErrorOr<bool> needzOSConversion(const char *FileName, const int FD = -1); 63 64 } // namespace llvm 65 #endif // __cplusplus 66 67 #endif /* __MVS__ */ 68 69 #endif /* LLVM_SUPPORT_AUTOCONVERT_H */ 70