1228753Smm/*-
2228753Smm * Copyright (c) 2003-2007 Tim Kientzle
3228753Smm * All rights reserved.
4228753Smm *
5228753Smm * Redistribution and use in source and binary forms, with or without
6228753Smm * modification, are permitted provided that the following conditions
7228753Smm * are met:
8228753Smm * 1. Redistributions of source code must retain the above copyright
9228753Smm *    notice, this list of conditions and the following disclaimer.
10228753Smm * 2. Redistributions in binary form must reproduce the above copyright
11228753Smm *    notice, this list of conditions and the following disclaimer in the
12228753Smm *    documentation and/or other materials provided with the distribution.
13228753Smm *
14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24228753Smm */
25228753Smm
26228753Smm#include "archive_platform.h"
27228763Smm__FBSDID("$FreeBSD: stable/10/contrib/libarchive/libarchive/archive_read_support_format_empty.c 368708 2020-12-16 22:25:40Z mm $");
28228753Smm
29228753Smm#include "archive.h"
30228753Smm#include "archive_entry.h"
31228753Smm#include "archive_private.h"
32228753Smm#include "archive_read_private.h"
33228753Smm
34232153Smmstatic int	archive_read_format_empty_bid(struct archive_read *, int);
35228753Smmstatic int	archive_read_format_empty_read_data(struct archive_read *,
36232153Smm		    const void **, size_t *, int64_t *);
37228753Smmstatic int	archive_read_format_empty_read_header(struct archive_read *,
38228753Smm		    struct archive_entry *);
39228753Smmint
40228753Smmarchive_read_support_format_empty(struct archive *_a)
41228753Smm{
42228753Smm	struct archive_read *a = (struct archive_read *)_a;
43228753Smm	int r;
44228753Smm
45232153Smm	archive_check_magic(_a, ARCHIVE_READ_MAGIC,
46232153Smm	    ARCHIVE_STATE_NEW, "archive_read_support_format_empty");
47232153Smm
48228753Smm	r = __archive_read_register_format(a,
49228753Smm	    NULL,
50368708Smm	    "empty",
51228753Smm	    archive_read_format_empty_bid,
52228753Smm	    NULL,
53228753Smm	    archive_read_format_empty_read_header,
54228753Smm	    archive_read_format_empty_read_data,
55228753Smm	    NULL,
56248616Smm	    NULL,
57302001Smm	    NULL,
58302001Smm	    NULL,
59228753Smm	    NULL);
60228753Smm
61228753Smm	return (r);
62228753Smm}
63228753Smm
64228753Smm
65228753Smmstatic int
66232153Smmarchive_read_format_empty_bid(struct archive_read *a, int best_bid)
67228753Smm{
68232153Smm	if (best_bid < 1 && __archive_read_ahead(a, 1, NULL) == NULL)
69232153Smm		return (1);
70232153Smm	return (-1);
71228753Smm}
72228753Smm
73228753Smmstatic int
74228753Smmarchive_read_format_empty_read_header(struct archive_read *a,
75228753Smm    struct archive_entry *entry)
76228753Smm{
77228753Smm	(void)a; /* UNUSED */
78228753Smm	(void)entry; /* UNUSED */
79228753Smm
80228753Smm	a->archive.archive_format = ARCHIVE_FORMAT_EMPTY;
81228753Smm	a->archive.archive_format_name = "Empty file";
82228753Smm
83228753Smm	return (ARCHIVE_EOF);
84228753Smm}
85228753Smm
86228753Smmstatic int
87228753Smmarchive_read_format_empty_read_data(struct archive_read *a,
88232153Smm    const void **buff, size_t *size, int64_t *offset)
89228753Smm{
90228753Smm	(void)a; /* UNUSED */
91228753Smm	(void)buff; /* UNUSED */
92228753Smm	(void)size; /* UNUSED */
93228753Smm	(void)offset; /* UNUSED */
94228753Smm
95228753Smm	return (ARCHIVE_EOF);
96228753Smm}
97