-
Notifications
You must be signed in to change notification settings - Fork 1
Add _ENCODE_FILE_EXISTING variable #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -761,6 +761,20 @@ int __tag_new_file(int fd) { | |
| return __chgfdccsid(fd, ccsid); | ||
| } | ||
|
|
||
| int __tag_existing_file(int fd) { | ||
| char* encode_file_existing = getenv("_ENCODE_FILE_EXISTING"); | ||
|
|
||
| if (!encode_file_existing) { | ||
| return 0; | ||
| } | ||
|
|
||
| if (strcmp(encode_file_existing, "BINARY") == 0) { | ||
| return __setfdbinary(fd); | ||
| } | ||
|
|
||
| return __chgfdcodeset(fd, encode_file_existing); | ||
| } | ||
|
|
||
| int __chgfdcodeset(int fd, char* codeset) { | ||
| unsigned short ccsid = __toCcsid(codeset); | ||
| if (!ccsid) | ||
|
|
@@ -877,6 +891,8 @@ int __open_ascii(const char *filename, int opts, ...) { | |
| } | ||
| // Enable auto-conversion of untagged files | ||
| else if (S_ISREG(sb.st_mode)) { | ||
| __tag_existing_file(fd); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Severity: medium Other Locations
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| errno = old_errno; | ||
| struct file_tag *t = &sb.st_tag; | ||
| if (t->ft_txtflag == 0 && (t->ft_ccsid == 0 || t->ft_ccsid == 1047) && | ||
| (opts & O_RDONLY) != 0) { | ||
|
|
@@ -920,6 +936,8 @@ FILE *__fopen_ascii(const char *filename, const char *mode) { | |
| } | ||
| // Enable auto-conversion of untagged files | ||
| else if (S_ISREG(sb.st_mode)) { | ||
| __tag_existing_file(fd); | ||
| errno = old_errno; | ||
| struct file_tag *t = &sb.st_tag; | ||
| if (t->ft_txtflag == 0 && (t->ft_ccsid == 0 || t->ft_ccsid == 1047) && | ||
| strcmp(mode, "r") == 0) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,6 +179,66 @@ TEST_F(CLIBOverrides, open) { | |
| EXPECT_EQ(__getfdccsid(fd), 0x10000 + 819); | ||
| memset(buff2, 1, sizeof(buff)); | ||
| read(fd, buff2, sizeof(buff)); | ||
|
|
||
| // Delete and re-open temp_path _ENCODE_FILE_NEW=UTF-8 | ||
| setenv("_ENCODE_FILE_NEW", "UTF-8", 1); | ||
| remove(temp_path); | ||
| fd = open(temp_path, O_CREAT | O_WRONLY, 0777); | ||
| EXPECT_EQ(__getfdccsid(fd), 0x10000 + 1208); | ||
| write(fd, buff, sizeof(buff)); | ||
| close(fd); | ||
|
|
||
| fd = open(temp_path, O_RDONLY); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| EXPECT_EQ(__getfdccsid(fd), 0x10000 + 1208); | ||
| memset(buff2, 1, sizeof(buff)); | ||
| read(fd, buff2, sizeof(buff)); | ||
| EXPECT_EQ(strcmp(buff, buff2), 0); | ||
|
|
||
| // Test _ENCODE_FILE_EXISTING with IBM-1047 | ||
| unsetenv("_ENCODE_FILE_NEW"); | ||
| remove(temp_path); | ||
| fd = open(temp_path, O_CREAT | O_WRONLY, 0777); | ||
| write(fd, buff, sizeof(buff)); | ||
| close(fd); | ||
|
|
||
| setenv("_ENCODE_FILE_EXISTING", "IBM-1047", 1); | ||
| fd = open(temp_path, O_RDONLY); | ||
| EXPECT_EQ(__getfdccsid(fd), 0x10000 + 1047); | ||
| memset(buff2, 1, sizeof(buff)); | ||
| read(fd, buff2, sizeof(buff)); | ||
| EXPECT_EQ(strcmp(buff, buff2), 0); | ||
| close(fd); | ||
|
|
||
| // Test _ENCODE_FILE_EXISTING with BINARY | ||
| setenv("_ENCODE_FILE_EXISTING", "BINARY", 1); | ||
| fd = open(temp_path, O_RDONLY); | ||
| EXPECT_EQ(__getfdccsid(fd), 65535); | ||
| memset(buff2, 1, sizeof(buff)); | ||
| read(fd, buff2, sizeof(buff)); | ||
| EXPECT_EQ(strcmp(buff, buff2), 0); | ||
| close(fd); | ||
|
|
||
| // Test _ENCODE_FILE_EXISTING with ISO8859-1 | ||
| setenv("_ENCODE_FILE_EXISTING", "ISO8859-1", 1); | ||
| fd = open(temp_path, O_RDONLY); | ||
| EXPECT_EQ(__getfdccsid(fd), 0x10000 + 819); | ||
| memset(buff2, 1, sizeof(buff)); | ||
| read(fd, buff2, sizeof(buff)); | ||
| EXPECT_EQ(strcmp(buff, buff2), 0); | ||
| close(fd); | ||
|
|
||
| // Test _ENCODE_FILE_EXISTING with UTF-8 | ||
| setenv("_ENCODE_FILE_EXISTING", "UTF-8", 1); | ||
| fd = open(temp_path, O_RDONLY); | ||
| EXPECT_EQ(__getfdccsid(fd), 0x10000 + 1208); | ||
| memset(buff2, 1, sizeof(buff)); | ||
| read(fd, buff2, sizeof(buff)); | ||
| EXPECT_EQ(strcmp(buff, buff2), 0); | ||
| close(fd); | ||
|
|
||
| unsetenv("_ENCODE_FILE_EXISTING"); | ||
|
|
||
|
|
||
| EXPECT_EQ(strcmp(buff, buff2), 0); | ||
| free(buff2); | ||
| close(fd); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
man/zoslib.1:26: This.TPstarts a new term immediately after_ENCODE_FILE_NEW=BINARY, which leaves the BINARY option with no description and makes the “tagged as BINARY” paragraph apply to the UTF-8 entry instead.Severity: medium
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.