~ubuntu-branches/ubuntu/oneiric/gnutls26/oneiric

« back to all changes in this revision

Viewing changes to lib/gl/read-file.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-05-20 13:07:18 UTC
  • mfrom: (12.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110520130718-db41dybbanzfvlji
Tags: 2.10.5-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Fix build failure with --no-add-needed.
  - Build for multiarch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* read-file.c -- read file contents into a string
2
 
   Copyright (C) 2006 Free Software Foundation, Inc.
 
2
   Copyright (C) 2006, 2009, 2010 Free Software Foundation, Inc.
3
3
   Written by Simon Josefsson and Bruno Haible.
4
4
 
5
5
   This program is free software; you can redistribute it and/or modify
45
45
      size_t requested;
46
46
 
47
47
      if (size + BUFSIZ + 1 > alloc)
48
 
        {
49
 
          char *new_buf;
50
 
 
51
 
          alloc += alloc / 2;
52
 
          if (alloc < size + BUFSIZ + 1)
53
 
            alloc = size + BUFSIZ + 1;
54
 
 
55
 
          new_buf = realloc (buf, alloc);
56
 
          if (!new_buf)
57
 
            {
58
 
              save_errno = errno;
59
 
              break;
60
 
            }
61
 
 
62
 
          buf = new_buf;
63
 
        }
 
48
        {
 
49
          char *new_buf;
 
50
 
 
51
          alloc += alloc / 2;
 
52
          if (alloc < size + BUFSIZ + 1)
 
53
            alloc = size + BUFSIZ + 1;
 
54
 
 
55
          new_buf = realloc (buf, alloc);
 
56
          if (!new_buf)
 
57
            {
 
58
              save_errno = errno;
 
59
              break;
 
60
            }
 
61
 
 
62
          buf = new_buf;
 
63
        }
64
64
 
65
65
      requested = alloc - size - 1;
66
66
      count = fread (buf + size, 1, requested, stream);
67
67
      size += count;
68
68
 
69
69
      if (count != requested)
70
 
        {
71
 
          save_errno = errno;
72
 
          if (ferror (stream))
73
 
            break;
74
 
          buf[size] = '\0';
75
 
          *length = size;
76
 
          return buf;
77
 
        }
 
70
        {
 
71
          save_errno = errno;
 
72
          if (ferror (stream))
 
73
            break;
 
74
          buf[size] = '\0';
 
75
          *length = size;
 
76
          return buf;
 
77
        }
78
78
    }
79
79
 
80
80
  free (buf);
99
99
  if (fclose (stream) != 0)
100
100
    {
101
101
      if (out)
102
 
        {
103
 
          save_errno = errno;
104
 
          free (out);
105
 
        }
 
102
        {
 
103
          save_errno = errno;
 
104
          free (out);
 
105
        }
106
106
      errno = save_errno;
107
107
      return NULL;
108
108
    }