stdio differences windows vs linux

This is a discussion on stdio differences windows vs linux within the C Programming forums, part of the General Programming Boards category; Hi, I had to write a trivial database program using first principles with the C standard library. I wrote and ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    81

    stdio differences windows vs linux

    Hi, I had to write a trivial database program using first principles with the C standard library. I wrote and tested the program on windows in binary mode, because I thought the C standard library was cross platform. However, when I compile the code on linux there seems to be some kind of differences because the database is failing to write the correct bytes to the file. I haven't determined what is causing the failure, that could take some serious time. So what I was hoping was if someone knows of all the differences between windows and linux when it comes to file i/o they could maybe point me in the right direction..

    Primarily all i am using is fseek, fwrite, fread, and ftell

    Can someone at least confirm that they are aware of differences between windows and linux support of these functions?

    Thanks in advance.

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    There shouldn't be any difference, no. I mean, fread(), fwrite(), ftell() are standard libraries. They should work both in Linux and Windows. I don't think you should have a problem with these functions.
    Are you sure you are opening the file in binary format? If not then there are some differences in Windows and Linux, but in any case it is wrong.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I have written quite a few programs for both Linux and Windows that use stdio, and there should be no difference. Of course, if you are bending the rules somehow, you may find that the different OS's do things differently. Also, bear in mind that the different OS's may have different sizes for data types, for example, if you use the 64-bit version of Linux, "long" would be 64-bit, whilst "long" even in 64-bit versions of Windows are 32-bit.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Windows uses "\r\n" for newlines; UNIX uses "\n" for newlines.
    That's the only difference I can think of.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by cpjust View Post
    Windows uses "\r\n" for newlines; UNIX uses "\n" for newlines.
    That's the only difference I can think of.
    But that ONLY applies if the file is opened in text mode, which the original post says it isn't.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by matsp View Post
    But that ONLY applies if the file is opened in text mode, which the original post says it isn't.

    --
    Mats
    If there's one thing I learned when I did tech support many years ago, it's that you should never trust anything that people tell you unless you've checked it yourself.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  7. #7
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Quote Originally Posted by cpjust View Post
    If there's one thing I learned when I did tech support many years ago, it's that you should never trust anything that people tell you unless you've checked it yourself.
    I agree. That is why I asked if it is sure opened in binary. It is a common mistake to think you opened it in binary mode, but to open it in text mode. Dunno, like putting "w+ b" as a parameter, so possibly " b" will be ignored and it will open in text mode.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. windows .dll vs. linux .so - global static objects
    By pheres in forum C++ Programming
    Replies: 11
    Last Post: 11-23-2010, 12:29 PM
  2. A question about windows programming
    By Hussain Hani in forum Windows Programming
    Replies: 16
    Last Post: 05-23-2007, 07:38 AM
  3. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 03:44 AM
  4. Why can't Windows run Linux binary executables?
    By Kleid-0 in forum Tech Board
    Replies: 30
    Last Post: 12-04-2005, 10:44 PM
  5. Linux and Windows Duel Boot
    By The15th in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-26-2002, 04:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21