LLVM 23.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/** Copy the tag attributes from \a source to \a destination.
59 *
60 * @param Source The name of the source file.
61 * @param Destination The file descriptor of the destination file.
62 * @returns errc::success if the tag attributes were copied successfully,
63 * otherwise returns a specific error_code.
64 */
65std::error_code copyFileTagAttributes(const std::string &Source,
66 const int DestinationFD);
67
68#endif /* __MVS__*/
69
70inline std::error_code disableAutoConversion(int FD) {
71#ifdef __MVS__
72 if (::disablezOSAutoConversion(FD) == -1)
73 return errnoAsErrorCode();
74#endif
75 return std::error_code();
76}
77
78inline std::error_code enableAutoConversion(int FD) {
79#ifdef __MVS__
80 if (::enablezOSAutoConversion(FD) == -1)
81 return errnoAsErrorCode();
82#endif
83 return std::error_code();
84}
85
86inline std::error_code restoreStdHandleAutoConversion(int FD) {
87#ifdef __MVS__
89 return errnoAsErrorCode();
90#endif
91 return std::error_code();
92}
93
94inline std::error_code setFileTag(int FD, int CCSID, bool Text) {
95#ifdef __MVS__
96 return setzOSFileTag(FD, CCSID, Text);
97#endif
98 return std::error_code();
99}
100
101inline ErrorOr<bool> needConversion(const Twine &FileName, const int FD = -1) {
102#ifdef __MVS__
103 return needzOSConversion(FileName, FD);
104#endif
105 return false;
106}
107
108} /* namespace llvm */
109#endif /* __cplusplus */
110
111#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.
Definition Types.h:26
std::error_code errnoAsErrorCode()
Helper to get errno as an std::error_code.
Definition Error.h:1240