Ticket #49235: patch-getline.diff

File patch-getline.diff, 1.9 KB (added by dbevans (David B. Evans), 8 years ago)

Modified patch-getline.diff as proposed by devans

  • src/polkitagent/polkitagenthelperprivate.c

    old new  
    4545}
    4646#endif
    4747
     48// getline() is only available on OS X Lion and newer
     49
     50#ifdef __APPLE__
     51#ifndef __MAC_OS_X_VERSION_MIN_REQUIRED
     52#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
     53#include <Availability.h>
     54#else
     55#include <AvailabilityMacros.h>
     56#endif
     57#endif
     58#if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1060
     59
     60static const int line_size = 128;
     61
     62static ssize_t
     63getdelim (char **lineptr, size_t *n, int delim, FILE *stream);
     64
     65static ssize_t
     66getline (char **lineptr, size_t *n, FILE *stream);
     67
     68static ssize_t
     69getdelim (char **lineptr, size_t *n, int delim, FILE *stream)
     70{
     71  int indx = 0;
     72  int c;
     73
     74  /* Sanity checks.  */
     75  if (lineptr == NULL || n == NULL || stream == NULL)
     76    return -1;
     77
     78  /* Allocate the line the first time.  */
     79  if (*lineptr == NULL)
     80    {
     81      *lineptr = malloc (line_size);
     82      if (*lineptr == NULL)
     83        return -1;
     84      *n = line_size;
     85    }
     86
     87  /* Clear the line.  */
     88  memset (*lineptr, '\0', *n);
     89
     90  while ((c = getc (stream)) != EOF)
     91    {
     92      /* Check if more memory is needed.  */
     93      if (indx >= *n)
     94        {
     95          *lineptr = realloc (*lineptr, *n + line_size);
     96          if (*lineptr == NULL)
     97            {
     98              return -1;
     99            }
     100          /* Clear the rest of the line.  */
     101          memset(*lineptr + *n, '\0', line_size);
     102          *n += line_size;
     103        }
     104
     105      /* Push the result in the line.  */
     106      (*lineptr)[indx++] = c;
     107
     108      /* Bail out.  */
     109      if (c == delim)
     110        {
     111          break;
     112        }
     113    }
     114  return (c == EOF) ? -1 : indx;
     115}
     116
     117static ssize_t
     118getline (char **lineptr, size_t *n, FILE *stream)
     119{
     120  return getdelim (lineptr, n, '\n', stream);
     121}
     122#endif
     123#endif
    48124
    49125char *
    50126read_cookie (int argc, char **argv)