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 #include <stdlib.h>
28 #include <netdb.h>
29 
30 #include "../libopkg/opkg_message.h"
31 
32 #ifndef FALSE
33 #define FALSE   ((int) 0)
34 #endif
35 
36 #ifndef TRUE
37 #define TRUE    ((int) 1)
38 #endif
39 
40 #define error_msg(fmt, args...) opkg_msg(ERROR, fmt"\n", ##args)
41 #define perror_msg(fmt, args...) opkg_perror(ERROR, fmt, ##args)
42 #define error_msg_and_die(fmt, args...) \
43 	do { \
44 		error_msg(fmt, ##args); \
45 		exit(EXIT_FAILURE); \
46 	} while (0)
47 #define perror_msg_and_die(fmt, args...) \
48 	do { \
49 		perror_msg(fmt, ##args); \
50 		exit(EXIT_FAILURE); \
51 	} while (0)
52 
53 extern void archive_xread_all(int fd, char *buf, size_t count);
54 
55 const char *mode_string(int mode);
56 const char *time_string(time_t timeVal);
57 
58 int copy_file(const char *source, const char *dest, int flags);
59 int copy_file_chunk(FILE * src_file, FILE * dst_file,
60 		    unsigned long long chunksize);
61 ssize_t safe_read(int fd, void *buf, size_t count);
62 ssize_t full_read(int fd, char *buf, int len);
63 
64 extern int parse_mode(const char *s, mode_t * theMode);
65 
66 extern FILE *wfopen(const char *path, const char *mode);
67 extern FILE *xfopen(const char *path, const char *mode);
68 
69 extern void *xmalloc(size_t size);
70 extern void *xrealloc(void *old, size_t size);
71 extern void *xcalloc(size_t nmemb, size_t size);
72 extern char *xstrdup(const char *s);
73 extern char *xstrndup(const char *s, int n);
74 extern char *safe_strncpy(char *dst, const char *src, size_t size);
75 
76 char *xreadlink(const char *path);
77 char *concat_path_file(const char *path, const char *filename);
78 char *last_char_is(const char *s, int c);
79 
80 typedef struct file_headers_s {
81 	char *name;
82 	char *link_name;
83 	off_t size;
84 	uid_t uid;
85 	gid_t gid;
86 	mode_t mode;
87 	time_t mtime;
88 	dev_t device;
89 } file_header_t;
90 
91 enum extract_functions_e {
92 	extract_verbose_list = 1,
93 	extract_list = 2,
94 	extract_one_to_buffer = 4,
95 	extract_to_stream = 8,
96 	extract_all_to_fs = 16,
97 	extract_preserve_date = 32,
98 	extract_data_tar_gz = 64,
99 	extract_control_tar_gz = 128,
100 	extract_unzip_only = 256,
101 	extract_unconditional = 512,
102 	extract_create_leading_dirs = 1024,
103 	extract_quiet = 2048,
104 	extract_exclude_list = 4096
105 };
106 
107 char *deb_extract(const char *package_filename, FILE * out_stream,
108 		  const int extract_function, const char *prefix,
109 		  const char *filename, int *err);
110 
111 extern int unzip(FILE * l_in_file, FILE * l_out_file);
112 extern int gz_close(int gunzip_pid);
113 extern FILE *gz_open(FILE * compressed_file, int *pid);
114 
115 int make_directory(const char *path, long mode, int flags);
116 
117 enum {
118 	FILEUTILS_PRESERVE_STATUS = 1,
119 	FILEUTILS_PRESERVE_SYMLINKS = 2,
120 	FILEUTILS_RECUR = 4,
121 	FILEUTILS_FORCE = 8,
122 };
123 
124 #endif /* __LIBBB_H__ */
125