Ticket #54060: patch-src-gss.diff

File patch-src-gss.diff, 1.7 KB (added by josephsacco, 7 years ago)

patch to add getline() to src/gss.c

  • src/gss.c

    old new  
    298298  return 0;
    299299}
    300300
     301#ifdef __APPLE__
     302#include <Availability.h>
     303#if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1060
     304
     305static const int line_size = 128;
     306
     307static ssize_t
     308getdelim (char **lineptr, size_t *n, int delim, FILE *stream);
     309
     310static ssize_t
     311getline (char **lineptr, size_t *n, FILE *stream);
     312
     313static ssize_t
     314getdelim (char **lineptr, size_t *n, int delim, FILE *stream)
     315{
     316  int indx = 0;
     317  int c;
     318
     319  /* Sanity checks.  */
     320  if (lineptr == NULL || n == NULL || stream == NULL)
     321    return -1;
     322
     323  /* Allocate the line the first time.  */
     324  if (*lineptr == NULL)
     325    {
     326      *lineptr = malloc (line_size);
     327      if (*lineptr == NULL)
     328        return -1;
     329      *n = line_size;
     330    }
     331
     332  /* Clear the line.  */
     333  memset (*lineptr, '\0', *n);
     334
     335  while ((c = getc (stream)) != EOF)
     336    {
     337      /* Check if more memory is needed.  */
     338      if (indx >= *n)
     339        {
     340          *lineptr = realloc (*lineptr, *n + line_size);
     341          if (*lineptr == NULL)
     342            {
     343              return -1;
     344            }
     345          /* Clear the rest of the line.  */
     346          memset(*lineptr + *n, '\0', line_size);
     347          *n += line_size;
     348        }
     349
     350      /* Push the result in the line.  */
     351      (*lineptr)[indx++] = c;
     352
     353      /* Bail out.  */
     354      if (c == delim)
     355        {
     356          break;
     357        }
     358    }
     359  return (c == EOF) ? -1 : indx;
     360}
     361
     362static ssize_t
     363getline (char **lineptr, size_t *n, FILE *stream)
     364{
     365  return getdelim (lineptr, n, '\n', stream);
     366}
     367#endif
     368#endif
     369
    301370static ssize_t
    302371gettrimline (char **line, size_t * n, FILE * fh)
    303372{