diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-17 19:43:03 -0600 |
|---|---|---|
| committer | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-17 19:43:03 -0600 |
| commit | 9bdfdf1679339e87f90e4df9e5a73f0e6969aaa9 (patch) | |
| tree | 83d5c56a17c9a6b64b6439fa2f6a12df3642c064 /src/sys_zos.c | |
| parent | 33c0062615e9c06bc799d77720423e7d9a176833 (diff) | |
| download | zash-9bdfdf1679339e87f90e4df9e5a73f0e6969aaa9.tar.gz | |
z/OS ASCII build: convert own I/O to IBM-1047 on pipes, here-docs, redirects, std streams
Diffstat (limited to 'src/sys_zos.c')
| -rw-r--r-- | src/sys_zos.c | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/src/sys_zos.c b/src/sys_zos.c index 9d405d3..b4fe804 100644 --- a/src/sys_zos.c +++ b/src/sys_zos.c @@ -193,6 +193,32 @@ static void tag_text(int fd, int ccsid) { } /** + * @brief Convert this process's I/O on `fd` between its own CCSID and + * IBM-1047. + * + * Automatic conversion for a descriptor is decided when it is opened, from + * the tag then in force. A pipe, a here-document file the shell tags + * after creating it, and a standard stream inherited untagged all miss + * that, so an ASCII zash would write ASCII bytes where EBCDIC readers + * (and EBCDIC writers on the same file) expect IBM-1047. The first z/OS + * run of the suite showed exactly that: `echo x | wc -l` counted 0 lines. + * + * pccsid 0 means "the CCSID of the program doing the I/O", so the setting + * is harmless if it is shared with a child through the open file: an + * EBCDIC child converts 1047 to 1047. + * + * VERIFY: pccsid 0 is resolved per process, as described above. + */ +static void cvt_1047(int fd) { + struct f_cnvrt cv; + memset(&cv, 0, sizeof cv); + cv.cvtcmd = SETCVTON; + cv.pccsid = 0; + cv.fccsid = 1047; + fcntl(fd, F_CONTROL_CVT, &cv); +} + +/** * @brief Apply tagging or conversion control to a file a redirection has * just opened. * @@ -277,20 +303,25 @@ void sys_redir_tag(int fd, tag_stream stream, tag_mode mode, bool created) { static void pipe_tag(int fd[2]) { if (tag_redir[TAG_OUT] != TAG_UNSET) tag_deferred(fd[1], tag_redir[TAG_OUT] == TAG_TXT); - else if (ZASH_ASCII && opt.pipetag) + else if (ZASH_ASCII && opt.pipetag) { tag_text(fd[1], 1047); + cvt_1047(fd[0]); /* $( ) and `read` get EBCDIC writers' text */ + cvt_1047(fd[1]); /* builtins write ASCII */ + } } /** * @brief Tag a temporary file that will carry a here-document. * - * In an ASCII build the file is tagged IBM-1047 text before the shell - * writes to it, so the text is EBCDIC on disk and any reader gets its own - * character set. Nothing to do in an EBCDIC build. + * In an ASCII build the file is tagged IBM-1047 text, and the shell's own + * writes and reads are converted, so the text is EBCDIC on disk and any + * reader gets its own character set. Nothing to do in an EBCDIC build. */ void sys_tmp_tag(int fd) { - if (ZASH_ASCII) + if (ZASH_ASCII) { tag_text(fd, 1047); + cvt_1047(fd); + } } /** |
