~ubuntu-branches/ubuntu/trusty/diffutils/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/cmpbuf.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2010-02-13 11:49:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100213114900-09lz8jx6wct52qp8
Tags: 1:2.9-1
* New upstream release, now under GPL version 3 or later.
* There is now a --tab-size option. Closes: #82923.
* Manpage for cmp describes exit status. Closes: #200614.
* Manpage for diff describes exit status. Closes: #228441, #473233.
* The file de.po is now more recent. Closes: #313686.
* Fixed bad sdiff behaviour. Closes: #320222.
* Added wdiff to Suggests. Closes: #324627.
* Fixed cmp behaviour regarding stdout and stderr. Closes: #356083.
* The file ru.po is now more recent. Closes: #409274.
* The file es.po is now more recent. Closes: #418005, #481708.
* The file nl.po is now more recent. Closes: #427370.
* Modified watch file to use http instead of ftp.
* Removed .comment section from executables.
* Added Homepage field to control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Buffer primitives for comparison operations.
2
2
 
3
 
   Copyright (C) 1993, 1995, 1998, 2001, 2002 Free Software Foundation, Inc.
 
3
   Copyright (C) 1993, 1995, 1998, 2001-2002, 2006, 2009-2010 Free Software
 
4
   Foundation, Inc.
4
5
 
5
 
   This program is free software; you can redistribute it and/or modify
 
6
   This program is free software: you can redistribute it and/or modify
6
7
   it under the terms of the GNU General Public License as published by
7
 
   the Free Software Foundation; either version 2, or (at your option)
8
 
   any later version.
 
8
   the Free Software Foundation, either version 3 of the License, or
 
9
   (at your option) any later version.
9
10
 
10
11
   This program is distributed in the hope that it will be useful,
11
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
14
   GNU General Public License for more details.
14
15
 
15
16
   You should have received a copy of the GNU General Public License
16
 
   along with this program; see the file COPYING.
17
 
   If not, write to the Free Software Foundation,
18
 
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
17
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
18
 
20
 
#if HAVE_CONFIG_H
21
 
# include <config.h>
22
 
#endif
 
19
#include <config.h>
23
20
 
24
21
#include <errno.h>
25
22
#include <limits.h>
43
40
 
44
41
#include <sys/types.h>
45
42
#include "cmpbuf.h"
46
 
 
47
 
/* Determine whether an integer type is signed, and its bounds.
48
 
   This code assumes two's (or one's!) complement with no holes.  */
49
 
 
50
 
/* The extra casts work around common compiler bugs,
51
 
   e.g. Cray C 5.0.3.0 when t == time_t.  */
52
 
#ifndef TYPE_SIGNED
53
 
# define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
54
 
#endif
55
 
#ifndef TYPE_MINIMUM
56
 
# define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
57
 
                               ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
58
 
                               : (t) 0))
59
 
#endif
60
 
#ifndef TYPE_MAXIMUM
61
 
# define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
62
 
#endif
 
43
#include "intprops.h"
63
44
 
64
45
#ifndef PTRDIFF_MAX
65
46
# define PTRDIFF_MAX TYPE_MAXIMUM (ptrdiff_t)
85
66
{
86
67
  char *bp = buf;
87
68
  char const *buflim = buf + nbytes;
88
 
  size_t readlim = SSIZE_MAX;
 
69
  size_t readlim = MIN (SSIZE_MAX, SIZE_MAX);
89
70
 
90
71
  do
91
72
    {
92
 
      size_t bytes_to_read = MIN (buflim - bp, readlim);
 
73
      size_t bytes_remaining = buflim - bp;
 
74
      size_t bytes_to_read = MIN (bytes_remaining, readlim);
93
75
      ssize_t nread = read (fd, bp, bytes_to_read);
94
76
      if (nread <= 0)
95
77
        {