Thread: Creation of 4GB file in Linux

  1. #1
    Registered User
    Join Date
    Oct 2008

    Creation of 4GB file in Linux

    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.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    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.

    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
    See _LARGEFILE_SOURCE, _LARGEFILE64_SOURCE, and _FILE_OFFSET_BITS macros in the libc manual:


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, 10: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