libbb.h cleanup.
[oweals/opkg-lede.git] / libbb / libbb.h
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Busybox main internal header file
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19
20 #ifndef __LIBBB_H__
21 #define __LIBBB_H__    1
22
23 #include <stdio.h>
24 #include <stdarg.h>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27
28 #include <netdb.h>
29
30 #include <features.h>
31
32 #define FALSE   ((int) 0)
33 #define TRUE    ((int) 1)
34
35 extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
36 extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
37 extern void perror_msg(const char *s, ...);
38 extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
39 extern void archive_xread_all(int fd, char *buf, size_t count);
40
41 /* These two are used internally -- you shouldn't need to use them */
42 extern void verror_msg(const char *s, va_list p);
43 extern void vperror_msg(const char *s, va_list p);
44
45 const char *mode_string(int mode);
46 const char *time_string(time_t timeVal);
47
48 int copy_file(const char *source, const char *dest, int flags);
49 int copy_file_chunk(FILE *src_file, FILE *dst_file, unsigned long long chunksize);
50 ssize_t safe_read(int fd, void *buf, size_t count);
51 ssize_t full_read(int fd, char *buf, int len);
52
53 extern int parse_mode( const char* s, mode_t* theMode);
54
55 extern FILE *wfopen(const char *path, const char *mode);
56 extern FILE *xfopen(const char *path, const char *mode);
57
58 extern void *xmalloc (size_t size);
59 extern void *xrealloc(void *old, size_t size);
60 extern void *xcalloc(size_t nmemb, size_t size);
61 extern char *xstrdup (const char *s);
62 extern char *xstrndup (const char *s, int n);
63 extern char *safe_strncpy(char *dst, const char *src, size_t size);
64
65 char *xreadlink(const char *path);
66 char *concat_path_file(const char *path, const char *filename);
67 char *last_char_is(const char *s, int c);
68
69 typedef struct file_headers_s {
70         char *name;
71         char *link_name;
72         off_t size;
73         uid_t uid;
74         gid_t gid;
75         mode_t mode;
76         time_t mtime;
77         dev_t device;
78 } file_header_t;
79
80 enum extract_functions_e {
81         extract_verbose_list = 1,
82         extract_list = 2,
83         extract_one_to_buffer = 4,
84         extract_to_stdout = 8,
85         extract_all_to_fs = 16,
86         extract_preserve_date = 32,
87         extract_data_tar_gz = 64,
88         extract_control_tar_gz = 128,
89         extract_unzip_only = 256,
90         extract_unconditional = 512,
91         extract_create_leading_dirs = 1024,
92         extract_quiet = 2048,
93         extract_exclude_list = 4096
94 };
95
96 char *deb_extract(const char *package_filename, FILE *out_stream,
97                 const int extract_function, const char *prefix, const char *filename);
98
99 extern int unzip(FILE *l_in_file, FILE *l_out_file);
100 extern void gz_close(int gunzip_pid);
101 extern FILE *gz_open(FILE *compressed_file, int *pid);
102
103 int make_directory (const char *path, long mode, int flags);
104
105 enum {
106         FILEUTILS_PRESERVE_STATUS = 1,
107         FILEUTILS_PRESERVE_SYMLINKS = 2,
108         FILEUTILS_RECUR = 4,
109         FILEUTILS_FORCE = 8,
110 };
111
112 extern const char *applet_name;
113 extern const char * const memory_exhausted;
114
115 #endif /* __LIBBB_H__ */