Posted on 1999-01-19
Last Modified: 2010-04-15
What is the maximum possible size for a text file that is to be used as a log file? And how do I go about exceeding the file size limitation?

The file size that I had get is 662KB and after which the program terminates the logging. My code is as follows:

BOOL LogFile(int line, char *smsg, char *rmsg)

      FILE *fp;
      static int i=1;
      char time_buf[30];
      time_t cur_time;
      int call_line;


      if((fp=fopen("SOCKlog.txt","at"))==  NULL)
            //t"))==  NULL)
            printf("Error encountered!");
fprintf(fp,"%s %ld %s %s %s %d ** %-10s %-10s %-10s %-10s \n","No.", i++,"Date/Time:",time_buf,"Line:",call_line,"(smsg):",smsg," (rmsg):",rmsg);

      return TRUE;

What could be the problem?
Question by:Meng

Author Comment

Comment Utility
Can U include the library functions that is accountable for exceeding this limitation?

Expert Comment

Comment Utility
This is operating system dependant.

Typically you will find the max file size is 2^32, 2^64, 2^31 or 2^63 bytes, depending on what platform you're running on

Expert Comment

Comment Utility
To exceed you can analize file size and create another one. Old file can be renamed. Not very nice but simple way
LVL 11

Expert Comment

Comment Utility
Since you posted it in the "C" area, the C functions fseek() and lseek() accept a "long" offset.  Therefore, they cannot work with files longer than LONG_MAX (as defined in LIMITS.H for your compiler).
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline


Expert Comment

Comment Utility
I havn't heard of a limitation on file size.  But I could belive it is operating system dependant.  Just yesterday I made a text file that was two hundred meg big.  I did it on accident, (A loop that never terminated.) but I don't think you would need a file bigger than that.  I did that under Win95.  What errors are you getting? can you post some code?

Author Comment

Comment Utility
Edited text of question
LVL 84

Expert Comment

Comment Utility
perror("fopen failed because:");

the disk may have run out of space,
or you may have a user quota, or process limit set

Expert Comment

Comment Utility
I havn't heard of a limitation on file size either.  You are using C and possiblly using integer as iondex to count or deal with bytes of the buffer.  If the integer is 16 bites (Max value ~65k) on your platform, it may cause (index) problem when file size is over 65k.

Accepted Solution

mliberi earned 10 total points
Comment Utility
there is no implicit limitation on the size of a text file, so your code should happily run on many os platforms.

please consider the following causes for your error:

1) your system manager configured your user account so that you cannot create a file bigger than ..... bytes. You can check for such a limitation, among others, with the command "ulimit -a" (are you running on a UNIX platform?"

2) your file filled the filesystem

3) if disk quotas has been configured, you could have exceeded your disk quota even if the filesystem is not full.

In any case the best thing you can do is putting a "perror" call just before exit(1). That would print an error message about the kind of error that occurred

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now