Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for libplaton/platon/str/dynfgets.c between version 1.1 and 1.2

version 1.1, 2001/11/07 14:17:04 version 1.2, 2001/12/08 18:23:53
Line 2 
Line 2 
 #include <string.h>  #include <string.h>
 #include <stdlib.h>  #include <stdlib.h>
   
 char *dynamic_fgets(FILE *fp) {  #include "dynfgets.h"
         char *ptr;  
         char temp[128];  char *dynamic_fgets(FILE *fp)
         int i;  {
           char temp[DYNAMIC_FGETS_BUFSIZE];
         ptr = (char *) malloc(1);          register char *ptr;
         if (ptr == NULL)          register int i;
                 return (NULL);  
           if ((ptr = (char *) malloc(1)) == NULL)
         *ptr = '\0';                  return NULL;
         for (i = 0;; i++) {  
                 if (fgets(temp, 128, fp) == NULL) {          for (*ptr = '\0', i = 0; ; i++) {
                   if (fgets(temp, DYNAMIC_FGETS_BUFSIZE, fp) == NULL) {
                         if (ferror(fp) != 0 || i == 0) {                          if (ferror(fp) != 0 || i == 0) {
                                 free(ptr);                                  free(ptr);
                                 return (NULL);                                  return NULL;
                         }                          }
                         return (ptr);  
                           return ptr;
                 }                  }
                 ptr = (char *) realloc(ptr, 127 * (i + 1) + 1);  
                   ptr = (char *) realloc(ptr, (DYNAMIC_FGETS_BUFSIZE - 1) * (i + 1) + 1);
                 if (ptr == NULL)                  if (ptr == NULL)
                         return (NULL);                          return NULL;
   
                 strcat(ptr, temp);                  strcat(ptr, temp);
   
                 if (strchr(temp, '\n') != NULL) {                  if (strchr(temp, '\n') != NULL) {
                         *strchr(ptr, '\n') = '\0';                          *strchr(ptr, '\n') = '\0';
                         return (ptr);                          return ptr;
                 }                  }
         }          }
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top