How to fix EOF error when transitioning from Windows to Linux?

  • Thread starter Thread starter swartzism
  • Start date Start date
  • Tags Tags
    Unix Windows
Click For Summary
The discussion revolves around a user encountering an EOF error while running code on Fedora Linux that previously worked in Cygwin on Windows. The user suspects potential issues related to file permissions or differences in file formats between Windows and Linux. Key points include the importance of determining whether the file is opened as text or binary, as well as the need to check file permissions since the user is not operating as root. Additionally, the difference in newline characters between Windows and Linux text files is highlighted as a possible cause of the EOF error, with a recommendation to use the dos2unix command to convert Windows text files to a format compatible with Linux. The conversation emphasizes the necessity of providing detailed error messages and code snippets to facilitate troubleshooting.
swartzism
Messages
103
Reaction score
0
I am getting a confusing EOF error. I have working code which I have tested in Cygwin on Windows, but now that I am running the same code on Fedora Linux, I am getting an EOF error in a data file that I know works. Is there something I need to do in the transition from Windows to Linux to prevent this?

Thanks
 
Technology news on Phys.org
I can be completely off with my thinking, but is it a text, or binary file? And is it opened as text, or as binary?
 
It's a text file opened correctly as a text file. I'm exploring the idea that I don't have the proper permissions to read/write since I'm not root on this Linux computer.

Thanks for the reply.
 
Hi swartzism! Welcome to PF! :smile:

You'll have to give us a bit more information to help you.
There are a number of reasons why what you're doing might fail.

Can you give a more detailed description from the error that you're getting?
Perhaps what does work and what doesn't?

Can you provide us with the output of the following commands?

$ ls -l filename

$ od -tx1 filename

where filename is your data file?
 
Last edited:
swartzism said:
It's a text file opened correctly as a text file. I'm exploring the idea that I don't have the proper permissions to read/write since I'm not root on this Linux computer.

Thanks for the reply.

Your code should be capable of giving you a more useful error message than that. If I knew the language, I might be able to show you how to make it give you more information (assuming it's one I know).

For example, in C (keeping in mind I've not tested it, it's from memory, but that should give you the gist):

Code:
#include <stdio.h>
#include <errno.h>
#include <string.h>

#define INPUT_FILENAME "somefile.txt"

int main()
{
    FILE *fp = NULL;

    errno = 0;
    fp = fopen(INPUT_FILENAME, "r");
    if (errno != 0)
    {
        int err = errno;
        fprintf(stderr, "Error opening file \"%s\" (%d): %s\n", INPUT_FILENAME, err, strerror(err));
        return -1;
    }
}

Important edit: fopen returns a NULL and sets errno on error. I'm not checking for the null, but it's just a demonstration for how to use errno, not an example of perfect error handling in fopen. Keep that in mind.
 
Last edited:
swartzism said:
It's a text file opened correctly as a text file.
A windows text file and a linux text file have different file formats (specifically, in regard to newlines).

It would be much easier to pin down the error if you could show us code or otherwise better explain what the error actually is.
 
Hurkyl said:
A windows text file and a linux text file have different file formats (specifically, in regard to newlines).

It would be much easier to pin down the error if you could show us code or otherwise better explain what the error actually is.
I usually have to run dos2unix to fix the newlines on my Windows text files that I've transferred to Unix.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
Replies
13
Views
4K
Replies
7
Views
1K
  • · Replies 1 ·
Replies
1
Views
778
  • · Replies 66 ·
3
Replies
66
Views
6K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 13 ·
Replies
13
Views
5K