Skip to content
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

fgetwc return wint_t, not wchar_t #118

Open
olehjalmar opened this issue Jan 5, 2021 · 1 comment
Open

fgetwc return wint_t, not wchar_t #118

olehjalmar opened this issue Jan 5, 2021 · 1 comment

Comments

@olehjalmar
Copy link

olehjalmar commented Jan 5, 2021

sam compiles out of the box on Cygwin, but hangs when opening files. I traced the problem to the test on WEOF following the assignment of fgetwc to a wchar_t. The following patch fixes the problem, and believe the original code is actually wrong on all systems, not only on Cygwin.

diff --git a/sam/cmd.c b/sam/cmd.c
index c69201e..12fb9d0 100644
--- a/sam/cmd.c
+++ b/sam/cmd.c
@@ -109,8 +109,9 @@ inputc(void)
             terminp = termoutp = termline;
     } else{
         int olderr = errno;
-        r = fgetwc(stdin);
-        if (r == WEOF && errno == EILSEQ){
+        wint_t err;
+        r = err = fgetwc(stdin);
+        if (err = WEOF && errno == EILSEQ){
             clearerr(stdin);
             fflush(stdin);
             fgetc(stdin);
diff --git a/sam/io.c b/sam/io.c
index 080cdfd..46f568c 100644
--- a/sam/io.c
+++ b/sam/io.c
@@ -90,8 +90,9 @@ readio(File *f, bool *nulls, bool setdate)

     wchar_t buf[2] = {0};
     while (true){
-        buf[0] = fgetwc(io);
-        if (buf[0] == WEOF){
+        wint_t err;
+        buf[0] = err = fgetwc(io);
+        if (err == WEOF){
             if (errno == EILSEQ){
                 clearerr(io);
                 fflush(io);
@deadpixi
Copy link
Owner

deadpixi commented Jan 5, 2021

Thanks for this. Could you put the patch into a PR please?

japanoise added a commit to japanoise/sam that referenced this issue Sep 9, 2023
It returns wint_t, not wchar_t.

This bug was fixed by Github user olehjalmar, I just applied the
patch: deadpixi#118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants