Merge from vendor branch SENDMAIL:
[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.23 2005/04/17 17:20:54 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         time_t            newer_ctime_sec; /* --newer/--newer-than */
52         long              newer_ctime_nsec; /* --newer/--newer-than */
53         time_t            newer_mtime_sec; /* --newer-mtime */
54         long              newer_mtime_nsec; /* --newer-mtime-than */
55         int               bytes_per_block; /* -b block_size */
56         int               verbose;   /* -v */
57         int               extract_flags; /* Flags for extract operation */
58         int               strip_components; /* Remove this many leading dirs */
59         char              mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */
60         char              symlink_mode; /* H or L, per BSD conventions */
61         char              create_compression; /* j, y, or z */
62         char              option_absolute_paths; /* -P */
63         char              option_dont_traverse_mounts; /* -X */
64         char              option_fast_read; /* --fast-read */
65         char              option_honor_nodump; /* --nodump */
66         char              option_interactive; /* -w */
67         char              option_no_owner; /* -o */
68         char              option_no_subdirs; /* -d */
69         char              option_null; /* --null */
70         char              option_stdout; /* -p */
71         char              option_totals; /* --totals */
72         char              option_unlink_first; /* -U */
73         char              option_warn_links; /* -l */
74         char              day_first; /* show day before month in -tv output */
75
76         /* If >= 0, then close this when done. */
77         int               fd;
78
79         /* Miscellaneous state information */
80         struct archive   *archive;
81         const char       *progname;
82         int               argc;
83         char            **argv;
84         size_t            gs_width; /* For 'list_item' in read.c */
85         size_t            u_width; /* for 'list_item' in read.c */
86         uid_t             user_uid; /* UID running this program */
87         int               return_value; /* Value returned by main() */
88         char              warned_lead_slash; /* Already displayed warning */
89         char              next_line_is_dir; /* Used for -C parsing in -cT */
90
91         /*
92          * Data for various subsystems.  Full definitions are located in
93          * the file where they are used.
94          */
95         struct archive_dir      *archive_dir;   /* for write.c */
96         struct name_cache       *gname_cache;   /* for write.c */
97         struct links_cache      *links_cache;   /* for write.c */
98         struct matching         *matching;      /* for matching.c */
99         struct security         *security;      /* for read.c */
100         struct name_cache       *uname_cache;   /* for write.c */
101 };
102
103 void    bsdtar_errc(struct bsdtar *, int _eval, int _code,
104             const char *fmt, ...);
105 void    bsdtar_strmode(struct archive_entry *entry, char *bp);
106 void    bsdtar_warnc(struct bsdtar *, int _code, const char *fmt, ...);
107 void    cleanup_exclusions(struct bsdtar *);
108 void    do_chdir(struct bsdtar *);
109 int     edit_pathname(struct bsdtar *, struct archive_entry *);
110 int     exclude(struct bsdtar *, const char *pattern);
111 int     exclude_from_file(struct bsdtar *, const char *pathname);
112 int     excluded(struct bsdtar *, const char *pathname);
113 int     include(struct bsdtar *, const char *pattern);
114 int     include_from_file(struct bsdtar *, const char *pathname);
115 int     process_lines(struct bsdtar *bsdtar, const char *pathname,
116             int (*process)(struct bsdtar *, const char *));
117 void    safe_fprintf(FILE *, const char *fmt, ...);
118 void    set_chdir(struct bsdtar *, const char *newdir);
119 void    tar_mode_c(struct bsdtar *bsdtar);
120 void    tar_mode_r(struct bsdtar *bsdtar);
121 void    tar_mode_t(struct bsdtar *bsdtar);
122 void    tar_mode_u(struct bsdtar *bsdtar);
123 void    tar_mode_x(struct bsdtar *bsdtar);
124 int     unmatched_inclusions(struct bsdtar *bsdtar);
125 void    usage(struct bsdtar *);
126 int     yes(const char *fmt, ...);
127