Solved

FILE I/O

Posted on 1999-01-19
9
187 Views
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;

      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?
0
Comment
Question by:Meng
9 Comments
 

Author Comment

by:Meng
ID: 1258183
Can U include the library functions that is accountable for exceeding this limitation?
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1258184
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
 
LVL 1

Expert Comment

by:MCoroli
ID: 1258185
To exceed you can analize file size and create another one. Old file can be renamed. Not very nice but simple way
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 11

Expert Comment

by:alexo
ID: 1258186
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
 

Expert Comment

by:Mithander
ID: 1258187
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
 

Author Comment

by:Meng
ID: 1258188
Edited text of question
0
 
LVL 84

Expert Comment

by:ozo
ID: 1258189
perror("fopen failed because:");

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

Expert Comment

by:yingchunli
ID: 1258190
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
 
LVL 3

Accepted Solution

by:
mliberi earned 10 total points
ID: 1258191
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

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

785 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