LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-15-2009, 03:48 PM   #1
dariyoosh
LQ Newbie
 
Registered: Mar 2009
Location: Iran (Tehran)
Posts: 12

Rep: Reputation: 0
Question Is there a system call other than 'open' for opening very large files?


Dear all,


Inside a C program, I want to open a very big file (about 12 GB) in order to read its
content. Here is the code:

Code:
    /*
          argv[1] contains the path to the file.
    */
    inputFileDescriptor = open(argv[1], O_RDONLY);
    if (inputFileDescriptor < 0)
    {
        fprintf(stderr, "Error: Could not open the input file\n");
        fprintf(stderr, "%s\n", strerror(errno));
        return 1;
    }

And it seems that the file is too big, because I receive the following error message:
Code:
Error: Could not open the input file
Value too large for defined data type
Is there any other system call, allowing to open very big files?


Thanks in advance,
Dariyoosh
 
Old 08-15-2009, 04:41 PM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Add O_LARGEFILE to the open flags or use open64 which uses this internally. IIRC there is a posix define which you can use _LARGEFILE_SOURCE.
You would probably be advised to mmap parts of the file at a time.
 
Old 08-16-2009, 06:33 AM   #3
dariyoosh
LQ Newbie
 
Registered: Mar 2009
Location: Iran (Tehran)
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by dmail View Post
Add O_LARGEFILE to the open flags or use open64 which uses this internally. IIRC there is a posix define which you can use _LARGEFILE_SOURCE.
You would probably be advised to mmap parts of the file at a time.


Hello there,


Thank you very much for your help. I'll try this method.


Kind Regards,
Dariyoosh
 
Old 08-16-2009, 04:29 PM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
mmap is another way top open files
but...
that is a very big file.
 
Old 08-16-2009, 05:57 PM   #5
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
Originally Posted by bigearsbilly View Post
mmap is another way top open files
but...
that is a very big file.
But mmap requires a file descriptor you still need to open the file first no?
 
Old 08-16-2009, 07:13 PM   #6
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You need the O_LARGEFILE flag with open:
Code:
#define _LARGEFILE64_SOURCE
#include <sys/stat.h>
//...

    /*
          argv[1] contains the path to the file.
    */
    inputFileDescriptor = open(argv[1], O_RDONLY | O_LARGEFILE);
    if (inputFileDescriptor < 0)
    {
        fprintf(stderr, "Error: Could not open the input file\n");
        fprintf(stderr, "%s\n", strerror(errno));
        return 1;
    }
Kevin Barry
 
Old 08-17-2009, 05:09 AM   #7
dariyoosh
LQ Newbie
 
Registered: Mar 2009
Location: Iran (Tehran)
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ta0kira View Post
You need the O_LARGEFILE flag with open:
Code:
#define _LARGEFILE64_SOURCE
#include <sys/stat.h>
//...

    /*
          argv[1] contains the path to the file.
    */
    inputFileDescriptor = open(argv[1], O_RDONLY | O_LARGEFILE);
    if (inputFileDescriptor < 0)
    {
        fprintf(stderr, "Error: Could not open the input file\n");
        fprintf(stderr, "%s\n", strerror(errno));
        return 1;
    }
Kevin Barry


Hello there,

Thanks a lot for your solution. I also applied this method and it worked pretty well.

I thank all of you for your attention to my problem and for your help.

Kind Regards,
Dariyoosh
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
An open source Call System brazilian_user Linux - Software 1 12-07-2006 11:46 PM
Open Office does not open large files linuxfond Linux - Newbie 8 09-26-2004 03:46 AM
difficulties with large files and system call read/write jwstric2 Programming 2 08-22-2004 11:42 PM
one more on open system call udayan Programming 2 05-17-2002 02:32 PM
open system call in linux udayan Linux - Newbie 1 05-06-2002 10:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration