source: vendor/diffutils/2.8.1/lib/cmpbuf.c@ 3506

Last change on this file since 3506 was 2556, checked in by bird, 20 years ago

diffutils 2.8.1

File size: 3.8 KB
Line 
1/* Buffer primitives for comparison operations.
2
3 Copyright (C) 1993, 1995, 1998, 2001, 2002 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 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.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 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. */
19
20#if HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24#include <errno.h>
25#include <limits.h>
26
27#include <signal.h>
28#ifndef SA_RESTART
29# ifdef SA_INTERRUPT /* e.g. SunOS 4.1.x */
30# define SA_RESTART SA_INTERRUPT
31# else
32# define SA_RESTART 0
33# endif
34#endif
35
36#if HAVE_UNISTD_H
37# include <unistd.h>
38#endif
39
40#if HAVE_INTTYPES_H
41# include <inttypes.h>
42#endif
43
44#include <sys/types.h>
45#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
63
64#ifndef PTRDIFF_MAX
65# define PTRDIFF_MAX TYPE_MAXIMUM (ptrdiff_t)
66#endif
67#ifndef SIZE_MAX
68# define SIZE_MAX TYPE_MAXIMUM (size_t)
69#endif
70#ifndef SSIZE_MAX
71# define SSIZE_MAX TYPE_MAXIMUM (ssize_t)
72#endif
73
74#undef MIN
75#define MIN(a, b) ((a) <= (b) ? (a) : (b))
76
77/* Read NBYTES bytes from descriptor FD into BUF.
78 NBYTES must not be SIZE_MAX.
79 Return the number of characters successfully read.
80 On error, return SIZE_MAX, setting errno.
81 The number returned is always NBYTES unless end-of-file or error. */
82
83size_t