aboutsummaryrefslogtreecommitdiff
path: root/support/file_contents.h
blob: 9b2d750aae8a885a50af9b57d7a220a6e5968fa3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Functionality for checking file contents.
   Copyright (C) 2024 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <https://www.gnu.org/licenses/>.  */

#ifndef SUPPORT_FILE_CONTENTS_H
#define SUPPORT_FILE_CONTENTS_H

#include <support/check.h>
#include <stdio.h>

__BEGIN_DECLS

/* Check that an already-open file has exactly the given bytes,
   starting at the current location in the file.  The file position
   indicator is updated to point after the bytes compared.  Return 0
   if equal, 1 otherwise or on read error.  */
int support_compare_file_bytes (FILE *fp, const char *contents, size_t length);

/* Check that an already-open file has exactly the given string as
   contents, starting at the current offset.  The file position
   indicator is updated to point after the bytes compared.  Return 0
   if equal, 1 otherwise or on read error.  */
int support_compare_file_string (FILE *fp, const char *contents);

/* Check that a not-currently-open file has exactly the given bytes.
   Return 0 if equal, 1 otherwise or on read error.  */
int support_open_and_compare_file_bytes (const char *file,
					 const char *contents,
					 size_t length);

/* Check that a not-currently-open file has exactly the given string
   as contents, starting at the current offset.  Return 0 if equal, 1
   otherwise or on read error.  */
int support_open_and_compare_file_string (const char *file,
					  const char *contents);

/* Compare bytes read from an open file with the given string.  The
   file position indicator is updated to point after the bytes
   compared.  */
#define TEST_COMPARE_FILE_STRING(FP, CONTENTS)			\
  TEST_COMPARE (support_compare_file_string (FP, CONTENTS), 0)

/* Read a file and compare bytes read from it with the given string.  */
#define TEST_OPEN_AND_COMPARE_FILE_STRING(FILE, CONTENTS)		\
  TEST_COMPARE (support_open_and_compare_file_string (FILE, CONTENTS), 0)

__END_DECLS

#endif /* SUPPORT_FILE_CONTENTS_H */