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
35int enablezOSAutoConversionCcsid(int FD, int ccsid);
38
39#ifdef __cplusplus
40}
41#endif /* __cplusplus */
42
43#ifdef __cplusplus
44namespace llvm {
45
46#ifdef __MVS__
47
48/** \brief Set the tag information for a file descriptor. */
49std::error_code setzOSFileTag(int FD, int CCSID, bool IsText);
50
51/** \brief Get the the tag ccsid for a file name or a file descriptor. */
52ErrorOr<__ccsid_t> getzOSFileTag(const Twine &FileName, const int FD = -1);
53
54/** \brief Query the file tag to determine if it needs conversion to UTF-8
55 * codepage.
56 */
57ErrorOr<bool> needzOSConversion(const Twine &FileName, const int FD = -1);
58
59/** Copy the tag attributes from \a source to \a destination.
60 *
61 * @param Source The name of the source file.
62 * @param Destination The file descriptor of the destination file.
63 * @returns errc::success if the tag attributes were copied successfully,
64 * otherwise returns a specific error_code.
65 */
66std::error_code copyFileTagAttributes(const std::string &Source,
67 const int DestinationFD);
68
69#endif /* __MVS__*/
70
71inline std::error_code disableAutoConversion(int FD) {
72#ifdef __MVS__
73 if (::disablezOSAutoConversion(FD) == -1)
74 return errnoAsErrorCode();
75#endif
76 return std::error_code();
77}
78
79inline std::error_code enableAutoConversion(int FD) {
80#ifdef __MVS__
81 if (::enablezOSAutoConversion(FD) == -1)
82 return errnoAsErrorCode();
83#endif
84 return std::error_code();
85}
86
87inline std::error_code enableAutoConversion(int FD, int ccsid) {
88#ifdef __MVS__
89 if (::enablezOSAutoConversionCcsid(FD, ccsid) == -1)
90 return errnoAsErrorCode();
91#endif
92 return std::error_code();
93}
94
95inline std::error_code restoreStdHandleAutoConversion(int FD) {
96#ifdef __MVS__
98 return errnoAsErrorCode();
99#endif
100 return std::error_code();
101}
102
103inline std::error_code setFileTag(int FD, int CCSID, bool IsText) {
104#ifdef __MVS__
105 return setzOSFileTag(FD, CCSID, IsText);
106#endif
107 return std::error_code();
108}
109
110inline ErrorOr<bool> needConversion(const Twine &FileName, const int FD = -1) {
111#ifdef __MVS__
112 return needzOSConversion(FileName, FD);
113#endif
114 return false;
115}
116
117} /* namespace llvm */
118#endif /* __cplusplus */
119
120#endif /* LLVM_SUPPORT_AUTOCONVERT_H */
int restorezOSStdHandleAutoConversion(int FD)
int enablezOSAutoConversionCcsid(int FD, int ccsid)
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:1256