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/ADT/Twine.h"
22#include "llvm/Support/Error.h"
23#include <system_error>
24#endif /* __cplusplus */
25
26#define CCSID_IBM_1047 1047
27#define CCSID_UTF_8 1208
28#define CCSID_ISO8859_1 819
29
30#ifdef __cplusplus
31extern "C" {
32#endif /* __cplusplus */
33
37
38#ifdef __cplusplus
39}
40#endif /* __cplusplus */
41
42#ifdef __cplusplus
43namespace llvm {
44
45#ifdef __MVS__
46
47/** \brief Set the tag information for a file descriptor. */
48std::error_code setzOSFileTag(int FD, int CCSID, bool Text);
49
50/** \brief Get the the tag ccsid for a file name or a file descriptor. */
51ErrorOr<__ccsid_t> getzOSFileTag(const Twine &FileName, const int FD = -1);
52
53/** \brief Query the file tag to determine if it needs conversion to UTF-8
54 * codepage.
55 */
56ErrorOr<bool> needzOSConversion(const Twine &FileName, const int FD = -1);
57
58#endif /* __MVS__*/
59
60inline std::error_code disableAutoConversion(int FD) {
61#ifdef __MVS__
62 if (::disablezOSAutoConversion(FD) == -1)
63 return errnoAsErrorCode();
64#endif
65 return std::error_code();
66}
67
68inline std::error_code enableAutoConversion(int FD) {
69#ifdef __MVS__
70 if (::enablezOSAutoConversion(FD) == -1)
71 return errnoAsErrorCode();
72#endif
73 return std::error_code();
74}
75
76inline std::error_code restoreStdHandleAutoConversion(int FD) {
77#ifdef __MVS__
79 return errnoAsErrorCode();
80#endif
81 return std::error_code();
82}
83
84inline std::error_code setFileTag(int FD, int CCSID, bool Text) {
85#ifdef __MVS__
86 return setzOSFileTag(FD, CCSID, Text);
87#endif
88 return std::error_code();
89}
90
91inline ErrorOr<bool> needConversion(const Twine &FileName, const int FD = -1) {
92#ifdef __MVS__
93 return needzOSConversion(FileName, FD);
94#endif
95 return false;
96}
97
98} /* namespace llvm */
99#endif /* __cplusplus */
100
101#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
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
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