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

File with CR-LF line break will loaded error on Windows. #350

Open
NEUGWB opened this issue Mar 8, 2021 · 4 comments
Open

File with CR-LF line break will loaded error on Windows. #350

NEUGWB opened this issue Mar 8, 2021 · 4 comments

Comments

@NEUGWB
Copy link

NEUGWB commented Mar 8, 2021

According to msdn _read a file with CR-LF line break will cause read size smaller than the file size.

@marcobambini
Copy link
Owner

Thanks @NEUGWB. Do you have a suggestion for a fix?

@NEUGWB
Copy link
Author

NEUGWB commented Mar 8, 2021

Thanks @NEUGWB. Do you have a suggestion for a fix?

I think use fopen instead of open, or an fdeof function may help.

bool fdeof(int fd)
{
  char c;
  int rdsize = read(fd, &c, 1);
  return rdsize == 0;
}

I don't know if there is a better way. :)

@wtjcn
Copy link

wtjcn commented Jun 2, 2021

my solution is add "O_BINARY", tested ok on VS2017:

char *file_read(const char *path, size_t *len) {

fd = open(path, O_RDONLY | O_BINARY);

@tDwtp
Copy link
Contributor

tDwtp commented Jun 15, 2021

Fixed with #365
Had the same problem. Could have just read this instead, would have been a lot easier.

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

4 participants