Merge from vendor branch NTPD:
[dragonfly.git] / contrib / bsdtar / bsdtar.h
1 /*-
2  * Copyright (c) 2003-2004 Tim Kientzle
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer
10  *    in this position and unchanged.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name(s) of the author(s) may not be used to endorse or promote
15  *    products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * $FreeBSD: src/usr.bin/tar/bsdtar.h,v 1.20 2004/08/08 05:50:10 kientzle Exp $
30  */
31
32 #include <archive.h>
33 #include <stdio.h>
34
35 #define DEFAULT_BYTES_PER_BLOCK (20*512)
36
37 /*
38  * The internal state for the "bsdtar" program.
39  *
40  * Keeping all of the state in a structure like this simplifies memory
41  * leak testing (at exit, anything left on the heap is suspect).  A
42  * pointer to this structure is passed to most bsdtar internal
43  * functions.
44  */
45 struct bsdtar {
46         /* Options */
47         const char       *filename; /* -f filename */
48         const char       *create_format; /* -F format */
49         char             *pending_chdir; /* -C dir */
50         const char       *names_from_file; /* -T file */
51         int               bytes_per_block; /* -b block_size */
52         int               verbose;   /* -v */
53         int               extract_flags; /* Flags for extract operation */
54         char              mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */
55         char              symlink_mode; /* H or L, per BSD conventions */
56         char              create_compression; /* j, y, or z */
57         char              option_absolute_paths; /* -P */
58         char              option_dont_traverse_mounts; /* -X */
59         char              option_fast_read; /* --fast-read */
60         char              option_honor_nodump; /* --nodump */
61         char              option_interactive; /* -w */
62         char              option_no_owner; /* -o */
63         char              option_no_subdirs; /* -d */
64         char              option_null; /* --null */
65         char              option_stdout; /* -p */
66         char              option_totals; /* --totals */
67         char              option_unlink_first; /* -U */
68         char              option_warn_links; /* -l */
69         char              day_first; /* show day before month in -tv output */
70
71         /* If >= 0, then close this when done. */
72         int               fd;
73
74         /* Miscellaneous state information */
75         struct archive   *archive;
76         const char       *progname;
77         int               argc;
78         char            **argv;
79         size_t            gs_width; /* For 'list_item' in read.c */
80         size_t            u_width; /* for 'list_item' in read.c */
81         uid_t             user_uid; /* UID running this program */
82         int               return_value; /* Value returned by main() */
83         char              warned_lead_slash; /* Already displayed warning */
84         char              next_line_is_dir; /* Used for -C parsing in -cT */
85
86         /*
87          * Data for various subsystems.  Full definitions are located in
88          * the file where they are used.
89          */
90         struct archive_dir      *archive_dir;   /* for write.c */
91         struct name_cache       *gname_cache;   /* for write.c */
92         struct links_cache      *links_cache;   /* for write.c */
93         struct matching         *matching;      /* for matching.c */
94         struct security         *security;      /* for read.c */
95         struct name_cache       *uname_cache;   /* for write.c */
96 };
97
98 void    bsdtar_errc(struct bsdtar *, int _eval, int _code,
99             const char *fmt, ...);
100 void    bsdtar_strmode(struct archive_entry *entry, char *bp);
101 void    bsdtar_warnc(struct bsdtar *, int _code, const char *fmt, ...);
102 void    cleanup_exclusions(struct bsdtar *);
103 void    do_chdir(struct bsdtar *);
104 int     exclude(struct bsdtar *, const char *pattern);
105 int     exclude_from_file(struct bsdtar *, const char *pathname);
106 int     excluded(struct bsdtar *, const char *pathname);
107 int     include(struct bsdtar *, const char *pattern);
108 int     include_from_file(struct bsdtar *, const char *pathname);
109 int     process_lines(struct bsdtar *bsdtar, const char *pathname,
110             int (*process)(struct bsdtar *, const char *));
111 void    safe_fprintf(FILE *, const char *fmt, ...);
112 void    set_chdir(struct bsdtar *, const char *newdir);
113 void    tar_mode_c(struct bsdtar *bsdtar);
114 void    tar_mode_r(struct bsdtar *bsdtar);
115 void    tar_mode_t(struct bsdtar *bsdtar);
116 void    tar_mode_u(struct bsdtar *bsdtar);
117 void    tar_mode_x(struct bsdtar *bsdtar);
118 int     unmatched_inclusions(struct bsdtar *bsdtar);
119 void    usage(struct bsdtar *);
120 int     yes(const char *fmt, ...);
121