• C

FILE I/O

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;

      call_line=(line+2)/2;

      time(&cur_time);
      strcpy(time_buf,asctime(localtime(&cur_time)));
      time_buf[strlen(time_buf)-1]='\0';
      
      if((fp=fopen("SOCKlog.txt","at"))==  NULL)
            //t"))==  NULL)
      {
            printf("Error encountered!");
            exit(1);
      }
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);

      fclose(fp);
      return TRUE;
      
}

What could be the problem?
MengAsked:
Who is Participating?
 
mliberiCommented:
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
0
 
MengAuthor Commented:
Can U include the library functions that is accountable for exceeding this limitation?
0
 
Answers2000Commented:
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
0
KuppingerCole Reviews AlgoSec in Executive Report

Leading analyst firm, KuppingerCole reviews AlgoSec's Security Policy Management Solution, and the security challenges faced by companies today in their Executive View report.

 
MCoroliCommented:
To exceed you can analize file size and create another one. Old file can be renamed. Not very nice but simple way
0
 
alexoCommented:
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).
0
 
MithanderCommented:
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?
0
 
MengAuthor Commented:
Edited text of question
0
 
ozoCommented:
perror("fopen failed because:");

the disk may have run out of space,
or you may have a user quota, or process limit set
0
 
yingchunliCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.