Creation of 4GB file in Linux

This is a discussion on Creation of 4GB file in Linux within the Linux Programming forums, part of the Platform Specific Boards category; Hello I want to create a file of 4GB in Linux. But I want to create that file using C ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    1

    Creation of 4GB file in Linux

    Hello
    I want to create a file of 4GB in Linux. But I want to create that file using C library functions like fseek, fopen etc. Can anybody suggest me some code for that ? Also I tried 'dd' command. This command creates a file. Can I access that file in C language.
    Thanks.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You can use arbitrarily large files with fread/fwrite and the character/line oriented function (such as fgets, fgetc) in Linux. The problem comes when using fseek, since it only takes a "unsigned long", so unless your linux version is a 64-bit variant, it will be limited to 4GB for fseek operations. There are some extended variants of fseek, such as fseeko and fsetpos that take bigger numbers.

    --
    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.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    See _LARGEFILE_SOURCE, _LARGEFILE64_SOURCE, and _FILE_OFFSET_BITS macros in the libc manual: http://www.gnu.org/software/libc/man..._005fSOURCE-47

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM

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