LLVM 22.0.0git
AutoConvert.h
Go to the documentation of this file.
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#endif
20#ifdef __cplusplus
21#include "llvm/Support/Error.h"
22#include <system_error>
23#endif /* __cplusplus */
24
25#define CCSID_IBM_1047 1047
26#define CCSID_UTF_8 1208
27#define CCSID_ISO8859_1 819
28
29#ifdef __cplusplus
30extern "C" {
31#endif /* __cplusplus */
32
36
37#ifdef __cplusplus
38}
39#endif /* __cplusplus */
40
41#ifdef __cplusplus
42namespace llvm {
43
44#ifdef __MVS__
45
46/** \brief Set the tag information for a file descriptor. */
47std::error_code setzOSFileTag(int FD, int CCSID, bool Text);
48
49/** \brief Get the the tag ccsid for a file name or a file descriptor. */
50ErrorOr<__ccsid_t> getzOSFileTag(const char *FileName, const int FD = -1);
51
52/** \brief Query the file tag to determine if it needs conversion to UTF-8
53 * codepage.
54 */
55ErrorOr<bool> needzOSConversion(const char *FileName, const int FD = -1);
56
57#endif /* __MVS__*/
58
59inline std::error_code disableAutoConversion(int FD) {
60#ifdef __MVS__
61 if (::disablezOSAutoConversion(FD) == -1)
62 return errnoAsErrorCode();
63#endif
64 return std::error_code();
65}
66
67inline std::error_code enableAutoConversion(int FD) {
68#ifdef __MVS__
69 if (::enablezOSAutoConversion(FD) == -1)
70 return errnoAsErrorCode();
71#endif
72 return std::error_code();
73}
74
75inline std::error_code restoreStdHandleAutoConversion(int FD) {
76#ifdef __MVS__
78 return errnoAsErrorCode();
79#endif
80 return std::error_code();
81}
82
83inline std::error_code setFileTag(int FD, int CCSID, bool Text) {
84#ifdef __MVS__
85 return setzOSFileTag(FD, CCSID, Text);
86#endif
87 return std::error_code();
88}
89
90inline ErrorOr<bool> needConversion(const char *FileName, const int FD = -1) {
91#ifdef __MVS__
92 return needzOSConversion(FileName, FD);
93#endif
94 return false;
95}
96
97} /* namespace llvm */
98#endif /* __cplusplus */
99
100#endif /* LLVM_SUPPORT_AUTOCONVERT_H */
int restorezOSStdHandleAutoConversion(int FD)
int enablezOSAutoConversion(int FD)
int disablezOSAutoConversion(int FD)
Represents either an error or a value T.
Definition ErrorOr.h:56
This is an optimization pass for GlobalISel generic memory operations.
std::error_code errnoAsErrorCode()
Helper to get errno as an std::error_code.
Definition Error.h:1240