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"
27229592Smm__FBSDID("$FreeBSD$");
28228753Smm
29228753Smm#include "archive.h"
30228753Smm#include "archive_entry.h"
31228753Smm#include "archive_private.h"
32228753Smm#include "archive_read_private.h"
33228753Smm
34228753Smmstatic int	archive_read_format_empty_bid(struct archive_read *);
35228753Smmstatic int	archive_read_format_empty_read_data(struct archive_read *,
36228753Smm		    const void **, size_t *, off_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
45228753Smm	r = __archive_read_register_format(a,
46228753Smm	    NULL,
47228753Smm	    NULL,
48228753Smm	    archive_read_format_empty_bid,
49228753Smm	    NULL,
50228753Smm	    archive_read_format_empty_read_header,
51228753Smm	    archive_read_format_empty_read_data,
52228753Smm	    NULL,
53228753Smm	    NULL);
54228753Smm
55228753Smm	return (r);
56228753Smm}
57228753Smm
58228753Smm
59228753Smmstatic int
60228753Smmarchive_read_format_empty_bid(struct archive_read *a)
61228753Smm{
62228753Smm	ssize_t avail;
63228753Smm
64228753Smm	(void)__archive_read_ahead(a, 1, &avail);
65228753Smm	if (avail != 0)
66228753Smm		return (-1);
67228753Smm	return (1);
68228753Smm}
69228753Smm
70228753Smmstatic int
71228753Smmarchive_read_format_empty_read_header(struct archive_read *a,
72228753Smm    struct archive_entry *entry)
73228753Smm{
74228753Smm	(void)a; /* UNUSED */
75228753Smm	(void)entry; /* UNUSED */
76228753Smm
77228753Smm	a->archive.archive_format = ARCHIVE_FORMAT_EMPTY;
78228753Smm	a->archive.archive_format_name = "Empty file";
79228753Smm
80228753Smm	return (ARCHIVE_EOF);
81228753Smm}
82228753Smm
83228753Smmstatic int
84228753Smmarchive_read_format_empty_read_data(struct archive_read *a,
85228753Smm    const void **buff, size_t *size, off_t *offset)
86228753Smm{
87228753Smm	(void)a; /* UNUSED */
88228753Smm	(void)buff; /* UNUSED */
89228753Smm	(void)size; /* UNUSED */
90228753Smm	(void)offset; /* UNUSED */
91228753Smm
92228753Smm	return (ARCHIVE_EOF);
93228753Smm}
94