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

  • Thread starter Thread starter swartzism
  • Start date Start date
  • Tags Tags
    Unix Windows
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
6 replies · 3K views
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
 
Physics 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.