mirror of
				https://gitlab.com/80486DX2-66/gists
				synced 2025-05-31 08:31:41 +05:30 
			
		
		
		
	extol.c: add file size limit
This commit is contained in:
		@@ -16,12 +16,15 @@ enum
 | 
			
		||||
} EXTOL_MODE;
 | 
			
		||||
 | 
			
		||||
#define EXTOL_PROTOTYPE "int extol(FILE* f)"
 | 
			
		||||
#define EXTOL_FILE_NAME "extol.txt"
 | 
			
		||||
#define EXTOL_FILE_LIMIT 128
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
extol (FILE *f)
 | 
			
		||||
{
 | 
			
		||||
  static bool spec_run = true;
 | 
			
		||||
  int result;
 | 
			
		||||
  off_t size;
 | 
			
		||||
 | 
			
		||||
  if (spec_run == false)
 | 
			
		||||
    {
 | 
			
		||||
@@ -38,6 +41,21 @@ extol (FILE *f)
 | 
			
		||||
          exit (EXIT_FAILURE);
 | 
			
		||||
        }
 | 
			
		||||
      fseek (fs, 0L, SEEK_END);
 | 
			
		||||
      size = ftello (fs);
 | 
			
		||||
      if (size == -1)
 | 
			
		||||
        {
 | 
			
		||||
          perror ("ftello");
 | 
			
		||||
          exit (EXIT_FAILURE);
 | 
			
		||||
        }
 | 
			
		||||
      else if (size > EXTOL_FILE_LIMIT)
 | 
			
		||||
        {
 | 
			
		||||
          FILE *new_fs = freopen (EXTOL_FILE_NAME, "w", fs);
 | 
			
		||||
          if (new_fs == NULL)
 | 
			
		||||
            {
 | 
			
		||||
              perror ("freopen");
 | 
			
		||||
              exit (EXIT_FAILURE);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
      result = extol (fs);
 | 
			
		||||
      for (result <<= 4, result &= ~15; (result & 15) != 15; result++)
 | 
			
		||||
        fputc ('=', fs);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user