myprintf.c
changeset 63 5a82f89d607e
parent 62 b7061c0e239f
child 77 49e0babccb23
equal deleted inserted replaced
62:b7061c0e239f 63:5a82f89d607e
    37                 s = va_arg (list, char *);
    37                 s = va_arg (list, char *);
    38                 while ((pos + strlen (s)) > (size * BUF_SIZE)) {
    38                 while ((pos + strlen (s)) > (size * BUF_SIZE)) {
    39                     if ((ptr = realloc (s_str, ++size * BUF_SIZE)) == NULL) {
    39                     if ((ptr = realloc (s_str, ++size * BUF_SIZE)) == NULL) {
    40                         s_str[pos] = '\0';
    40                         s_str[pos] = '\0';
    41                         fputs (s_str, fp);  /* print it anyway... */
    41                         fputs (s_str, fp);  /* print it anyway... */
       
    42                         free (s_str);
    42                         return EOF;
    43                         return EOF;
    43                     }
    44                     }
    44                     s_str = ptr;
    45                     s_str = ptr;
    45                 }
    46                 }
    46                 for (i = 0; i < strlen (s); i++) {
    47                 for (i = 0; i < strlen (s); i++) {
    65             s_str[pos++] = *fmt++;
    66             s_str[pos++] = *fmt++;
    66         }
    67         }
    67 
    68 
    68         if (pos > (size * BUF_SIZE / 2)) {
    69         if (pos > (size * BUF_SIZE / 2)) {
    69             if ((ptr = realloc (s_str, ++size * BUF_SIZE)) == NULL) {
    70             if ((ptr = realloc (s_str, ++size * BUF_SIZE)) == NULL) {
       
    71                 free (s_str);
    70                 return EOF;
    72                 return EOF;
    71             }
    73             }
    72             s_str = ptr;
    74             s_str = ptr;
    73         }
    75         }
    74     }
    76     }