* http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
*/
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <utime.h>
-#include <unistd.h>
-
-#include "unarchive.h"
#include "busybox.h"
+#include "unarchive.h"
static void header_verbose_list_ar(const file_header_t *file_header)
{
bb_error_msg_and_die(msg_unsupported_err, "insertion");
}
- archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY);
+ archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
while (optind < argc) {
archive_handle->filter = filter_accept_list;
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
#include "busybox.h"
#include "unarchive.h"
filename = argv[optind];
if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) {
/* Open input file */
- src_fd = bb_xopen(filename, O_RDONLY);
+ src_fd = xopen(filename, O_RDONLY);
} else {
src_fd = STDIN_FILENO;
filename = 0;
}
xstat(filename, &stat_buf);
*extension=0;
- dst_fd = bb_xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
+ dst_fd = xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
} else dst_fd = STDOUT_FILENO;
status = uncompressStream(src_fd, dst_fd);
if(filename) {
/* vi: set sw=4 ts=4: */
/*
- * Mini dpkg implementation for busybox.
- * This is not meant as a replacement for dpkg
+ * mini dpkg implementation for busybox.
+ * this is not meant as a replacement for dpkg
*
- * Written By Glenn McGrath with the help of others
- * Copyright (C) 2001 by Glenn McGrath
+ * written by glenn mcgrath with the help of others
+ * copyright (c) 2001 by glenn mcgrath
*
- * Started life as a busybox implementation of udpkg
+ * started life as a busybox implementation of udpkg
*
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * licensed under gplv2 or later, see file license in this tarball for details.
*/
/*
- * Known difference between busybox dpkg and the official dpkg that i don't
+ * known difference between busybox dpkg and the official dpkg that i don't
* consider important, its worth keeping a note of differences anyway, just to
* make it easier to maintain.
- * - The first value for the Confflile: field isnt placed on a new line.
- * - When installing a package the Status: field is placed at the end of the
- * section, rather than just after the Package: field.
+ * - the first value for the confflile: field isnt placed on a new line.
+ * - when installing a package the status: field is placed at the end of the
+ * section, rather than just after the package: field.
*
- * Bugs that need to be fixed
+ * bugs that need to be fixed
* - (unknown, please let me know when you find any)
*
*/
-#include <fcntl.h>
-#include <getopt.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "unarchive.h"
#include "busybox.h"
+#include "unarchive.h"
-/* NOTE: If you vary HASH_PRIME sizes be aware,
- * 1) Tweaking these will have a big effect on how much memory this program uses.
- * 2) For computational efficiency these hash tables should be at least 20%
+/* note: if you vary hash_prime sizes be aware,
+ * 1) tweaking these will have a big effect on how much memory this program uses.
+ * 2) for computational efficiency these hash tables should be at least 20%
* larger than the maximum number of elements stored in it.
- * 3) All _HASH_PRIME's must be a prime number or chaos is assured, if your looking
+ * 3) all _hash_prime's must be a prime number or chaos is assured, if your looking
* for a prime, try http://www.utm.edu/research/primes/lists/small/10000.txt
- * 4) If you go bigger than 15 bits you may get into trouble (untested) as its
+ * 4) if you go bigger than 15 bits you may get into trouble (untested) as its
* sometimes cast to an unsigned int, if you go to 16 bit you will overlap
* int's and chaos is assured, 16381 is the max prime for 14 bit field
*/
}
}
}
- name_hashtable[probe_address] = bb_xstrdup(key);
+ name_hashtable[probe_address] = xstrdup(key);
return(probe_address);
}
int ret;
if (version1 == NULL) {
- version1 = bb_xstrdup("");
+ version1 = xstrdup("");
}
if (version2 == NULL) {
- version2 = bb_xstrdup("");
+ version2 = xstrdup("");
}
upstream_len1 = strlen(version1);
upstream_len2 = strlen(version2);
while ((len1 < upstream_len1) || (len2 < upstream_len2)) {
/* Compare non-digit section */
tmp_int = strcspn(&version1[len1], "0123456789");
- name1_char = bb_xstrndup(&version1[len1], tmp_int);
+ name1_char = xstrndup(&version1[len1], tmp_int);
len1 += tmp_int;
tmp_int = strcspn(&version2[len2], "0123456789");
- name2_char = bb_xstrndup(&version2[len2], tmp_int);
+ name2_char = xstrndup(&version2[len2], tmp_int);
len2 += tmp_int;
tmp_int = strcmp(name1_char, name2_char);
free(name1_char);
/* Compare digits */
tmp_int = strspn(&version1[len1], "0123456789");
- name1_char = bb_xstrndup(&version1[len1], tmp_int);
+ name1_char = xstrndup(&version1[len1], tmp_int);
len1 += tmp_int;
tmp_int = strspn(&version2[len2], "0123456789");
- name2_char = bb_xstrndup(&version2[len2], tmp_int);
+ name2_char = xstrndup(&version2[len2], tmp_int);
len2 += tmp_int;
ver_num1 = atoi(name1_char);
ver_num2 = atoi(name2_char);
}
/* Compare upstream version */
- upstream_ver1 = bb_xstrdup(ver1_ptr);
- upstream_ver2 = bb_xstrdup(ver2_ptr);
+ upstream_ver1 = xstrdup(ver1_ptr);
+ upstream_ver2 = xstrdup(ver2_ptr);
/* Chop off debian version, and store for later use */
deb_ver1 = strrchr(upstream_ver1, '-');
*/
static void add_split_dependencies(common_node_t *parent_node, const char *whole_line, unsigned int edge_type)
{
- char *line = bb_xstrdup(whole_line);
+ char *line = xstrdup(whole_line);
char *line2;
char *line_ptr1 = NULL;
char *line_ptr2 = NULL;
do {
/* skip leading spaces */
field += strspn(field, " ");
- line2 = bb_xstrdup(field);
+ line2 = xstrdup(field);
field2 = strtok_r(line2, "|", &line_ptr2);
if ( (edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS) &&
(strcmp(field, field2) != 0)) {
}
}
+/*
+ * Gets the next package field from package_buffer, seperated into the field name
+ * and field value, it returns the int offset to the first character of the next field
+ */
+static int read_package_field(const char *package_buffer, char **field_name, char **field_value)
+{
+ int offset_name_start = 0;
+ int offset_name_end = 0;
+ int offset_value_start = 0;
+ int offset_value_end = 0;
+ int offset = 0;
+ int next_offset;
+ int name_length;
+ int value_length;
+ int exit_flag = FALSE;
+
+ if (package_buffer == NULL) {
+ *field_name = NULL;
+ *field_value = NULL;
+ return(-1);
+ }
+ while (1) {
+ next_offset = offset + 1;
+ switch (package_buffer[offset]) {
+ case('\0'):
+ exit_flag = TRUE;
+ break;
+ case(':'):
+ if (offset_name_end == 0) {
+ offset_name_end = offset;
+ offset_value_start = next_offset;
+ }
+ /* TODO: Name might still have trailing spaces if ':' isnt
+ * immediately after name */
+ break;
+ case('\n'):
+ /* TODO: The char next_offset may be out of bounds */
+ if (package_buffer[next_offset] != ' ') {
+ exit_flag = TRUE;
+ break;
+ }
+ case('\t'):
+ case(' '):
+ /* increment the value start point if its a just filler */
+ if (offset_name_start == offset) {
+ offset_name_start++;
+ }
+ if (offset_value_start == offset) {
+ offset_value_start++;
+ }
+ break;
+ }
+ if (exit_flag) {
+ /* Check that the names are valid */
+ offset_value_end = offset;
+ name_length = offset_name_end - offset_name_start;
+ value_length = offset_value_end - offset_value_start;
+ if (name_length == 0) {
+ break;
+ }
+ if ((name_length > 0) && (value_length > 0)) {
+ break;
+ }
+
+ /* If not valid, start fresh with next field */
+ exit_flag = FALSE;
+ offset_name_start = offset + 1;
+ offset_name_end = 0;
+ offset_value_start = offset + 1;
+ offset_value_end = offset + 1;
+ offset++;
+ }
+ offset++;
+ }
+ if (name_length == 0) {
+ *field_name = NULL;
+ } else {
+ *field_name = xstrndup(&package_buffer[offset_name_start], name_length);
+ }
+ if (value_length > 0) {
+ *field_value = xstrndup(&package_buffer[offset_value_start], value_length);
+ } else {
+ *field_value = NULL;
+ }
+ return(next_offset);
+}
+
static unsigned int fill_package_struct(char *control_buffer)
{
static const char *const field_names[] = { "Package", "Version",
status_string += strspn(status_string, " ");
}
len = strcspn(status_string, " \n\0");
- state_sub_string = bb_xstrndup(status_string, len);
+ state_sub_string = xstrndup(status_string, len);
state_sub_num = search_name_hashtable(state_sub_string);
free(state_sub_string);
return(state_sub_num);
bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen");
}
- new_status = bb_xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
+ new_status = xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
status_hashtable[status_node_num]->status = search_name_hashtable(new_status);
free(new_status);
return;
status_node_t *status_node = NULL;
unsigned int status_num;
- status_file = bb_xfopen(filename, "r");
+ status_file = xfopen(filename, "r");
while ((control_buffer = fgets_str(status_file, "\n\n")) != NULL) {
const unsigned int package_num = fill_package_struct(control_buffer);
if (package_num != -1) {
if (status_line != NULL) {
status_line += 7;
status_line += strspn(status_line, " \n\t");
- status_line = bb_xstrndup(status_line, strcspn(status_line, "\n\0"));
+ status_line = xstrndup(status_line, strcspn(status_line, "\n\0"));
status_node->status = search_name_hashtable(status_line);
free(status_line);
}
/* This could do with a cleanup */
static void write_status_file(deb_file_t **deb_file)
{
- FILE *old_status_file = bb_xfopen("/var/lib/dpkg/status", "r");
- FILE *new_status_file = bb_xfopen("/var/lib/dpkg/status.udeb", "w");
+ FILE *old_status_file = xfopen("/var/lib/dpkg/status", "r");
+ FILE *new_status_file = xfopen("/var/lib/dpkg/status.udeb", "w");
char *package_name;
char *status_from_file;
char *control_buffer = NULL;
tmp_string += 8;
tmp_string += strspn(tmp_string, " \n\t");
- package_name = bb_xstrndup(tmp_string, strcspn(tmp_string, "\n\0"));
+ package_name = xstrndup(tmp_string, strcspn(tmp_string, "\n\0"));
write_flag = FALSE;
tmp_string = strstr(control_buffer, "Status:");
if (tmp_string != NULL) {
/* Seperate the status value from the control buffer */
tmp_string += 7;
tmp_string += strspn(tmp_string, " \n\t");
- status_from_file = bb_xstrndup(tmp_string, strcspn(tmp_string, "\n"));
+ status_from_file = xstrndup(tmp_string, strcspn(tmp_string, "\n"));
} else {
status_from_file = NULL;
}
char *script_path;
int result;
- script_path = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
+ script_path = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
/* If the file doesnt exist is isnt a fatal */
result = lstat(script_path, &path_stat) < 0 ? EXIT_SUCCESS : system(script_path);
/* Create a list of all /var/lib/dpkg/info/<package> files */
remove_files = xzalloc(sizeof(all_control_files));
while (all_control_files[i]) {
- remove_files[i] = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
+ remove_files[i] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
i++;
}
/* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
exclude_files = xzalloc(sizeof(char*) * 3);
- exclude_files[0] = bb_xstrdup(conffile_name);
- exclude_files[1] = bb_xasprintf("/var/lib/dpkg/info/%s.postrm", package_name);
+ exclude_files[0] = xstrdup(conffile_name);
+ exclude_files[1] = xasprintf("/var/lib/dpkg/info/%s.postrm", package_name);
/* Create a list of all /var/lib/dpkg/info/<package> files */
remove_files = all_control_list(package_name);
/* Setup an ar archive handle that refers to the gzip sub archive */
ar_handle = init_handle();
ar_handle->filter = filter_accept_list_reassign;
- ar_handle->src_fd = bb_xopen(filename, O_RDONLY);
+ ar_handle->src_fd = xopen(filename, O_RDONLY);
return(ar_handle);
}
name_ptr += strspn(name_ptr, "./");
if (name_ptr[0] != '\0') {
- archive_handle->file_header->name = bb_xasprintf("%s%s", archive_handle->buffer, name_ptr);
+ archive_handle->file_header->name = xasprintf("%s%s", archive_handle->buffer, name_ptr);
data_extract_all(archive_handle);
}
return;
}
/* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */
- info_prefix = bb_xasprintf("/var/lib/dpkg/info/%s.", package_name);
+ info_prefix = xasprintf("/var/lib/dpkg/info/%s.", package_name);
archive_handle = init_archive_deb_ar(deb_file->filename);
init_archive_deb_control(archive_handle);
while(all_control_files[i]) {
- char *c = bb_xasprintf("./%s", all_control_files[i]);
+ char *c = xasprintf("./%s", all_control_files[i]);
llist_add_to(&accept_list, c);
i++;
}
/* Create the list file */
strcat(info_prefix, "list");
- out_stream = bb_xfopen(info_prefix, "w");
+ out_stream = xfopen(info_prefix, "w");
while (archive_handle->sub_archive->passed) {
/* the leading . has been stripped by data_extract_all_prefix already */
fputs(archive_handle->sub_archive->passed->data, out_stream);
if (deb_file[deb_count]->control_file == NULL) {
bb_error_msg_and_die("Couldnt extract control file");
}
- deb_file[deb_count]->filename = bb_xstrdup(argv[optind]);
+ deb_file[deb_count]->filename = xstrdup(argv[optind]);
package_num = fill_package_struct(deb_file[deb_count]->control_file);
if (package_num == -1) {
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "unarchive.h"
#include "busybox.h"
+#include "unarchive.h"
#define DPKG_DEB_OPT_CONTENTS 1
#define DPKG_DEB_OPT_CONTROL 2
bb_show_usage();
}
- tar_archive->src_fd = ar_archive->src_fd = bb_xopen(argv[optind++], O_RDONLY);
+ tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
/* Workout where to extract the files */
/* 2nd argument is a dir name */
}
if (extract_dir) {
mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
- bb_xchdir(extract_dir);
+ xchdir(extract_dir);
}
unpack_ar_archive(ar_archive);
* See the file algorithm.doc for the compression algorithms and file formats.
*/
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
#include "busybox.h"
#include "unarchive.h"
src_fd = STDIN_FILENO;
opt |= GUNZIP_OPT_STDOUT;
} else {
- src_fd = bb_xopen(old_path, O_RDONLY);
+ src_fd = xopen(old_path, O_RDONLY);
/* Get the time stamp on the input file. */
xstat(old_path, &stat_buf);
/* Set output filename and number */
if (opt & GUNZIP_OPT_TEST) {
- dst_fd = bb_xopen(bb_dev_null, O_WRONLY); /* why does test use filenum 2 ? */
+ dst_fd = xopen(bb_dev_null, O_WRONLY); /* why does test use filenum 2 ? */
} else if (opt & GUNZIP_OPT_STDOUT) {
dst_fd = STDOUT_FILENO;
} else {
char *extension;
- new_path = bb_xstrdup(old_path);
+ new_path = xstrdup(old_path);
extension = strrchr(new_path, '.');
#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
}
/* Open output file (with correct permissions) */
- dst_fd = bb_xopen3(new_path, O_WRONLY | O_CREAT, stat_buf.st_mode);
+ dst_fd = xopen3(new_path, O_WRONLY | O_CREAT, stat_buf.st_mode);
/* If unzip succeeds remove the old file */
delete_path = old_path;
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/types.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <utime.h>
-#include <unistd.h>
-#include <stdlib.h>
-
#include "libbb.h"
#include "unarchive.h"
int res;
if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) {
- char *name = bb_xstrdup(file_header->name);
+ char *name = xstrdup(file_header->name);
bb_make_directory (dirname(name), -1, FILEUTILS_RECUR);
free(name);
}
switch(file_header->mode & S_IFMT) {
case S_IFREG: {
/* Regular file */
- dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL);
+ dst_fd = xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL);
bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size);
close(dst_fd);
break;
Manuel
*/
-#include <setjmp.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <limits.h>
-
#include "libbb.h"
-
#include "unarchive.h"
/* Constants for Huffman coding */
/* Init the CRC32 table (big endian) */
- bd->crc32Table = bb_crc32_filltable(1);
+ bd->crc32Table = crc32_filltable(1);
/* Setup for I/O error handling via longjmp */
*/
#include "libbb.h"
-#include <sys/wait.h>
-#include <signal.h>
#include "unarchive.h"
typedef struct huft_s {
gunzip_bb = 0;
/* Create the crc table */
- gunzip_crc_table = bb_crc32_filltable(0);
+ gunzip_crc_table = crc32_filltable(0);
gunzip_crc = ~0;
/* Allocate space for buffer */
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "unarchive.h"
#include "libbb.h"
+#include "unarchive.h"
char get_header_ar(archive_handle_t *archive_handle)
{
static unsigned int ar_long_name_size;
#endif
- /* dont use bb_xread as we want to handle the error ourself */
+ /* dont use xread as we want to handle the error ourself */
if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
/* End Of File */
return(EXIT_FAILURE);
if (long_offset >= ar_long_name_size) {
bb_error_msg_and_die("Cant resolve long filename");
}
- typed->name = bb_xstrdup(ar_long_names + long_offset);
+ typed->name = xstrdup(ar_long_names + long_offset);
}
#else
bb_error_msg_and_die("long filenames not supported");
#endif
} else {
/* short filenames */
- typed->name = bb_xstrndup(ar.formatted.name, 16);
+ typed->name = xstrndup(ar.formatted.name, 16);
}
typed->name[strcspn(typed->name, " /")] = '\0';
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/sysmacros.h> /* major() and minor() */
-#include "unarchive.h"
#include "libbb.h"
+#include "unarchive.h"
typedef struct hardlinks_s {
file_header_t *entry;
pending_hardlinks = 1;
while (tmp) {
if (tmp->inode == inode) {
- tmp->entry->link_name = bb_xstrdup(file_header->name);
+ tmp->entry->link_name = xstrdup(file_header->name);
nlink--;
}
tmp = tmp->next;
* http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/sysmacros.h> /* For makedev */
-#include "unarchive.h"
#include "libbb.h"
+#include "unarchive.h"
#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
static char *longname = NULL;
} else
#endif
{
- file_header->name = bb_xstrndup(tar.formatted.name,100);
+ file_header->name = xstrndup(tar.formatted.name,100);
if (tar.formatted.prefix[0]) {
char *temp = file_header->name;
file_header->size = strtol(tar.formatted.size, NULL, 8);
file_header->mtime = strtol(tar.formatted.mtime, NULL, 8);
file_header->link_name = (tar.formatted.linkname[0] != '\0') ?
- bb_xstrdup(tar.formatted.linkname) : NULL;
+ xstrdup(tar.formatted.linkname) : NULL;
file_header->device = makedev(strtol(tar.formatted.devmajor, NULL, 8),
strtol(tar.formatted.devminor, NULL, 8));
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <unistd.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <netinet/in.h> /* For ntohl & htonl function */
-#include <string.h> /* For strncmp */
-#include <sys/mman.h> /* For mmap */
-#include <time.h> /* For ctime */
-
#include "busybox.h"
#include "unarchive.h"
if (optind == argc) bb_show_usage();
while (optind < argc) {
- rpm_fd = bb_xopen(argv[optind], O_RDONLY);
+ rpm_fd = xopen(argv[optind], O_RDONLY);
mytags = rpm_gettags(rpm_fd, (int *) &tagcount);
offset = lseek(rpm_fd, 0, SEEK_CUR);
if (!mytags) { printf("Error reading rpm header\n"); exit(-1); }
bb_error_msg_and_die("Invalid gzip magic");
}
check_header_gzip(archive_handle->src_fd);
- bb_xchdir("/"); // Install RPM's to root
+ xchdir("/"); // Install RPM's to root
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
archive_handle->offset = 0;
if (rpm_getint(RPMTAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { /* Only need to backup config files */
stat_res = lstat (filename, &oldfile);
if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { /* File already exists - really should check MD5's etc to see if different */
- newname = bb_xstrdup(filename);
+ newname = xstrdup(filename);
newname = strcat(newname, ".rpmorig");
copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS);
remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE);
{
int count = 0;
while (rpm_getstring(filetag, count)) {
- char * filename = bb_xasprintf("%s%s",
+ char * filename = xasprintf("%s%s",
rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES,
count)), rpm_getstring(RPMTAG_BASENAMES, count));
fileaction(filename, count++);
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/types.h>
-#include <netinet/in.h> /* For ntohl & htonl function */
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
#include "busybox.h"
#include "unarchive.h"
if (argc == 1) {
rpm_fd = STDIN_FILENO;
} else {
- rpm_fd = bb_xopen(argv[1], O_RDONLY);
+ rpm_fd = xopen(argv[1], O_RDONLY);
}
xread(rpm_fd, &lead, sizeof(struct rpm_lead));
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
#include "busybox.h"
#include "unarchive.h"
src_fd = STDIN_FILENO;
flags |= GUNZIP_TO_STDOUT;
} else {
- src_fd = bb_xopen(compressed_file, O_RDONLY);
+ src_fd = xopen(compressed_file, O_RDONLY);
}
/* Check that the input is sane. */
struct stat stat_buf;
char *extension;
- uncompressed_file = bb_xstrdup(compressed_file);
+ uncompressed_file = xstrdup(compressed_file);
extension = strrchr(uncompressed_file, '.');
if (!extension || (strcmp(extension, ".Z") != 0)) {
/* Open output file */
xstat(compressed_file, &stat_buf);
- dst_fd = bb_xopen3(uncompressed_file, O_WRONLY | O_CREAT,
+ dst_fd = xopen3(uncompressed_file, O_WRONLY | O_CREAT,
stat_buf.st_mode);
/* If unzip succeeds remove the old file */
* Licensed under GPL v2, see file LICENSE in this tarball for details.
*/
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
#include "busybox.h"
#include "unarchive.h"
filename = argv[optind];
if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) {
/* Open input file */
- src_fd = bb_xopen(filename, O_RDONLY);
+ src_fd = xopen(filename, O_RDONLY);
} else {
src_fd = STDIN_FILENO;
filename = 0;
}
xstat(filename, &stat_buf);
*extension = 0;
- dst_fd = bb_xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
+ dst_fd = xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
} else
dst_fd = STDOUT_FILENO;
status = unlzma(src_fd, dst_fd);
* - central directory
*/
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include "unarchive.h"
#include "busybox.h"
+#include "unarchive.h"
#define ZIP_FILEHEADER_MAGIC SWAP_LE32(0x04034b50)
#define ZIP_CDS_MAGIC SWAP_LE32(0x02014b50)
static void unzip_create_leading_dirs(char *fn)
{
/* Create all leading directories */
- char *name = bb_xstrdup(fn);
+ char *name = xstrdup(fn);
if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
bb_error_msg_and_die("Exiting"); /* bb_make_directory is noisy */
}
break;
case 1 : /* The zip file */
- src_fn = bb_xstrndup(optarg, strlen(optarg)+4);
+ src_fn = xstrndup(optarg, strlen(optarg)+4);
opt_range++;
break;
/* Change dir if necessary */
if (base_dir)
- bb_xchdir(base_dir);
+ xchdir(base_dir);
if (verbosity != v_silent)
printf("Archive: %s\n", src_fn);
overwrite = o_always;
case 'y': /* Open file and fall into unzip */
unzip_create_leading_dirs(dst_fn);
- dst_fd = bb_xopen(dst_fn, O_WRONLY | O_CREAT);
+ dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT);
case -1: /* Unzip */
if (verbosity == v_normal) {
printf(" inflating: %s\n", dst_fn);
bb_perror_msg_and_die("Cannot read input");
}
free(dst_fn);
- dst_fn = bb_xstrdup(key_buf);
+ dst_fn = xstrdup(key_buf);
chomp(dst_fn);
goto _check_file;
*
*/
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/ioctl.h>
#include "busybox.h"
/* From <linux/kd.h> */
if (argc >= 2 && *argv[1] == '-')
bb_show_usage();
- fd = bb_xopen(CURRENT_VC, O_RDWR);
+ fd = xopen(CURRENT_VC, O_RDWR);
write(1, magic, 7);
* Loads the console font, and possibly the corresponding screen map(s).
* (Adapted for busybox by Matej Vela.)
*/
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <sys/kd.h>
-#include <endian.h>
#include "busybox.h"
+#include <sys/kd.h>
enum{
PSF_MAGIC1 = 0x36,
if (argc != 1)
bb_show_usage();
- fd = bb_xopen(CURRENT_VC, O_RDWR);
+ fd = xopen(CURRENT_VC, O_RDWR);
loadnewfont(fd);
return EXIT_SUCCESS;
*
*/
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
#include "busybox.h"
#define BINARY_KEYMAP_MAGIC "bkeymap"
if (argc != 1)
bb_show_usage();
- fd = bb_xopen(CURRENT_VC, O_RDWR);
+ fd = xopen(CURRENT_VC, O_RDWR);
xread(0, buff, 7);
if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
close(0); /* so that new vt becomes stdin */
/* and grab new one */
- fd = bb_xopen(vtname, O_RDWR);
+ fd = xopen(vtname, O_RDWR);
/* Reassign stdout and sterr */
dup2(fd, STDOUT_FILENO);
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <getopt.h> /* struct option */
-
#include "busybox.h"
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
device = CONSOLE_DEV;
}
- if (-1 == ioctl(bb_xopen(device, O_RDONLY), TIOCCONS)) {
+ if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) {
bb_perror_msg_and_die("TIOCCONS");
}
return EXIT_SUCCESS;
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
#include "busybox.h"
extern int setlogcons_main(int argc, char **argv)
if (argc == 2)
arg.subarg = atoi(argv[1]);
- if (ioctl(bb_xopen(VC_1, O_RDONLY), TIOCLINUX, &arg))
+ if (ioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg))
bb_perror_msg_and_die("TIOCLINUX");;
return 0;
* Major size reduction... over 50% (>1.5k) on i386.
*/
-#include <sys/types.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
#include "busybox.h"
-#ifdef CONFIG_LOCALE_SUPPORT
-#include <locale.h>
-#endif
-
#define THURSDAY 4 /* for reformation */
#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
do {
zero_tm.tm_mon = i;
strftime(buf, sizeof(buf), "%B", &zero_tm);
- month_names[i] = bb_xstrdup(buf);
+ month_names[i] = xstrdup(buf);
if (i < 7) {
zero_tm.tm_wday = i;
* http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */
#include "busybox.h"
-#include <unistd.h>
-#include <fcntl.h>
int catv_main(int argc, char **argv)
{
// Read from stdin if there's nothing else to do.
fd = 0;
- if (*argv && 0>(fd = bb_xopen(*argv, O_RDONLY))) retval = EXIT_FAILURE;
+ if (*argv && 0>(fd = xopen(*argv, O_RDONLY))) retval = EXIT_FAILURE;
else for(;;) {
int i, res;
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
#include "busybox.h"
int chroot_main(int argc, char **argv)
if (chroot(*argv)) {
bb_perror_msg_and_die("cannot change root directory to %s", *argv);
}
- bb_xchdir("/");
+ xchdir("/");
++argv;
if (argc == 2) {
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
#include "busybox.h"
int cksum_main(int argc, char **argv) {
- uint32_t *crc32_table = bb_crc32_filltable(1);
+ uint32_t *crc32_table = crc32_filltable(1);
FILE *fp;
uint32_t crc;
* in the '-l' case.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
#include "busybox.h"
static FILE *cmp_xfopen_input(const char *filename)
c1 = c2;
}
if (c1 == EOF) {
- bb_xferror(fp1, filename1);
+ xferror(fp1, filename1);
fmt = fmt_eof; /* Well, no error, so it must really be EOF. */
outfile = stderr;
/* There may have been output to stdout (option -l), so
* make sure we fflush before writing to stderr. */
- bb_xfflush_stdout();
+ xfflush_stdout();
}
if (opt_flags != OPT_s) {
if (opt_flags == OPT_l) {
}
} while (c1 != EOF);
- bb_xferror(fp1, filename1);
- bb_xferror(fp2, filename2);
+ xferror(fp1, filename1);
+ xferror(fp2, filename2);
bb_fflush_stdout_and_exit(exit_val);
}
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
#include "busybox.h"
#define COMM_OPT_1 0x01
int i;
for (i = 0; i < 2; ++i) {
- streams[i] = ((infiles[i][0] == '=' && infiles[i][1]) ? stdin : bb_xfopen(infiles[i], "r"));
+ streams[i] = ((infiles[i][0] == '=' && infiles[i][1]) ? stdin : xfopen(infiles[i], "r"));
fgets(thisline[i], LINE_LEN, streams[i]);
}
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <signal.h> // For FEATURE_DD_SIGNAL_HANDLING
#include "busybox.h"
static const struct suffix_mult dd_suffixes[] = {
else obuf = ibuf;
if (infile != NULL) {
- ifd = bb_xopen(infile, O_RDONLY);
+ ifd = xopen(infile, O_RDONLY);
} else {
ifd = STDIN_FILENO;
infile = bb_msg_standard_input;
oflag |= O_TRUNC;
}
- ofd = bb_xopen3(outfile, oflag, 0666);
+ ofd = xopen3(outfile, oflag, 0666);
if (seek && trunc_flag) {
if (ftruncate(ofd, seek * obs) < 0) {
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <time.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <ctype.h>
-#include <errno.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/wait.h>
-#include <fcntl.h>
-#include <stddef.h>
-#include <paths.h>
-#include <dirent.h>
#include "busybox.h"
#define FSIZE_MAX 32768
goto closem;
if (flags & D_EMPTY1)
- f1 = bb_xfopen(bb_dev_null, "r");
+ f1 = xfopen(bb_dev_null, "r");
else {
if (strcmp(file1, "-") == 0)
f1 = stdin;
else
- f1 = bb_xfopen(file1, "r");
+ f1 = xfopen(file1, "r");
}
if (flags & D_EMPTY2)
- f2 = bb_xfopen(bb_dev_null, "r");
+ f2 = xfopen(bb_dev_null, "r");
else {
if (strcmp(file2, "-") == 0)
f2 = stdin;
else
- f2 = bb_xfopen(file2, "r");
+ f2 = xfopen(file2, "r");
}
if ((i = files_differ(f1, f2, flags)) == 0)
int flags = D_HEADER;
int val;
- char *fullpath1 = bb_xasprintf("%s/%s", dir1, path1);
- char *fullpath2 = bb_xasprintf("%s/%s", dir2, path2);
+ char *fullpath1 = xasprintf("%s/%s", dir1, path1);
+ char *fullpath2 = xasprintf("%s/%s", dir2, path2);
if (stat(fullpath1, &stb1) != 0) {
flags |= D_EMPTY1;
memset(&stb1, 0, sizeof(stb1));
- fullpath1 = bb_xasprintf("%s/%s", dir1, path2);
+ fullpath1 = xasprintf("%s/%s", dir1, path2);
}
if (stat(fullpath2, &stb2) != 0) {
flags |= D_EMPTY2;
memset(&stb2, 0, sizeof(stb2));
stb2.st_mode = stb1.st_mode;
- fullpath2 = bb_xasprintf("%s/%s", dir2, path1);
+ fullpath2 = xasprintf("%s/%s", dir2, path1);
}
if (stb1.st_mode == 0)
{
dl_count++;
dl = xrealloc(dl, dl_count * sizeof(char *));
- dl[dl_count - 1] = bb_xstrdup(filename);
+ dl[dl_count - 1] = xstrdup(filename);
if (cmd_flags & FLAG_r) {
int *pp = (int *) userdata;
int path_len = *pp + 1;
int path_len = strlen(path);
void *userdata = &path_len;
- /* Reset dl_count - there's no need to free dl as bb_xrealloc does
+ /* Reset dl_count - there's no need to free dl as xrealloc does
* the job nicely. */
dl_count = 0;
DIR *dp;
struct dirent *ep;
- dp = bb_opendir(path);
+ dp = warn_opendir(path);
while ((ep = readdir(dp))) {
if ((!strcmp(ep->d_name, "..")) || (!strcmp(ep->d_name, ".")))
continue;
/* Copy dl so that we can return it. */
retval = xmalloc(dl_count * sizeof(char *));
for (i = 0; i < dl_count; i++)
- retval[i] = bb_xstrdup(dl[i]);
+ retval[i] = xstrdup(dl[i]);
return retval;
}
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <string.h>
-#include <unistd.h>
-#include <stdint.h>
-#include <fcntl.h>
#include "busybox.h"
enum ConvType {
int i;
if (fn != NULL) {
- in = bb_xfopen(fn, "rw");
+ in = xfopen(fn, "rw");
/*
The file is then created with mode read/write and
permissions 0666 for glibc 2.0.6 and earlier or
/* no getopt needed */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <regex.h>
-#include <sys/types.h>
-#include <errno.h>
#include "busybox.h"
-
+#include "xregex.h"
/* The kinds of value we can have. */
enum valtype {
{
VALUE *v;
- v = xmalloc (sizeof(VALUE));
+ v = xmalloc(sizeof(VALUE));
v->type = string;
- v->u.s = bb_xstrdup (s);
+ v->u.s = xstrdup(s);
return v;
}
static void tostring (VALUE *v)
{
if (v->type == integer) {
- v->u.s = bb_xasprintf ("%" PF_REZ "d", PF_REZ_TYPE v->u.i);
+ v->u.s = xasprintf("%" PF_REZ "d", PF_REZ_TYPE v->u.i);
v->type = string;
}
}
else {
v = xmalloc (sizeof(VALUE));
v->type = string;
- v->u.s = bb_xstrndup(l->u.s + i1->u.i - 1, i2->u.i);
+ v->u.s = xstrndup(l->u.s + i1->u.i - 1, i2->u.i);
}
freev (l);
freev (i1);
Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
#include "busybox.h"
static unsigned long flags;
if (*a == '-' && !a[1])
break;
if (isdigit(*a)) {
- argv[i] = bb_xasprintf("-w%s", a);
+ argv[i] = xasprintf("-w%s", a);
}
}
}
/* BB_AUDIT GNU compatible -c, -q, and -v options in 'fancy' configuration. */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <ctype.h>
-#include <unistd.h>
#include "busybox.h"
static const char head_opts[] =
bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */
retval = EXIT_FAILURE;
}
- bb_xferror_stdout();
+ xferror_stdout();
}
fmt = header_fmt_str;
} while (*++argv);
/* BB_AUDIT GNU options missing: -d, -F, -i, and -v. */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/ln.html */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
#include "busybox.h"
#define LN_SYMLINK 1
if (argc == optind + 1) {
*--argv = last;
- last = bb_get_last_path_component(bb_xstrdup(last));
+ last = bb_get_last_path_component(xstrdup(last));
}
do {
if (is_directory(src,
(flag & LN_NODEREFERENCE) ^ LN_NODEREFERENCE,
NULL)) {
- src_name = bb_xstrdup(*argv);
+ src_name = xstrdup(*argv);
src = concat_path_file(src, bb_get_last_path_component(src_name));
free(src_name);
src_name = src;
if (flag & LN_BACKUP) {
char *backup;
- backup = bb_xasprintf("%s%s", src, suffix);
+ backup = xasprintf("%s%s", src, suffix);
if (rename(src, backup) < 0 && errno != ENOENT) {
bb_perror_msg("%s", src);
status = EXIT_FAILURE;
/************************************************************************/
#include "busybox.h"
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <getopt.h> /* struct option */
-#include <sys/ioctl.h>
-#include <sys/sysmacros.h> /* major() and minor() */
-#include <time.h>
+#include <getopt.h>
/* what is the overall style of the listing */
#define STYLE_COLUMNS (1U<<21) /* fill columns */
dn = NULL;
nfiles = 0;
- dir = bb_opendir(path);
+ dir = warn_opendir(path);
if (dir == NULL) {
status = EXIT_FAILURE;
return (NULL); /* could not open the dir */
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
#include "busybox.h"
typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
if (strcmp(file_ptr, "-") == 0) {
pre_computed_stream = stdin;
} else {
- pre_computed_stream = bb_xfopen(file_ptr, "r");
+ pre_computed_stream = xfopen(file_ptr, "r");
}
while ((line = bb_get_chomped_line_from_file(pre_computed_stream)) != NULL) {
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <fcntl.h>
-#include <signal.h>
-#include <unistd.h>
#include "busybox.h"
int nohup_main(int argc, char *argv[])
if (argc<2) bb_show_usage();
- nullfd = bb_xopen(bb_dev_null, O_WRONLY|O_APPEND);
+ nullfd = xopen(bb_dev_null, O_WRONLY|O_APPEND);
// If stdin is a tty, detach from it.
if (isatty(0)) dup2(nullfd, 0);
home = getenv("HOME");
if (home) {
home = concat_path_file(home, nohupout);
- bb_xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR);
+ xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR);
}
}
} else dup2(nullfd, 1);
* http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html
*/
-#include <ctype.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
#include "busybox.h"
static int global_flags;
}
/* Make the copy */
if(end<start) end=start;
- str=bb_xstrndup(str+start,end-start);
+ str=xstrndup(str+start,end-start);
/* Handle -d */
if(flags&FLAG_d) {
for(start=end=0;str[end];end++)
/* Perform fallback sort if necessary */
if(!retval && !(global_flags&FLAG_s))
retval=strcmp(*(char **)xarg, *(char **)yarg);
-//dprintf(2,"reverse=%d\n",flags&FLAG_r);
return ((flags&FLAG_r)?-1:1)*retval;
}
#ifdef CONFIG_FEATURE_SORT_BIG
case 'o':
if(outfile) bb_error_msg_and_die("Too many -o.");
- outfile=bb_xfopen(optarg,"w");
+ outfile=xfopen(optarg,"w");
break;
case 't':
if(key_separator || optarg[1])
/* Open input files and read data */
for(i=argv[optind] ? optind : optind-1;argv[i];i++) {
if(i<optind || (*argv[i]=='-' && !argv[i][1])) fp=stdin;
- else fp=bb_xfopen(argv[i],"r");
+ else fp=xfopen(argv[i],"r");
for(;;) {
line=GET_LINE(fp);
if(!line) break;
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <pwd.h>
-#include <grp.h>
-#include <sys/vfs.h>
-#include <time.h>
-#include <getopt.h> /* optind */
-#include <sys/stat.h>
-#include <sys/statfs.h>
-#include <sys/statvfs.h>
-#include <string.h>
#include "busybox.h"
/* vars to control behavior */
char *b;
/* create a working copy of the format string */
- char *format = bb_xstrdup(masterformat);
+ char *format = xstrdup(masterformat);
/* Add 2 to accommodate our conversion of the stat `%s' format string
* to the printf `%llu' one. */
*/
-//#define TEST
-
#include "busybox.h"
-#include <stddef.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-
-#include <sys/param.h>
-#include <unistd.h>
-
-#ifndef STDIN_FILENO
-# define STDIN_FILENO 0
-#endif
-
-#ifndef STDOUT_FILENO
-# define STDOUT_FILENO 1
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <fcntl.h>
#define STREQ(a, b) (strcmp ((a), (b)) == 0)
{NULL, 0 }
};
-#ifndef TEST
int stty_main(int argc, char **argv)
-#else
-int main(int argc, char **argv)
-#endif
{
struct termios mode;
void (*output_func)(struct termios *);
device_name = file_name;
fclose(stdin);
- bb_xopen(device_name, O_RDONLY | O_NONBLOCK);
+ xopen(device_name, O_RDONLY | O_NONBLOCK);
if ((fdflags = fcntl(STDIN_FILENO, F_GETFL)) == -1
|| fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
perror_on_device("%s: couldn't reset non-blocking mode");
*bpout = '\0';
return (const char *) buf;
}
-
-#ifdef TEST
-
-const char *bb_applet_name = "stty";
-
-#endif
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/tee.html */
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <unistd.h>
#include "busybox.h"
int tee_main(int argc, char **argv)
do { /* Now check for (input and) output errors. */
/* Checking ferror should be sufficient, but we may want to fclose.
* If we do, remember not to close stdin! */
- bb_xferror(*p, filenames[(int)(p - files)]);
+ xferror(*p, filenames[(int)(p - files)]);
} while (*++p);
bb_fflush_stdout_and_exit(retval);
/* http://www.opengroup.org/onlinepubs/007904975/utilities/uniq.html */
#include "busybox.h"
-#include <string.h>
-#include <ctype.h>
-#include <unistd.h>
static const char uniq_opts[] = "f:s:" "cdu\0\1\2\4";
if ((n = *argv) != NULL) {
if ((*n != '-') || n[1]) {
- return bb_xfopen(n, "r\0w" + read0write2);
+ return xfopen(n, "r\0w" + read0write2);
}
}
return (read0write2) ? stdout : stdin;
}
} while (s1);
- bb_xferror(in, input_filename);
+ xferror(in, input_filename);
bb_fflush_stdout_and_exit(EXIT_SUCCESS);
}
*/
-#include <stdio.h>
-#include <errno.h>
-#include <getopt.h> /* optind */
-#include <string.h>
-#include <stdlib.h>
#include "busybox.h"
static int read_stduu(FILE *src_stream, FILE *dst_stream)
if (optind == argc) {
src_stream = stdin;
} else if (optind + 1 == argc) {
- src_stream = bb_xfopen(argv[optind], "r");
+ src_stream = xfopen(argv[optind], "r");
} else {
bb_show_usage();
}
if (strcmp(outname, "-") == 0) {
dst_stream = stdout;
} else {
- dst_stream = bb_xfopen(outname, "w");
+ dst_stream = xfopen(outname, "w");
chmod(outname, mode & (S_IRWXU | S_IRWXG | S_IRWXO));
}
free(line);
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
+
#include "busybox.h"
/* Conversion table. for base 64 */
switch (argc - optind) {
case 2:
- src_stream = bb_xfopen(argv[optind], "r");
+ src_stream = xfopen(argv[optind], "r");
xstat(argv[optind], &stat_buf);
mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
if (src_stream == stdout) {
}
bb_printf(tbl == tbl_std ? "\n`\nend\n" : "\n====\n");
- bb_xferror(src_stream, "source"); /* TODO - Fix this! */
+ xferror(src_stream, "source"); /* TODO - Fix this! */
bb_fflush_stdout_and_exit(EXIT_SUCCESS);
}
* reduced size.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-#include <assert.h>
-#include <unistd.h>
-#include <sys/wait.h>
#include "busybox.h"
int watch_main(int argc, char **argv)
printf("\033[H\033[J%s %s\n", header, thyme);
- waitpid(bb_xspawn(watched_argv),0,0);
+ waitpid(xspawn(watched_argv),0,0);
sleep(period);
}
}
* Mini start-stop-daemon implementation(s) for busybox
*
* Written by Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>,
- * public domain.
* Adapted for busybox David Kimdon <dwhedon@gordian.com>
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <getopt.h> /* struct option */
-#include "pwd_.h"
+#include <getopt.h>
static int signal_nr = 15;
static int user_id = -1;
static int quiet;
-static char *userspec = NULL;
-static char *chuid = NULL;
-static char *cmdname = NULL;
-static char *execname = NULL;
-static char *pidfile = NULL;
+static char *userspec;
+static char *chuid;
+static char *cmdname;
+static char *execname;
+static char *pidfile;
struct pid_list {
struct pid_list *next;
return;
}
- procdir = bb_xopendir("/proc");
+ procdir = xopendir("/proc");
foundany = 0;
while ((entry = readdir(procdir)) != NULL) {
}
*--argv = startas;
if (opt & SSD_OPT_BACKGROUND) {
- bb_xdaemon(0, 0);
+ xdaemon(0, 0);
setsid();
}
if (opt & SSD_OPT_MAKEPID) {
/* user wants _us_ to make the pidfile */
- FILE *pidf = bb_xfopen(pidfile, "w");
+ FILE *pidf = xfopen(pidfile, "w");
pid_t pidt = getpid();
fprintf(pidf, "%d\n", pidt);
unsigned int mask;
int compat_type;
- buf = bb_xstrdup(str);
+ buf = xstrdup(str);
cp = buf;
while (cp && *cp) {
neg = 0;
int neg;
unsigned int mask;
- buf = bb_xstrdup(str);
+ buf = xstrdup(str);
cp = buf;
while (cp && *cp) {
neg = 0;
else
os = "(unknown os)";
- ret = bb_xstrdup(os);
+ ret = xstrdup(os);
return ret;
}
int len;
#endif
- cp = str = bb_xstrdup(device);
+ cp = str = xstrdup(device);
/* Skip over /dev/; if it's not present, give up. */
if (strncmp(cp, "/dev/", 5) != 0)
tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
for(s = strtok(p, ":"); s; s = strtok(NULL, ":")) {
- s = bb_xasprintf(tpl, s, type);
+ s = xasprintf(tpl, s, type);
if (stat(s, &st) == 0) break;
free(s);
}
return ENOMEM;
memset(inst, 0, sizeof(struct fsck_instance));
- prog = bb_xasprintf("fsck.%s", type);
+ prog = xasprintf("fsck.%s", type);
argv[0] = prog;
argc = 1;
FILE *f;
errcode_t retval;
- f = bb_xfopen(bad_blocks_file, "r");
+ f = xfopen(bad_blocks_file, "r");
retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
fclose (f);
mke2fs_error_msg_and_die(retval, "read bad blocks from list");
char *buf, *token, *next, *p, *arg;
int r_usage = 0;
- buf = bb_xstrdup(opts);
+ buf = xstrdup(opts);
for (token = buf; token && *token; token = next) {
p = strchr(token, ',');
next = 0;
{
char *buf, *token, *next, *p, *arg;
int journal_usage = 0;
- buf = bb_xstrdup(opts);
+ buf = xstrdup(opts);
for (token = buf; token && *token; token = next) {
p = strchr(token, ',');
next = 0;
/* Update our PATH to include /sbin */
#define PATH_SET "/sbin"
if (oldpath)
- oldpath = bb_xasprintf("%s:%s", PATH_SET, oldpath);
+ oldpath = xasprintf("%s:%s", PATH_SET, oldpath);
else
oldpath = PATH_SET;
putenv (oldpath);
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <strings.h>
-#include <time.h>
-#include <math.h>
-#include <ctype.h>
-#include <getopt.h>
-
-#include "xregex.h"
#include "busybox.h"
+#include "xregex.h"
+#include <math.h>
#define MAXVARFMT 240
static FILE *afopen(const char *path, const char *mode)
{
- return (*path == '-' && *(path+1) == '\0') ? stdin : bb_xfopen(path, mode);
+ return (*path == '-' && *(path+1) == '\0') ? stdin : xfopen(path, mode);
}
/* -------- working with variables (set/get/copy/etc) -------- */
/* same as setvar_p but make a copy of string */
static var *setvar_s(var *v, const char *value)
{
- return setvar_p(v, (value && *value) ? bb_xstrdup(value) : NULL);
+ return setvar_p(v, (value && *value) ? xstrdup(value) : NULL);
}
/* same as setvar_s but set USER flag */
/* if v is numeric and has no cached string, convert it to string */
if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) {
fmt_num(buf, MAXVARFMT, getvar_s(V[CONVFMT]), v->number, TRUE);
- v->string = bb_xstrdup(buf);
+ v->string = xstrdup(buf);
v->type |= VF_CACHED;
}
return (v->string == NULL) ? "" : v->string;
dest->type |= (src->type & ~VF_DONTTOUCH);
dest->number = src->number;
if (src->string)
- dest->string = bb_xstrdup(src->string);
+ dest->string = xstrdup(src->string);
}
handle_special(dest);
return dest;
if (seq->programname != programname) {
seq->programname = programname;
n = chain_node(OC_NEWSOURCE);
- n->l.s = bb_xstrdup(programname);
+ n->l.s = xstrdup(programname);
}
n = seq->last;
regmatch_t pmatch[2];
/* in worst case, each char would be a separate field */
- *slist = s1 = bb_xstrndup(s, strlen(s) * 2 + 3);
+ *slist = s1 = xstrndup(s, strlen(s) * 2 + 3);
c[0] = c[1] = (char)spl->info;
c[2] = c[3] = '\0';
var *v, *arg;
v = nvalloc(1);
- fmt = f = bb_xstrdup(getvar_s(evaluate(nextarg(&n), v)));
+ fmt = f = xstrdup(getvar_s(evaluate(nextarg(&n), v)));
i = 0;
while (*f) {
case B_up:
to_xxx = toupper;
lo_cont:
- s1 = s = bb_xstrdup(as[0]);
+ s1 = s = xstrdup(as[0]);
while (*s1) {
*s1 = (*to_xxx)(*s1);
s1++;
bb_perror_msg_and_die("popen");
X.rsm->is_pipe = 1;
} else {
- X.rsm->F = bb_xfopen(R.s, opn=='w' ? "w" : "a");
+ X.rsm->F = xfopen(R.s, opn=='w' ? "w" : "a");
}
}
X.F = X.rsm->F;
X.rsm->F = popen(L.s, "r");
X.rsm->is_pipe = TRUE;
} else {
- X.rsm->F = fopen(L.s, "r"); /* not bb_xfopen! */
+ X.rsm->F = fopen(L.s, "r"); /* not xfopen! */
}
}
} else {
{
char *exprc, *s, *s0, *s1;
- exprc = bb_xstrdup(expr);
+ exprc = xstrdup(expr);
if (!isalnum_(*exprc) || (s = strchr(exprc, '=')) == NULL) {
free(exprc);
return FALSE;
}
for (envp=environ; *envp; envp++) {
- s = bb_xstrdup(*envp);
+ s = xstrdup(*envp);
s1 = strchr(s, '=');
if (!s1) {
goto keep_going;
filename_start_ptr = temp + 1;
}
- return(bb_xstrdup(filename_start_ptr));
+ return(xstrdup(filename_start_ptr));
}
static int file_doesnt_exist(const char *filename)
if (ret & 1)
patch_level = bb_xgetlarg(p, 10, -1, USHRT_MAX);
if (ret & 2) {
- patch_file = bb_xfopen(i, "r");
+ patch_file = xfopen(i, "r");
} else {
patch_file = stdin;
}
bb_make_directory(new_filename, -1, FILEUTILS_RECUR);
*line_ptr = '/';
}
- dst_stream = bb_xfopen(new_filename, "w+");
+ dst_stream = xfopen(new_filename, "w+");
backup_filename = NULL;
} else {
backup_filename = xmalloc(strlen(new_filename) + 6);
bb_perror_msg_and_die("Couldnt create file %s",
backup_filename);
}
- dst_stream = bb_xfopen(new_filename, "w");
+ dst_stream = xfopen(new_filename, "w");
}
if ((backup_filename == NULL) || file_doesnt_exist(original_filename)) {
src_stream = NULL;
} else {
if (strcmp(original_filename, new_filename) == 0) {
- src_stream = bb_xfopen(backup_filename, "r");
+ src_stream = xfopen(backup_filename, "r");
} else {
- src_stream = bb_xfopen(original_filename, "r");
+ src_stream = xfopen(original_filename, "r");
}
}
sed_cmd_t *sed_cmd_next = sed_cmd->next;
if(sed_cmd->file)
- bb_xprint_and_close_file(sed_cmd->file);
+ xprint_and_close_file(sed_cmd->file);
if (sed_cmd->beg_match) {
regfree(sed_cmd->beg_match);
/* If lines glued together, put backslash back. */
if(filecmdstr[idx]=='\n') hack=1;
if(idx==start) bb_error_msg_and_die("Empty filename");
- *retval = bb_xstrndup(filecmdstr+start, idx-start+hack+1);
+ *retval = xstrndup(filecmdstr+start, idx-start+hack+1);
if(hack) *(idx+*retval)='\\';
return idx;
} else if(isspace(*cmdstr)) cmdstr++;
else break;
}
- sed_cmd->string = bb_xstrdup(cmdstr);
+ sed_cmd->string = xstrdup(cmdstr);
parse_escapes(sed_cmd->string,sed_cmd->string,strlen(cmdstr),0,0);
cmdstr += strlen(cmdstr);
/* handle file cmds: (r)ead */
bb_error_msg_and_die("Command only uses one address");
cmdstr += parse_file_cmd(sed_cmd, cmdstr, &sed_cmd->string);
if(sed_cmd->cmd=='w')
- sed_cmd->file=bb_xfopen(sed_cmd->string,"w");
+ sed_cmd->file=xfopen(sed_cmd->string,"w");
/* handle branch commands */
} else if (strchr(":btT", sed_cmd->cmd)) {
int length;
while(isspace(*cmdstr)) cmdstr++;
length = strcspn(cmdstr, semicolon_whitespace);
if (length) {
- sed_cmd->string = bb_xstrndup(cmdstr, length);
+ sed_cmd->string = xstrndup(cmdstr, length);
cmdstr += length;
}
}
/* Append this line to any unfinished line from last time. */
if (bbg.add_cmd_line) {
- cmdstr = bb_xasprintf("%s\n%s", bbg.add_cmd_line, cmdstr);
+ cmdstr = xasprintf("%s\n%s", bbg.add_cmd_line, cmdstr);
free(bbg.add_cmd_line);
bbg.add_cmd_line = cmdstr;
}
/* If this line ends with backslash, request next line. */
temp=strlen(cmdstr);
if(temp && cmdstr[temp-1]=='\\') {
- if (!bbg.add_cmd_line) bbg.add_cmd_line = bb_xstrdup(cmdstr);
+ if (!bbg.add_cmd_line) bbg.add_cmd_line = xstrdup(cmdstr);
bbg.add_cmd_line[temp-1] = 0;
return;
}
static void append(char *s)
{
- llist_add_to_end(&bbg.append_head, bb_xstrdup(s));
+ llist_add_to_end(&bbg.append_head, xstrdup(s));
}
static void flush_append(void)
char *tmp = strchr(pattern_space,'\n');
if(tmp) {
- tmp=bb_xstrdup(tmp+1);
+ tmp=xstrdup(tmp+1);
free(pattern_space);
pattern_space=tmp;
goto restart;
while ((line = bb_get_chomped_line_from_file(rfile))
!= NULL)
append(line);
- bb_xprint_and_close_file(rfile);
+ xprint_and_close_file(rfile);
}
break;
}
case 'g': /* Replace pattern space with hold space */
free(pattern_space);
- pattern_space = bb_xstrdup(bbg.hold_space ? bbg.hold_space : "");
+ pattern_space = xstrdup(bbg.hold_space ? bbg.hold_space : "");
break;
case 'G': /* Append newline and hold space to pattern space */
{
}
case 'h': /* Replace hold space with pattern space */
free(bbg.hold_space);
- bbg.hold_space = bb_xstrdup(pattern_space);
+ bbg.hold_space = xstrdup(pattern_space);
break;
case 'H': /* Append newline and pattern space to hold space */
{
static void add_cmd_block(char *cmdstr)
{
int go=1;
- char *temp=bb_xstrdup(cmdstr),*temp2=temp;
+ char *temp=xstrdup(cmdstr),*temp2=temp;
while(go) {
int len=strcspn(temp2,"\n");
FILE *cmdfile;
char *line;
- cmdfile = bb_xfopen(optarg, "r");
+ cmdfile = xfopen(optarg, "r");
while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
add_cmd(line);
getpat=0;
free(line);
}
- bb_xprint_and_close_file(cmdfile);
+ xprint_and_close_file(cmdfile);
break;
}
struct stat statbuf;
int nonstdoutfd;
- bbg.outname=bb_xstrndup(argv[i],strlen(argv[i])+6);
+ bbg.outname=xstrndup(argv[i],strlen(argv[i])+6);
strcat(bbg.outname,"XXXXXX");
if(-1==(nonstdoutfd=mkstemp(bbg.outname)))
bb_error_msg_and_die("no temp file");
#include "busybox.h"
-#include <string.h>
-#include <strings.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <time.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <setjmp.h>
-#include <regex.h>
-#include <ctype.h>
-#include <errno.h>
-#define vi_Version BB_VER " " BB_BT
#ifdef CONFIG_LOCALE_SUPPORT
#define Isprint(c) isprint((c))
for (; optind < argc; optind++) {
editing = 1; // 0=exit, 1=one file, 2+ =many files
free(cfn);
- cfn = (Byte *) bb_xstrdup(argv[optind]);
+ cfn = (Byte *) xstrdup(argv[optind]);
edit_file(cfn);
}
}
*q++ = *p;
*q = '\0';
}
- pat = (Byte *) bb_xstrdup((char *) buf); // save copy of pattern
+ pat = (Byte *) xstrdup((char *) buf); // save copy of pattern
if (*p == '/')
p++;
q = char_search(dot, pat, FORWARD, FULL);
// There is a read-able regular file
// make this the current file
- q = (Byte *) bb_xstrdup((char *) fn); // save the cfn
+ q = (Byte *) xstrdup((char *) fn); // save the cfn
free(cfn); // free the old name
cfn = q; // remember new cfn
if (strlen((char *) args) > 0) {
// user wants a new filename
free(cfn);
- cfn = (Byte *) bb_xstrdup((char *) args);
+ cfn = (Byte *) xstrdup((char *) args);
} else {
// user wants file status info
last_status_cksum = 0; // force status update
}
#endif /* CONFIG_FEATURE_VI_SEARCH */
} else if (strncasecmp((char *) cmd, "version", i) == 0) { // show software version
- psb("%s", vi_Version);
+ psb("%s", BB_VER " " BB_BT);
} else if (strncasecmp((char *) cmd, "write", i) == 0 // write text to file
|| strncasecmp((char *) cmd, "wq", i) == 0
|| strncasecmp((char *) cmd, "wn", i) == 0
}
refresh(FALSE);
free(obufp);
- obufp = (Byte *) bb_xstrdup((char *) buf);
+ obufp = (Byte *) xstrdup((char *) buf);
return (obufp);
}
// Stuff the last_modifying_cmd back into stdin
// and let it be re-executed.
if (last_modifying_cmd != 0) {
- ioq = ioq_start = (Byte *) bb_xstrdup((char *) last_modifying_cmd);
+ ioq = ioq_start = (Byte *) xstrdup((char *) last_modifying_cmd);
}
break;
#endif /* CONFIG_FEATURE_VI_DOT_CMD */
if (strlen((char *) q) > 1) { // new pat- save it and find
// there is a new pat
free(last_search_pattern);
- last_search_pattern = (Byte *) bb_xstrdup((char *) q);
+ last_search_pattern = (Byte *) xstrdup((char *) q);
goto dc3; // now find the pattern
}
// user changed mind and erased the "/"- do nothing
*/
#include "busybox.h"
-#include <stdio.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <string.h>
-#include <stdlib.h>
#include <fnmatch.h>
-#include <time.h>
-#include <ctype.h>
static char *pattern;
#ifdef CONFIG_FEATURE_FIND_PRINT0
int i;
char *cmd_string = "";
for (i = 0; i < num_matches; i++)
- cmd_string = bb_xasprintf("%s%s%s", cmd_string, exec_str[i], fileName);
- cmd_string = bb_xasprintf("%s%s", cmd_string, exec_str[num_matches]);
+ cmd_string = xasprintf("%s%s%s", cmd_string, exec_str[i], fileName);
+ cmd_string = xasprintf("%s%s", cmd_string, exec_str[num_matches]);
system(cmd_string);
goto no_match;
}
bb_error_msg_and_die(bb_msg_requires_arg, "-exec");
if (*argv[i] == ';')
break;
- cmd_string = bb_xasprintf("%s %s", cmd_string, argv[i]);
+ cmd_string = xasprintf("%s %s", cmd_string, argv[i]);
}
if (*cmd_string == 0)
while ((b_pos = strstr(cmd_string, "{}") - cmd_string), (b_pos >= 0)) {
num_matches++;
exec_str = xrealloc(exec_str, (num_matches + 1) * sizeof(char *));
- exec_str[num_matches - 1] = bb_xstrndup(cmd_string, b_pos);
+ exec_str[num_matches - 1] = xstrndup(cmd_string, b_pos);
cmd_string += b_pos + 2;
}
- exec_str[num_matches] = bb_xstrdup(cmd_string);
+ exec_str[num_matches] = xstrdup(cmd_string);
exec_opt = 1;
#endif
} else
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <getopt.h>
-#include <string.h>
-#include <errno.h>
#include "xregex.h"
/* Add the line to the circular 'before' buffer */
if(lines_before) {
free(before_buf[curpos]);
- before_buf[curpos] = bb_xstrdup(line);
+ before_buf[curpos] = xstrdup(line);
curpos = (curpos + 1) % lines_before;
}
}
fopt = cur->link;
free(cur);
- f = bb_xfopen(ffile, "r");
+ f = xfopen(ffile, "r");
while ((line = bb_get_chomped_line_from_file(f)) != NULL) {
llist_add_to(&pattern_head,
new_grep_list_data(line, PATTERN_MEM_A));
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/wait.h>
/* COMPAT: SYSV version defaults size (and has a max value of) to 470.
We try to make it as large as possible. */
int c, savec;
if (!tty_stream) {
- tty_stream = bb_xfopen(CURRENT_TTY, "r");
+ tty_stream = xfopen(CURRENT_TTY, "r");
/* pranoidal security by vodz */
fcntl(fileno(tty_stream), F_SETFD, FD_CLOEXEC);
}
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <malloc.h>
#include <netdb.h>
+#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/ioctl.h>
+#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
+#include <sys/statfs.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <termios.h>
+#include <time.h>
#include <unistd.h>
+#include <utime.h>
#ifdef CONFIG_SELINUX
#include <selinux/selinux.h>
#endif
+#ifdef CONFIG_LOCALE_SUPPORT
+#include <locale.h>
+#endif
+
#include "pwd_.h"
#include "grp_.h"
#include "shadow_.h"
extern const char *bb_mode_string(int mode);
extern int is_directory(const char *name, int followLinks, struct stat *statBuf);
-extern DIR *bb_opendir(const char *path);
-extern DIR *bb_xopendir(const char *path);
+extern DIR *warn_opendir(const char *path);
+extern DIR *xopendir(const char *path);
extern int remove_file(const char *path, int flags);
extern int copy_file(const char *source, const char *dest, int flags);
extern char *bb_get_chunk_from_file(FILE *file, int *end);
extern int bb_copyfd_size(int fd1, int fd2, const off_t size);
extern int bb_copyfd_eof(int fd1, int fd2);
-extern void bb_xprint_and_close_file(FILE *file);
-extern int bb_xprint_file_by_name(const char *filename);
extern char bb_process_escape_sequence(const char **ptr);
extern char *bb_get_last_path_component(char *path);
extern FILE *bb_wfopen(const char *path, const char *mode);
extern FILE *bb_wfopen_input(const char *filename);
-extern FILE *bb_xfopen(const char *path, const char *mode);
+extern FILE *xfopen(const char *path, const char *mode);
extern int bb_fclose_nonstdin(FILE *f);
extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN;
extern void xstat(const char *filename, struct stat *buf);
-extern int bb_xsocket(int domain, int type, int protocol);
-extern pid_t bb_spawn(char **argv);
-extern pid_t bb_xspawn(char **argv);
+extern int xsocket(int domain, int type, int protocol);
+extern pid_t spawn(char **argv);
+extern pid_t xspawn(char **argv);
extern int wait4pid(int pid);
-extern void bb_xdaemon(int nochdir, int noclose);
-extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
-extern void bb_xlisten(int s, int backlog);
-extern void bb_xchdir(const char *path);
+extern void xdaemon(int nochdir, int noclose);
+extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
+extern void xlisten(int s, int backlog);
+extern void xchdir(const char *path);
extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen);
extern char *utoa(unsigned n);
extern void itoa_to_buf(int n, char *buf, unsigned buflen);
__attribute__ ((format (printf, 1, 2)));
//#warning rename to xferror_filename?
-extern void bb_xferror(FILE *fp, const char *fn);
-extern void bb_xferror_stdout(void);
-extern void bb_xfflush_stdout(void);
+extern void xferror(FILE *fp, const char *fn);
+extern void xferror_stdout(void);
+extern void xfflush_stdout(void);
extern void bb_warn_ignoring_args(int n);
extern void *xzalloc(size_t size);
extern void *xcalloc(size_t nmemb, size_t size);
-extern char *bb_xstrdup (const char *s);
-extern char *bb_xstrndup (const char *s, int n);
+extern char *xstrdup (const char *s);
+extern char *xstrndup (const char *s, int n);
extern char *safe_strncpy(char *dst, const char *src, size_t size);
extern int safe_strtoi(char *arg, int* value);
extern int safe_strtod(char *arg, double* value);
char *concat_subpath_file(const char *path, const char *filename);
char *last_char_is(const char *s, int c);
-int read_package_field(const char *package_buffer, char **field_name, char **field_value);
//#warning yuk!
char *fgets_str(FILE *file, const char *terminating_string);
void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
void reset_ino_dev_hashtable(void);
-char *bb_xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
+char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
+void xprint_and_close_file(FILE *file);
#define FAIL_DELAY 3
extern void bb_do_delay(int seconds);
extern char *pw_encrypt(const char *clear, const char *salt);
extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
-extern int bb_xopen(const char *pathname, int flags);
-extern int bb_xopen3(const char *pathname, int flags, int mode);
+extern int xopen(const char *pathname, int flags);
+extern int xopen3(const char *pathname, int flags, int mode);
extern void xread(int fd, void *buf, size_t count);
extern unsigned char xread_char(int fd);
extern void xlseek(int fd, off_t offset, int whence);
void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
void *md5_end(void *resbuf, md5_ctx_t *ctx);
-extern uint32_t *bb_crc32_filltable (int endian);
+extern uint32_t *crc32_filltable (int endian);
#ifndef RB_POWER_OFF
/* Stop system and switch power off if possible. */
LIBBB-n:=
LIBBB-y:= \
- bb_asprintf.c ask_confirmation.c change_identity.c chomp.c \
+ ask_confirmation.c change_identity.c chomp.c \
compare_string_array.c concat_path_file.c copy_file.c copyfd.c \
crc32.c create_icmp_socket.c create_icmp6_socket.c \
device_open.c dump.c error_msg.c error_msg_and_die.c \
kernel_version.c last_char_is.c login.c \
make_directory.c md5.c mode_string.c mtab_file.c \
obscure.c parse_mode.c parse_number.c perror_msg.c \
- perror_msg_and_die.c print_file.c get_console.c \
+ perror_msg_and_die.c get_console.c \
process_escape_sequence.c procps.c qmodule.c \
- read_package_field.c recursive_action.c remove_file.c \
+ recursive_action.c remove_file.c \
restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
safe_strncpy.c setup_environment.c sha1.c simplify_path.c \
trim.c u_signal_names.c vdprintf.c verror_msg.c \
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
- bb_xsocket.c bb_xdaemon.c bb_xbind.c bb_xlisten.c bb_xchdir.c \
get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \
$(LIBBB_MOBJ6):$(LIBBB_MSRC6)
$(compile.c) -DL_$(notdir $*)
-LIBBB_MSRC7:=$(srcdir)/opendir.c
-LIBBB_MOBJ7:=$(call get-file-subparts, ${LIBBB_MSRC7})
-LIBBB_MOBJ7:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ7))
-$(LIBBB_MOBJ7):$(LIBBB_MSRC7)
- $(compile.c) -DL_$(notdir $*)
-
# We need the names of the object files built from MSRC for the L_ defines
LIBBB_ALL_MOBJ:=$(LIBBB_MOBJ0) $(LIBBB_MOBJ1) $(LIBBB_MOBJ2) $(LIBBB_MOBJ3) \
- $(LIBBB_MOBJ4) $(LIBBB_MOBJ5) $(LIBBB_MOBJ6) $(LIBBB_MOBJ7)
+ $(LIBBB_MOBJ4) $(LIBBB_MOBJ5) $(LIBBB_MOBJ6)
LIBBB_ALL_MSRC:=$(LIBBB_MSRC0) $(LIBBB_MSRC1) $(LIBBB_MSRC2) $(LIBBB_MSRC3) \
- $(LIBBB_MSRC4) $(LIBBB_MSRC5) $(LIBBB_MSRC6) $(LIBBB_MSRC7)
+ $(LIBBB_MSRC4) $(LIBBB_MSRC5) $(LIBBB_MSRC6)
LIBBB-y:=$(sort $(LIBBB-y) $(LIBBB_ALL_MSRC))
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * Copyright (C) 2002,2005 Vladimir Oleynik <dzo@simtreas.ru>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include "libbb.h"
-
-char *bb_xasprintf(const char *format, ...)
-{
- va_list p;
- int r;
- char *string_ptr;
-
-#ifdef HAVE_GNU_EXTENSIONS
- va_start(p, format);
- r = vasprintf(&string_ptr, format, p);
- va_end(p);
-#else
- va_start(p, format);
- r = vsnprintf(NULL, 0, format, p);
- va_end(p);
- string_ptr = xmalloc(r+1);
- va_start(p, format);
- r = vsnprintf(string_ptr, r+1, format, p);
- va_end(p);
-#endif
-
- if (r < 0) {
- bb_perror_msg_and_die("bb_xasprintf");
- }
- return string_ptr;
-}
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xbind.c - a bind() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "libbb.h"
-
-void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
-{
- if (bind(sockfd, my_addr, addrlen))
- bb_perror_msg_and_die("bind");
-}
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xchdir.c - a chdir() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-#include <unistd.h>
-#include "libbb.h"
-
-void bb_xchdir(const char *path)
-{
- if (chdir(path))
- bb_perror_msg_and_die("chdir(%s)", path);
-}
-
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xdaemon.c - a daemon() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <unistd.h>
-#include "libbb.h"
-
-#ifndef BB_NOMMU
-void bb_xdaemon(int nochdir, int noclose)
-{
- if (daemon(nochdir, noclose))
- bb_perror_msg_and_die("daemon");
-}
-#endif
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xlisten.c - a listen() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <sys/socket.h>
-#include "libbb.h"
-
-void bb_xlisten(int s, int backlog)
-{
- if (listen(s, backlog))
- bb_perror_msg_and_die("listen");
-}
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xsocket.c - a socket() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <sys/socket.h>
-#include "libbb.h"
-
-int bb_xsocket(int domain, int type, int protocol)
-{
- int r = socket(domain, type, protocol);
- if (r < 0)
- bb_perror_msg_and_die("socket");
- return r;
-}
* not addition '/' if path name already have '/'
*/
-#include <string.h>
#include "libbb.h"
char *concat_path_file(const char *path, const char *filename)
lc = last_char_is(path, '/');
while (*filename == '/')
filename++;
- return bb_xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
+ return xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
}
*/
#include "libbb.h"
-#include <utime.h>
-#include <errno.h>
int copy_file(const char *source, const char *dest, int flags)
{
}
/* Recursively copy files in SOURCE. */
- if ((dp = bb_opendir(source)) == NULL) {
+ if ((dp = opendir(source)) == NULL) {
status = -1;
goto preserve_status;
}
* endian = 0: little-endian
*/
-#include <stdio.h>
-#include <stdlib.h>
#include "libbb.h"
-uint32_t *bb_crc32_filltable (int endian) {
+uint32_t *crc32_filltable(int endian)
+{
uint32_t *crc_table = xmalloc(256 * sizeof(uint32_t));
uint32_t polynomial = endian ? 0x04c11db7 : 0xedb88320;
*/
#include "libbb.h"
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h> /* for isdigit() */
#include "dump.h"
enum _vflag bb_dump_vflag = FIRST;
*/
savech = *p2;
p1[1] = '\0';
- pr->fmt = bb_xstrdup(fmtp);
+ pr->fmt = xstrdup(fmtp);
*p2 = savech;
pr->cchar = pr->fmt + (p1 - fmtp);
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-#include <dirent.h>
-#include <stdlib.h>
#include "libbb.h"
char *find_block_device(char *path)
char devpath[PATH_MAX];
sprintf(devpath,"/dev/%s", entry->d_name);
if(!stat(devpath, &st) && S_ISBLK(st.st_mode) && st.st_rdev == dev) {
- retpath = bb_xstrdup(devpath);
+ retpath = xstrdup(devpath);
break;
}
}
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <getopt.h>
-#include <string.h>
-#include <assert.h>
-#include <stdlib.h>
#include "libbb.h"
+#include <getopt.h>
/* Documentation
#if defined(CONFIG_AR) || defined(CONFIG_TAR)
if((spec_flgs & FIRST_ARGV_IS_OPT)) {
if(argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') {
- argv[1] = bb_xasprintf("-%s", argv[1]);
+ argv[1] = xasprintf("-%s", argv[1]);
if(ENABLE_FEATURE_CLEAN_UP)
spec_flgs |= FREE_FIRST_ARGV_IS_OPT;
}
#include "libbb.h"
#include "inet_common.h"
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef DEBUG
-# include <resolv.h>
-#endif
-
const char bb_INET_default[] = "default";
pn->addr = *s_in;
pn->next = INET_nn;
pn->host = host;
- pn->name = bb_xstrdup(name);
+ pn->name = xstrdup(name);
INET_nn = pn;
return (0);
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <features.h>
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
#include "libbb.h"
/* For 2.6, use the cleaned up header to get the 64 bit API. */
if ((fd = open(device, O_RDONLY)) < 0) return 0;
if (!ioctl(fd, BB_LOOP_GET_STATUS, &loopinfo))
- dev=bb_xasprintf("%ld %s", (long) loopinfo.lo_offset,
+ dev=xasprintf("%ld %s", (long) loopinfo.lo_offset,
(char *)loopinfo.lo_file_name);
close(fd);
of crypt do not truncate passwords.
*/
-#include <ctype.h>
-#include <unistd.h>
-#include <string.h>
-#include <strings.h>
-
#include "libbb.h"
static int string_checker_helper(const char *p1, const char *p2) __attribute__ ((__pure__));
/* check string */
int ret = string_checker_helper(p1, p2);
/* Make our own copy */
- char *p = bb_xstrdup(p1);
+ char *p = xstrdup(p1);
/* reverse string */
size = strlen(p);
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * wrapper for opendir()
- *
- * Copyright (C) 2006 Bernhard Fischer <busybox@busybox.net>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <sys/types.h>
-#include <dirent.h>
-#include "libbb.h"
-
-#ifdef L_bb_opendir
-DIR *bb_opendir(const char *path)
-{
- DIR *dp;
-
- if ((dp = opendir(path)) == NULL) {
- bb_perror_msg("unable to open `%s'", path);
- return NULL;
- }
- return dp;
-}
-#endif
-
-#ifdef L_bb_xopendir
-DIR *bb_xopendir(const char *path)
-{
- DIR *dp;
-
- if ((dp = opendir(path)) == NULL) {
- bb_perror_msg_and_die("unable to open `%s'", path);
- }
- return dp;
-}
-#endif
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "libbb.h"
-
-void bb_xprint_and_close_file(FILE *file)
-{
- bb_xfflush_stdout();
- /* Note: Do not use STDOUT_FILENO here, as this is a lib routine
- * and the calling code may have reassigned stdout. */
- if (bb_copyfd_eof(fileno(file), STDOUT_FILENO) == -1) {
- /* bb_copyfd outputs any needed messages, so just die. */
- exit(bb_default_error_retval);
- }
- /* Note: Since we're reading, don't bother checking the return value
- * of fclose(). The only possible failure is EINTR which
- * should already have been taken care of. */
- fclose(file);
-}
-
-/* Returns:
- * 0 if successful
- * -1 if 'filename' does not exist or is a directory
- * exits with default error code if an error occurs
- */
-
-int bb_xprint_file_by_name(const char *filename)
-{
- FILE *f;
-
-#if 0
- /* This check shouldn't be necessary for linux, but is left
- * here disabled just in case. */
- struct stat statBuf;
-
- if(is_directory(filename, TRUE, &statBuf)) {
- bb_error_msg("%s: Is directory", filename);
- } else
-#endif
- if ((f = bb_wfopen(filename, "r")) != NULL) {
- bb_xprint_and_close_file(f);
- return 0;
- }
-
- return -1;
-}
struct stat sb;
if (!dir) {
- dir = bb_xopendir("/proc");
+ dir = xopendir("/proc");
}
for (;;) {
if ((entry = readdir(dir)) == NULL) {
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) many different people.
- * If you wrote this, please acknowledge your work.
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include "libbb.h"
-
-/*
- * Gets the next package field from package_buffer, seperated into the field name
- * and field value, it returns the int offset to the first character of the next field
- */
-int read_package_field(const char *package_buffer, char **field_name, char **field_value)
-{
- int offset_name_start = 0;
- int offset_name_end = 0;
- int offset_value_start = 0;
- int offset_value_end = 0;
- int offset = 0;
- int next_offset;
- int name_length;
- int value_length;
- int exit_flag = FALSE;
-
- if (package_buffer == NULL) {
- *field_name = NULL;
- *field_value = NULL;
- return(-1);
- }
- while (1) {
- next_offset = offset + 1;
- switch (package_buffer[offset]) {
- case('\0'):
- exit_flag = TRUE;
- break;
- case(':'):
- if (offset_name_end == 0) {
- offset_name_end = offset;
- offset_value_start = next_offset;
- }
- /* TODO: Name might still have trailing spaces if ':' isnt
- * immediately after name */
- break;
- case('\n'):
- /* TODO: The char next_offset may be out of bounds */
- if (package_buffer[next_offset] != ' ') {
- exit_flag = TRUE;
- break;
- }
- case('\t'):
- case(' '):
- /* increment the value start point if its a just filler */
- if (offset_name_start == offset) {
- offset_name_start++;
- }
- if (offset_value_start == offset) {
- offset_value_start++;
- }
- break;
- }
- if (exit_flag) {
- /* Check that the names are valid */
- offset_value_end = offset;
- name_length = offset_name_end - offset_name_start;
- value_length = offset_value_end - offset_value_start;
- if (name_length == 0) {
- break;
- }
- if ((name_length > 0) && (value_length > 0)) {
- break;
- }
-
- /* If not valid, start fresh with next field */
- exit_flag = FALSE;
- offset_name_start = offset + 1;
- offset_name_end = 0;
- offset_value_start = offset + 1;
- offset_value_end = offset + 1;
- offset++;
- }
- offset++;
- }
- if (name_length == 0) {
- *field_name = NULL;
- } else {
- *field_name = bb_xstrndup(&package_buffer[offset_name_start], name_length);
- }
- if (value_length > 0) {
- *field_value = bb_xstrndup(&package_buffer[offset_value_start], value_length);
- } else {
- *field_value = NULL;
- }
- return(next_offset);
-}
-
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <string.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <stdlib.h> /* free() */
#include "libbb.h"
#undef DEBUG_RECURS_ACTION
} else if (status == SKIP)
return TRUE;
}
- dir = bb_opendir(fileName);
+ dir = opendir(fileName);
if (!dir) {
return FALSE;
}
return 0;
}
- if ((dp = bb_opendir(path)) == NULL) {
+ if ((dp = opendir(path)) == NULL) {
return -1;
}
args = (const char **) xmalloc (sizeof (char *) * ( 4 + additional_args_cnt ));
- args [0] = bb_get_last_path_component ( bb_xstrdup ( shell ));
+ args [0] = bb_get_last_path_component ( xstrdup ( shell ));
if ( loginshell )
- args [0] = bb_xasprintf ("-%s", args [0]);
+ args [0] = xasprintf ("-%s", args [0]);
if ( command ) {
args [argno++] = "-c";
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdlib.h>
#include "libbb.h"
char *bb_simplify_path(const char *path)
char *s, *start, *p;
if (path[0] == '/')
- start = bb_xstrdup(path);
+ start = xstrdup(path);
else {
s = xgetcwd(NULL);
start = concat_path_file(s, path);
*
*/
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <errno.h>
-#include <netdb.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
#include "libbb.h"
/* Return network byte ordered port number for a service.
int xconnect(struct sockaddr_in *s_addr)
{
- int s = bb_xsocket(AF_INET, SOCK_STREAM, 0);
+ int s = xsocket(AF_INET, SOCK_STREAM, 0);
if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0)
{
if (ENABLE_FEATURE_CLEAN_UP) close(s);
* Utility routines.
*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
+ * Copyright (C) 2006 Rob Landley
+ * Copyright (C) 2006 Denis Vlasenko
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
#include "busybox.h"
#ifndef DMALLOC
#endif /* DMALLOC */
#ifdef L_xstrdup
-char * bb_xstrdup (const char *s)
+char * xstrdup (const char *s)
{
char *t;
#endif
#ifdef L_xstrndup
-char * bb_xstrndup (const char *s, int n)
+char * xstrndup (const char *s, int n)
{
char *t;
if (ENABLE_DEBUG && s == NULL)
- bb_error_msg_and_die("bb_xstrndup bug");
+ bb_error_msg_and_die("xstrndup bug");
t = xmalloc(++n);
#endif
#ifdef L_xfopen
-FILE *bb_xfopen(const char *path, const char *mode)
+FILE *xfopen(const char *path, const char *mode)
{
FILE *fp;
if ((fp = fopen(path, mode)) == NULL)
#endif
#ifdef L_xopen
-int bb_xopen(const char *pathname, int flags)
+int xopen(const char *pathname, int flags)
{
- return bb_xopen3(pathname, flags, 0777);
+ return xopen3(pathname, flags, 0777);
}
#endif
#ifdef L_xopen3
-int bb_xopen3(const char *pathname, int flags, int mode)
+int xopen3(const char *pathname, int flags, int mode)
{
int ret;
#endif
#ifdef L_xferror
-void bb_xferror(FILE *fp, const char *fn)
+void xferror(FILE *fp, const char *fn)
{
if (ferror(fp)) {
bb_error_msg_and_die("%s", fn);
#endif
#ifdef L_xferror_stdout
-void bb_xferror_stdout(void)
+void xferror_stdout(void)
{
- bb_xferror(stdout, bb_msg_standard_output);
+ xferror(stdout, bb_msg_standard_output);
}
#endif
#ifdef L_xfflush_stdout
-void bb_xfflush_stdout(void)
+void xfflush_stdout(void)
{
if (fflush(stdout)) {
bb_perror_msg_and_die(bb_msg_standard_output);
#ifdef L_spawn
// This does a fork/exec in one call, using vfork().
-pid_t bb_spawn(char **argv)
+pid_t spawn(char **argv)
{
static int failed;
pid_t pid;
#endif
#ifdef L_xspawn
-pid_t bb_xspawn(char **argv)
+pid_t xspawn(char **argv)
{
- pid_t pid = bb_spawn(argv);
+ pid_t pid = spawn(argv);
if (pid < 0) bb_perror_msg_and_die("%s", *argv);
return pid;
}
return pos + 1;
}
#endif
+
+#ifdef L_xasprintf
+char *xasprintf(const char *format, ...)
+{
+ va_list p;
+ int r;
+ char *string_ptr;
+
+#if 1
+ // GNU extension
+ va_start(p, format);
+ r = vasprintf(&string_ptr, format, p);
+ va_end(p);
+#else
+ // Bloat for systems that haven't got the GNU extension.
+ va_start(p, format);
+ r = vsnprintf(NULL, 0, format, p);
+ va_end(p);
+ string_ptr = xmalloc(r+1);
+ va_start(p, format);
+ r = vsnprintf(string_ptr, r+1, format, p);
+ va_end(p);
+#endif
+
+ if (r < 0) bb_perror_msg_and_die("xasprintf");
+ return string_ptr;
+}
+#endif
+
+#ifdef L_xprint_and_close_file
+void xprint_and_close_file(FILE *file)
+{
+ // copyfd outputs error messages for us.
+ if (bb_copyfd_eof(fileno(file), 1) == -1) exit(bb_default_error_retval);
+
+ fclose(file);
+}
+#endif
+
+#ifdef L_xchdir
+void xchdir(const char *path)
+{
+ if (chdir(path))
+ bb_perror_msg_and_die("chdir(%s)", path);
+}
+#endif
+
+#ifdef L_warn_opendir
+DIR *warn_opendir(const char *path)
+{
+ DIR *dp;
+
+ if ((dp = opendir(path)) == NULL) {
+ bb_perror_msg("unable to open `%s'", path);
+ return NULL;
+ }
+ return dp;
+}
+#endif
+
+#ifdef L_xopendir
+DIR *xopendir(const char *path)
+{
+ DIR *dp;
+
+ if ((dp = opendir(path)) == NULL)
+ bb_perror_msg_and_die("unable to open `%s'", path);
+ return dp;
+}
+#endif
+
+#ifdef L_xdaemon
+#ifndef BB_NOMMU
+void xdaemon(int nochdir, int noclose)
+{
+ if (daemon(nochdir, noclose)) bb_perror_msg_and_die("daemon");
+}
+#endif
+#endif
+
+#ifdef L_xbind
+void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
+{
+ if (bind(sockfd, my_addr, addrlen)) bb_perror_msg_and_die("bind");
+}
+#endif
+
+#ifdef L_xsocket
+int xsocket(int domain, int type, int protocol)
+{
+ int r = socket(domain, type, protocol);
+
+ if (r < 0) bb_perror_msg_and_die("socket");
+
+ return r;
+}
+#endif
+
+#ifdef L_xlisten
+void xlisten(int s, int backlog)
+{
+ if (listen(s, backlog)) bb_perror_msg_and_die("listen");
+}
+#endif
*
*/
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-
#include "busybox.h"
/* make sure gr_name isn't taken, make sure gid is kosher
struct group *grp;
const int max = 65000;
- etc_group = bb_xfopen(bb_path_group_file, "r");
+ etc_group = xfopen(bb_path_group_file, "r");
/* make sure gr_name isn't taken, make sure gid is kosher */
desired = g->gr_gid;
return 1;
/* add entry to group */
- file = bb_xfopen(bb_path_group_file, "a");
+ file = xfopen(bb_path_group_file, "a");
/* group:passwd:gid:userlist */
fprintf(file, "%s:%s:%d:%s\n", group, "x", gr.gr_gid, user);
fclose(file);
#if ENABLE_FEATURE_SHADOWPASSWDS
- file = bb_xfopen(bb_path_gshadow_file, "a");
+ file = xfopen(bb_path_gshadow_file, "a");
fprintf(file, "%s:!::\n", group);
fclose(file);
#endif
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <stdio.h>
-#include <sys/types.h>
-#include <string.h>
-#include <unistd.h>
-#include <time.h>
-#include <getopt.h>
-#include <sys/stat.h>
-
#include "busybox.h"
#define DONT_SET_PASS (1 << 4)
const int min = 500;
const int max = 65000;
- passwd = bb_xfopen(filename, "r");
+ passwd = xfopen(filename, "r");
/* EDR if uid is out of bounds, set to min */
if ((p->pw_uid > max) || (p->pw_uid < min))
{
char *cmd;
- cmd = bb_xasprintf("addgroup -g %d \"%s\"", p->pw_gid, p->pw_name);
+ cmd = xasprintf("addgroup -g %d \"%s\"", p->pw_gid, p->pw_name);
system(cmd);
free(cmd);
}
int addgroup = !p->pw_gid;
/* make sure everything is kosher and setup uid && gid */
- file = bb_xfopen(bb_path_passwd_file, "a");
+ file = xfopen(bb_path_passwd_file, "a");
fseek(file, 0, SEEK_END);
switch (passwd_study(bb_path_passwd_file, p)) {
#if ENABLE_FEATURE_SHADOWPASSWDS
/* add to shadow if necessary */
- file = bb_xfopen(bb_path_shadow_file, "a");
+ file = xfopen(bb_path_shadow_file, "a");
fseek(file, 0, SEEK_END);
fprintf(file, "%s:!:%ld:%d:%d:%d:::\n",
p->pw_name, /* username */
*
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include <getopt.h>
-#include <termios.h>
#include "busybox.h"
#ifdef CONFIG_FEATURE_UTMP
const char *p = op->initstring;
char *q;
- q = op->initstring = bb_xstrdup(op->initstring);
+ q = op->initstring = xstrdup(op->initstring);
/* copy optarg into op->initstring decoding \ddd
octal codes into chars */
while (*p) {
};
#ifdef DEBUGGING
- dbf = bb_xfopen(DEBUGTERM, "w");
+ dbf = xfopen(DEBUGTERM, "w");
{
int i;
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <utime.h>
-#include <syslog.h>
-#include <time.h>
-#include <sys/resource.h>
-#include <errno.h>
-
#include "busybox.h"
+#include <syslog.h>
static char crypt_passwd[128];
bb_show_usage();
}
}
- myname = (char *) bb_xstrdup(bb_getpwuid(NULL, getuid(), -1));
+ myname = (char *) xstrdup(bb_getpwuid(NULL, getuid(), -1));
/* exits on error */
if (optind < argc) {
name = argv[optind];
*/
#include "busybox.h"
-#include <signal.h>
#include <syslog.h>
-#include <sys/resource.h>
-#include <time.h>
-
int su_main ( int argc, char **argv )
{
the user, especially if someone su's from a su-shell.
But getlogin can fail -- usually due to lack of utmp entry.
in this case resort to getpwuid. */
- old_user = bb_xstrdup(USE_FEATURE_UTMP(getlogin() ? : ) (pw = getpwuid(cur_uid)) ? pw->pw_name : "");
+ old_user = xstrdup(USE_FEATURE_UTMP(getlogin() ? : ) (pw = getpwuid(cur_uid)) ? pw->pw_name : "");
tty = ttyname(2) ? : "none";
openlog(bb_applet_name, 0, LOG_AUTH);
}
/* Fixed by Erik Andersen to do passwords the tinylogin way...
* It now works with md5, sha1, etc passwords. */
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/vt.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <termios.h>
-
#include "busybox.h"
+#include <sys/vt.h>
static struct passwd *pw;
static struct vt_mode ovtm;
bb_error_msg_and_die("Unknown uid %d", getuid());
}
- vfd = bb_xopen(CURRENT_TTY, O_RDWR);
+ vfd = xopen(CURRENT_TTY, O_RDWR);
if (ioctl(vfd, VT_GETMODE, &vtm) < 0) {
bb_perror_msg_and_die("VT_GETMODE");
#define VERSION "2.3.2"
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <signal.h>
-#include <getopt.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/resource.h>
+#include <sys/syslog.h>
#define arysize(ary) (sizeof(ary)/sizeof((ary)[0]))
* change directory
*/
- bb_xchdir(CDir);
+ xchdir(CDir);
signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
* version - his died. ;(
*/
/* reexec for vfork() do continue parent */
vfork_daemon_rexec(1, 0, ac, av, "-f");
#else
- bb_xdaemon(1, 0);
+ xdaemon(1, 0);
#endif
}
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <signal.h>
-#include <getopt.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/resource.h>
#ifndef CRONTABS
#define CRONTABS "/var/spool/cron/crontabs"
static int GetReplaceStream(const char *user, const char *file);
static int ChangeUser(const char *user, short dochdir);
-int
-crontab_main(int ac, char **av)
+int crontab_main(int ac, char **av)
{
enum { NONE, EDIT, LIST, REPLACE, DELETE } option = NONE;
const struct passwd *pas;
* Change directory to our crontab directory
*/
- bb_xchdir(CDir);
+ xchdir(CDir);
/*
* Handle options as appropriate
char buf[1024];
snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid());
- fd = bb_xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600);
+ fd = xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600);
chown(tmp, getuid(), getgid());
if ((fi = fopen(pas->pw_name, "r"))) {
while ((n = fread(buf, 1, sizeof(buf), fi)) > 0)
return 0;
}
-static int
-GetReplaceStream(const char *user, const char *file)
+static int GetReplaceStream(const char *user, const char *file)
{
int filedes[2];
int pid;
exit(0);
bb_default_error_retval = 0;
- fd = bb_xopen3(file, O_RDONLY, 0);
+ fd = xopen3(file, O_RDONLY, 0);
buf[0] = 0;
write(filedes[1], buf, 1);
while ((n = read(fd, buf, sizeof(buf))) > 0) {
exit(0);
}
-static void
-EditFile(const char *user, const char *file)
+static void EditFile(const char *user, const char *file)
{
int pid;
wait4(pid, NULL, 0, NULL);
}
-static int
-ChangeUser(const char *user, short dochdir)
+static int ChangeUser(const char *user, short dochdir)
{
struct passwd *pas;
if (dochdir) {
if (chdir(pas->pw_dir) < 0) {
bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir);
- bb_xchdir(TMPDIR);
+ xchdir(TMPDIR);
}
}
return(pas->pw_uid);
if (chdir (mount_point) != 0)
devfsd_perror_msg_and_die(mount_point);
- fd = bb_xopen (".devfsd", O_RDONLY);
+ fd = xopen (".devfsd", O_RDONLY);
if (fcntl (fd, F_SETFD, FD_CLOEXEC) != 0)
devfsd_perror_msg_and_die("FD_CLOEXEC");
num_args -= 3;
for (count = 0; count < num_args; ++count)
- new->u.execute.argv[count] = bb_xstrdup (p[count]);
+ new->u.execute.argv[count] = xstrdup (p[count]);
new->u.execute.argv[num_args] = NULL;
break;
if (num_args != 2)
goto process_config_line_err; /* missing path and function in line */
- new->u.copy.source = bb_xstrdup (p[0]);
- new->u.copy.destination = bb_xstrdup (p[1]);
+ new->u.copy.source = xstrdup (p[0]);
+ new->u.copy.destination = xstrdup (p[1]);
break;
case 8: /* IGNORE */
/* FALLTROUGH */
*/
#include "busybox.h"
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <ctype.h>
-#include <sys/ioctl.h>
-#include <sys/sysmacros.h>
-#include <sys/times.h>
-#include <sys/mman.h>
-#include <linux/types.h>
#include <linux/hdreg.h>
-#if BB_BIG_ENDIAN && !defined(__USE_XOPEN)
-# define __USE_XOPEN
-#endif
-#include <unistd.h>
-
/* device types */
/* ------------ */
#define NO_DEV 0xffff
unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
const char *fmt = " %s\t= %2ld";
- fd = bb_xopen(devname, O_RDONLY|O_NONBLOCK);
+ fd = xopen(devname, O_RDONLY|O_NONBLOCK);
printf("\n%s:\n", devname);
if (set_readahead)
*/
#include "busybox.h"
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
#include <utmp.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <time.h>
#ifndef SHUTDOWN_TIME
# define SHUTDOWN_TIME 254
if (argc > 1) {
bb_show_usage();
}
- file = bb_xopen(bb_path_wtmp_file, O_RDONLY);
+ file = xopen(bb_path_wtmp_file, O_RDONLY);
printf("%-10s %-14s %-18s %-12.12s %s\n", "USER", "TTY", "HOST", "LOGIN", "TIME");
while ((n = safe_read(file, (void*)&ut, sizeof(struct utmp))) != 0) {
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-#include <ctype.h>
#ifdef CONFIG_FEATURE_LESS_REGEXP
#include "xregex.h"
for (i = 0; i <= num_flines; i++) {
safe_strncpy(current_line, flines[i], 256);
- flines[i] = bb_xasprintf("%5d %s", i + 1, current_line);
+ flines[i] = xasprintf("%5d %s", i + 1, current_line);
}
}
char current_line[256];
FILE *fp;
- fp = (inp_stdin) ? stdin : bb_xfopen(filename, "r");
+ fp = (inp_stdin) ? stdin : xfopen(filename, "r");
flines = NULL;
for (i = 0; (feof(fp)==0) && (i <= MAXLINES); i++) {
strcpy(current_line, "");
fgets(current_line, 256, fp);
if (fp != stdin)
- bb_xferror(fp, filename);
+ xferror(fp, filename);
flines = xrealloc(flines, (i+1) * sizeof(char *));
- flines[i] = bb_xstrdup(current_line);
+ flines[i] = xstrdup(current_line);
}
num_flines = i - 2;
fclose(fp);
if (inp == NULL)
- inp = (inp_stdin) ? bb_xfopen(CURRENT_TTY, "r") : stdin;
+ inp = (inp_stdin) ? xfopen(CURRENT_TTY, "r") : stdin;
if (flags & FLAG_N)
add_linenumbers();
/* Fill the buffer until the end of the file or the
end of the buffer is reached */
for (i = 0; (i < (height - 1)) && (i <= num_flines); i++) {
- buffer[i] = bb_xstrdup(flines[i]);
+ buffer[i] = xstrdup(flines[i]);
}
/* If the buffer still isn't full, fill it with blank lines */
for (; i < (height - 1); i++) {
- buffer[i] = bb_xstrdup("");
+ buffer[i] = xstrdup("");
}
}
line_pos += nlines;
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
}
}
else {
line_pos += 1;
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
}
}
}
line_pos -= nlines;
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
}
}
else {
line_pos -= 1;
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
}
}
}
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
if (i < tilde_line - nlines + 1)
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
else {
if (line_pos >= num_flines - height + 2)
- buffer[i] = bb_xstrdup("~\n");
+ buffer[i] = xstrdup("~\n");
}
}
}
else if (linenum < (num_flines - height - 2)) {
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[linenum + i]);
+ buffer[i] = xstrdup(flines[linenum + i]);
}
line_pos = linenum;
buffer_print();
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
if (linenum + i < num_flines + 2)
- buffer[i] = bb_xstrdup(flines[linenum + i]);
+ buffer[i] = xstrdup(flines[linenum + i]);
else
- buffer[i] = bb_xstrdup((flags & FLAG_TILDE) ? "\n" : "~\n");
+ buffer[i] = xstrdup((flags & FLAG_TILDE) ? "\n" : "~\n");
}
line_pos = linenum;
/* Set past_eof so buffer_down and buffer_up act differently */
newline_offset = strlen(filename) - 1;
filename[newline_offset] = '\0';
- files[num_files] = bb_xstrdup(filename);
+ files[num_files] = xstrdup(filename);
current_file = num_files + 1;
num_files++;
char *growline = "";
regmatch_t match_structs;
- line2 = bb_xstrdup(line);
+ line2 = xstrdup(line);
match_found = 0;
match_status = regexec(pattern, line2, 1, &match_structs, 0);
match_found = 1;
if (action) {
- growline = bb_xasprintf("%s%.*s%s%.*s%s", growline, match_structs.rm_so, line2, HIGHLIGHT, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so, NORMAL);
+ growline = xasprintf("%s%.*s%s%.*s%s", growline, match_structs.rm_so, line2, HIGHLIGHT, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so, NORMAL);
}
else {
- growline = bb_xasprintf("%s%.*s%.*s", growline, match_structs.rm_so - 4, line2, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so);
+ growline = xasprintf("%s%.*s%.*s", growline, match_structs.rm_so - 4, line2, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so);
}
line2 += match_structs.rm_eo;
match_status = regexec(pattern, line2, 1, &match_structs, REG_NOTBOL);
}
- growline = bb_xasprintf("%s%s", growline, line2);
+ growline = xasprintf("%s%s", growline, line2);
return (match_found ? growline : line);
/* Get rid of all the highlights we added previously */
for (i = 0; i <= num_flines; i++) {
current_line = process_regex_on_line(flines[i], &old_pattern, 0);
- flines[i] = bb_xstrdup(current_line);
+ flines[i] = xstrdup(current_line);
}
}
old_pattern = pattern;
/* Run the regex on each line of the current file here */
for (i = 0; i <= num_flines; i++) {
current_line = process_regex_on_line(flines[i], &pattern, 1);
- flines[i] = bb_xstrdup(current_line);
+ flines[i] = xstrdup(current_line);
if (match_found) {
match_lines = xrealloc(match_lines, (j + 1) * sizeof(int));
match_lines[j] = i;
fgets(current_line, 256, inp);
current_line[strlen(current_line) - 1] = '\0';
if (strlen(current_line) > 1) {
- fp = bb_xfopen(current_line, "w");
+ fp = xfopen(current_line, "w");
for (i = 0; i < num_flines; i++)
fprintf(fp, "%s", flines[i]);
fclose(fp);
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <time.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/sysmacros.h> /* major() and minor() */
#ifdef CONFIG_FEATURE_MAKEDEVS_LEAF
int makedevs_main(int argc, char **argv)
unsigned long flags;
flags = bb_getopt_ulflags(argc, argv, "d:", &line);
if (line)
- table = bb_xfopen(line, "r");
+ table = xfopen(line, "r");
if (optind >= argc || (rootdir=argv[optind])==NULL) {
bb_error_msg_and_die("root directory not specified");
}
- bb_xchdir(rootdir);
+ xchdir(rootdir);
umask(0);
*/
#include "busybox.h"
-#include <sys/stat.h>
-#include <errno.h> /* errno */
-#include <string.h> /* strerror */
-#include <getopt.h> /* optind */
int mountpoint_main(int argc, char **argv)
{
if (S_ISDIR(st.st_mode)) {
dev_t st_dev = st.st_dev;
ino_t st_ino = st.st_ino;
- char *p = bb_xasprintf("%s/..", arg);
+ char *p = xasprintf("%s/..", arg);
if (stat(p, &st) == 0) {
short ret = (st_dev != st.st_dev) ||
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include <sys/mtio.h>
-#include <fcntl.h>
struct mt_opcodes {
char *name;
break;
}
- fd = bb_xopen3(file, mode, 0);
+ fd = xopen3(file, mode, 0);
switch (code->value) {
case MTTELL:
*/
#include "busybox.h"
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <termios.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-
#define SOH 0x01
#define STX 0x02
bb_show_usage();
fn = argv[1];
- ttyfd = bb_xopen3(CURRENT_TTY, O_RDWR, 0);
- filefd = bb_xopen3(fn, O_RDWR|O_CREAT|O_TRUNC, 0666);
+ ttyfd = xopen3(CURRENT_TTY, O_RDWR, 0);
+ filefd = xopen3(fn, O_RDWR|O_CREAT|O_TRUNC, 0666);
if (tcgetattr(ttyfd, &tty) < 0)
bb_error_msg_and_die("%s: tcgetattr failed: %m\n", argv[0]);
*/
#include "busybox.h"
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <signal.h>
#define OPT_FOREGROUND 0x01
#define OPT_TIMER 0x02
if (!(opts & OPT_FOREGROUND))
vfork_daemon_rexec(0, 1, argc, argv, "-F");
#else
- bb_xdaemon(0, 1);
+ xdaemon(0, 1);
#endif
signal(SIGHUP, watchdog_shutdown);
signal(SIGINT, watchdog_shutdown);
- fd = bb_xopen(argv[argc - 1], O_WRONLY);
+ fd = xopen(argv[argc - 1], O_WRONLY);
while (1) {
/*
*/
#include "busybox.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <errno.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <ctype.h>
-#include <assert.h>
-#include <string.h>
-#include <getopt.h>
-#include <fcntl.h>
#include <sys/utsname.h>
#if !defined(CONFIG_FEATURE_2_4_MODULES) && \
if (fullname[0] == '\0')
return (FALSE);
else {
- char *tmp, *tmp1 = bb_xstrdup(filename);
+ char *tmp, *tmp1 = xstrdup(filename);
tmp = bb_get_last_path_component(tmp1);
if (strcmp(tmp, fullname) == 0) {
free(tmp1);
/* Stop searching if we find a match */
- m_filename = bb_xstrdup(filename);
+ m_filename = xstrdup(filename);
return (FALSE);
}
free(tmp1);
* (which is .got) similar to branch,
* but is full 32 bits relative */
- assert(got != 0);
*loc += got - dot;
break;
goto bb_use_plt;
case R_ARM_GOTOFF: /* address relative to the got */
- assert(got != 0);
*loc += v - got;
break;
break;
case R_386_GOTPC:
- assert(got != 0);
*loc += got - dot;
break;
goto bb_use_got;
case R_386_GOTOFF:
- assert(got != 0);
*loc += v - got;
break;
# ifdef R_68K_GOTOFF
case R_68K_GOTOFF:
- assert(got != 0);
*loc += v - got;
break;
# endif
struct mips_hi16 *next;
unsigned long insn;
- /* The value for the HI16 had best be the same. */
- assert(v == l->value);
-
/* Do the HI16 relocation. Note that we actually don't
need to know anything about the LO16 itself, except where
to find the low 16 bits of the addend needed by the LO16. */
case R_390_PLT32:
case R_390_PLT16DBL:
/* find the plt entry and initialize it. */
- assert(isym != NULL);
pe = (struct arch_single_entry *) &isym->pltent;
- assert(pe->allocated);
if (pe->inited == 0) {
ip = (unsigned long *)(ifile->plt->contents + pe->offset);
ip[0] = 0x0d105810; /* basr 1,0; lg 1,10(1); br 1 */
break;
case R_390_GOTPC:
- assert(got != 0);
*(unsigned long *) loc += got - dot;
break;
case R_390_GOT12:
case R_390_GOT16:
case R_390_GOT32:
- assert(isym != NULL);
- assert(got != 0);
if (!isym->gotent.inited)
{
isym->gotent.inited = 1;
# define R_390_GOTOFF32 R_390_GOTOFF
# endif
case R_390_GOTOFF32:
- assert(got != 0);
*loc += v - got;
break;
break;
case R_SH_GOTPC:
- assert(got != 0);
*loc = got - dot + rel->r_addend;
break;
goto bb_use_got;
case R_SH_GOTOFF:
- assert(got != 0);
*loc = v - got;
break;
case R_X86_64_GOTPCREL:
goto bb_use_got;
# if 0
- assert(isym != NULL);
if (!isym->gotent.reloc_done)
{
isym->gotent.reloc_done = 1;
bb_use_plt:
/* find the plt entry and initialize it if necessary */
- assert(isym != NULL);
#if defined(CONFIG_USE_PLT_LIST)
for (pe = isym->pltent; pe != NULL && pe->addend != rel->r_addend;)
pe = pe->next;
- assert(pe != NULL);
#else
pe = &isym->pltent;
#endif
#if defined(CONFIG_USE_GOT_ENTRIES)
bb_use_got:
- assert(isym != NULL);
/* needs an entry in the .got: set it, once */
if (!isym->gotent.inited) {
isym->gotent.inited = 1;
} else {
myrelsec = obj_create_alloced_section(f, name,
size, offset);
- assert(myrelsec);
}
return myrelsec;
};
if (realpath(filename, real)) {
- absolute_filename = bb_xstrdup(real);
+ absolute_filename = xstrdup(real);
}
else {
int save_errno = errno;
bb_error_msg("cannot get realpath for %s", filename);
errno = save_errno;
perror("");
- absolute_filename = bb_xstrdup(filename);
+ absolute_filename = xstrdup(filename);
}
lm_name = strlen(m_name);
break;
case 'o': /* name the output module */
free(m_name);
- m_name = bb_xstrdup(optarg);
+ m_name = xstrdup(optarg);
break;
case 'L': /* Stub warning */
/* This is needed for compatibility with modprobe.
}
/* Grab the module name */
- tmp1 = bb_xstrdup(argv[optind]);
+ tmp1 = xstrdup(argv[optind]);
tmp = basename(tmp1);
len = strlen(tmp);
#if defined(CONFIG_FEATURE_2_6_MODULES)
if (k_version > 4)
- m_fullName = bb_xasprintf("%s.ko", tmp);
+ m_fullName = xasprintf("%s.ko", tmp);
else
#endif
- m_fullName = bb_xasprintf("%s.o", tmp);
+ m_fullName = xasprintf("%s.o", tmp);
if (!m_name) {
m_name = tmp;
bb_error_msg_and_die("%s: no module by that name found", m_fullName);
}
} else
- m_filename = bb_xstrdup(argv[optind]);
+ m_filename = xstrdup(argv[optind]);
if (flag_verbose)
printf("Using %s\n", m_filename);
struct stat st;
unsigned long len;
void *map;
- char *filename, *options = bb_xstrdup("");
+ char *filename, *options = xstrdup("");
filename = argv[1];
if (!filename) {
strcat(options, " ");
}
- fd = bb_xopen3(filename, O_RDONLY, 0);
+ fd = xopen3(filename, O_RDONLY, 0);
fstat(fd, &st);
len = st.st_size;
#include "busybox.h"
#include <sys/utsname.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <getopt.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <string.h>
-#include <ctype.h>
-#include <fcntl.h>
#include <fnmatch.h>
struct mod_opt_t { /* one-way list of options to pass to a module */
ol = opt_list = xmalloc( sizeof( struct mod_opt_t ) );
}
- ol-> m_opt_val = bb_xstrdup( opt );
+ ol-> m_opt_val = xstrdup( opt );
ol-> m_next = NULL;
return opt_list;
* dst: pointer to where to store the parsed argument
* return value: the pointer to the first char after the parsed argument,
* NULL if there was no argument parsed (only trailing spaces).
- * Note that memory is allocated with bb_xstrdup when a new argument was
+ * Note that memory is allocated with xstrdup when a new argument was
* parsed. Don't forget to free it!
*/
#define ARG_EMPTY 0x00
/* Reached the start of an argument
* By the way, we duplicate a little too much
* here but what is too much is freed later. */
- *dst = tmp_str = bb_xstrdup( src );
+ *dst = tmp_str = xstrdup( src );
/* Get to the end of that argument */
while( ( *tmp_str != '\0' )
&& ( ( *tmp_str != ' ' )
(*current)-> m_next = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t ));
(*current) = (*current)-> m_next;
}
- (*current)-> m_name = bb_xstrdup ( alias );
+ (*current)-> m_name = xstrdup ( alias );
(*current)-> m_isalias = 1;
if (( strcmp ( mod, "off" ) == 0 ) || ( strcmp ( mod, "null" ) == 0 )) {
else {
(*current)-> m_depcnt = 1;
(*current)-> m_deparr = xmalloc ( 1 * sizeof( char * ));
- (*current)-> m_deparr[0] = bb_xstrdup ( mod );
+ (*current)-> m_deparr[0] = xstrdup ( mod );
}
(*current)-> m_next = 0;
}
k_version = un.release[2] - '0';
}
- filename = bb_xasprintf("/lib/modules/%s/modules.dep", un.release );
+ filename = xasprintf("/lib/modules/%s/modules.dep", un.release );
fd = open ( filename, O_RDONLY );
if (ENABLE_FEATURE_CLEAN_UP)
free(filename);
if (( *(col-2) == '.' ) && ( *(col-1) == 'o' ))
dot = col - 2;
- mod = bb_xstrndup ( mods, dot - mods );
+ mod = xstrndup ( mods, dot - mods );
/* enqueue new module */
if ( !current ) {
current = current-> m_next;
}
current-> m_name = mod;
- current-> m_path = bb_xstrdup(modpath);
+ current-> m_path = xstrdup(modpath);
current-> m_options = NULL;
current-> m_isalias = 0;
current-> m_depcnt = 0;
/* Cope with blank lines */
if ((next-deps-ext+1) <= 0)
continue;
- dep = bb_xstrndup ( deps, next - deps - ext + 1 );
+ dep = xstrndup ( deps, next - deps - ext + 1 );
/* Add the new dependable module name */
current-> m_depcnt++;
/* Only 2.6 has a modules.alias file */
if (ENABLE_FEATURE_2_6_MODULES) {
/* Parse kernel-declared aliases */
- filename = bb_xasprintf("/lib/modules/%s/modules.alias", un.release);
+ filename = xasprintf("/lib/modules/%s/modules.alias", un.release);
if ((fd = open ( filename, O_RDONLY )) < 0) {
/* Ok, that didn't work. Fall back to looking in /lib/modules */
fd = open ( "/lib/modules/modules.alias", O_RDONLY );
printf("%s module %s\n", do_insert?"Loading":"Unloading", list-> m_name );
}
if (!show_only) {
- int rc2 = wait4pid(bb_spawn(argv));
+ int rc2 = wait4pid(spawn(argv));
if (do_insert) {
rc = rc2; /* only last module matters */
char* mod;
char* p;
- pat = bb_xstrdup (pat_src);
- mod = bb_xstrdup (mod_src);
+ pat = xstrdup (pat_src);
+ mod = xstrdup (mod_src);
for (p = pat; (p = strchr(p, '-')); *p++ = '_' );
for (p = mod; (p = strchr(p, '-')); *p++ = '_' );
*/
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <ctype.h>
-#include <string.h>
-
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <features.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
-#include <netdb.h>
#include <netinet/ether.h>
-
-#ifdef __linux__
#include <linux/if.h>
-#endif
#include "busybox.h"
*/
#ifdef PF_PACKET
# define whereto_t sockaddr_ll
-# define make_socket() bb_xsocket(PF_PACKET, SOCK_RAW, 0)
+# define make_socket() xsocket(PF_PACKET, SOCK_RAW, 0)
#else
# define whereto_t sockaddr
-# define make_socket() bb_xsocket(AF_INET, SOCK_PACKET, SOCK_PACKET)
+# define make_socket() xsocket(AF_INET, SOCK_PACKET, SOCK_PACKET)
#endif
#ifdef DEBUG
*/
#include "busybox.h"
-
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/syslog.h>
-
-#include <pwd.h>
-
#include <sys/syslog.h>
-#include <time.h>
-#include <sys/socket.h>
-#include <errno.h>
#include <sys/uio.h>
else
port = se->s_port;
- s = bb_xsocket(AF_INET, SOCK_STREAM, 0);
+ s = xsocket(AF_INET, SOCK_STREAM, 0);
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
- bb_xbind(s, (struct sockaddr *)&addr, len);
- bb_xlisten(s, 5);
+ xbind(s, (struct sockaddr *)&addr, len);
+ xlisten(s, 5);
movefd(s, 0);
}
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/ioctl.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <sys/socket.h>
-
#include "busybox.h"
+#include <getopt.h>
typedef struct ftp_host_info_s {
char *user;
/* only make a local file if we know that one exists on the remote server */
if (fd_local == -1) {
if (do_continue) {
- fd_local = bb_xopen(local_path, O_APPEND | O_WRONLY);
+ fd_local = xopen(local_path, O_APPEND | O_WRONLY);
} else {
- fd_local = bb_xopen(local_path, O_CREAT | O_TRUNC | O_WRONLY);
+ fd_local = xopen(local_path, O_CREAT | O_TRUNC | O_WRONLY);
}
}
if ((local_path[0] == '-') && (local_path[1] == '\0')) {
fd_local = STDIN_FILENO;
} else {
- fd_local = bb_xopen(local_path, O_RDONLY);
+ fd_local = xopen(local_path, O_RDONLY);
fstat(fd_local, &sbuf);
sprintf(buf, "ALLO %lu", (unsigned long)sbuf.st_size);
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <errno.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <getopt.h>
#include "busybox.h"
+#include <getopt.h>
extern char *optarg; /* in unistd.h */
extern int optind, opterr, optopt; /* in unistd.h */
bb_perror_msg_and_die("sethostname");
}
} else {
- f = bb_xfopen(s, "r");
+ f = xfopen(s, "r");
while (fgets(buf, 255, f) != NULL) {
if (buf[0] =='#') {
continue;
* IPV6 support added by Bart Visscher <magick@linux-fan.com>
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h> /* strcmp and friends */
-#include <ctype.h> /* isdigit and friends */
-#include <stddef.h> /* offsetof */
-#include <unistd.h>
-#include <netdb.h>
-#include <sys/ioctl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
}
/* Create a channel to the NET kernel. */
- sockfd = bb_xsocket(AF_INET, SOCK_DGRAM, 0);
+ sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);
/* get interface name */
safe_strncpy(ifr.ifr_name, *argv, IFNAMSIZ);
/* TODO: standardise execute() return codes to return 0 for success and 1 for failure */
-#include <sys/stat.h>
+#include "busybox.h"
#include <sys/utsname.h>
-#include <sys/wait.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
#include <fnmatch.h>
#include <getopt.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "busybox.h"
#define MAX_OPT_DEPTH 10
#define EUNBALBRACK 10001
defn = xzalloc(sizeof(struct interfaces_file_t));
- f = bb_xfopen(filename, "r");
+ f = xfopen(filename, "r");
while ((buf = bb_get_chomped_line_from_file(f)) != NULL) {
char *buf_ptr = buf;
currmap->match = xrealloc(currmap->match, sizeof(currmap->match) * currmap->max_matches);
}
- currmap->match[currmap->n_matches++] = bb_xstrdup(firstword);
+ currmap->match[currmap->n_matches++] = xstrdup(firstword);
}
currmap->max_mappings = 0;
currmap->n_mappings = 0;
return NULL;
}
- currif->iface = bb_xstrdup(iface_name);
+ currif->iface = xstrdup(iface_name);
currif->address_family = get_address_family(addr_fams, address_family_name);
if (!currif->address_family) {
}
/* Add the interface to the list */
- llist_add_to_end(&(defn->autointerfaces), bb_xstrdup(firstword));
+ llist_add_to_end(&(defn->autointerfaces), xstrdup(firstword));
debug_noise("\nauto %s\n", firstword);
}
currently_processing = NONE;
opt = xrealloc(currif->option, sizeof(*opt) * currif->max_options);
currif->option = opt;
}
- currif->option[currif->n_options].name = bb_xstrdup(firstword);
- currif->option[currif->n_options].value = bb_xstrdup(buf_ptr);
+ currif->option[currif->n_options].name = xstrdup(firstword);
+ currif->option[currif->n_options].value = xstrdup(buf_ptr);
if (!currif->option[currif->n_options].name) {
perror(filename);
return NULL;
bb_error_msg("duplicate script in mapping \"%s\"", buf);
return NULL;
} else {
- currmap->script = bb_xstrdup(next_word(&buf_ptr));
+ currmap->script = xstrdup(next_word(&buf_ptr));
}
} else if (strcmp(firstword, "map") == 0) {
if (currmap->max_mappings == currmap->n_mappings) {
currmap->max_mappings = currmap->max_mappings * 2 + 1;
currmap->mapping = xrealloc(currmap->mapping, sizeof(char *) * currmap->max_mappings);
}
- currmap->mapping[currmap->n_mappings] = bb_xstrdup(next_word(&buf_ptr));
+ currmap->mapping[currmap->n_mappings] = xstrdup(next_word(&buf_ptr));
currmap->n_mappings++;
} else {
bb_error_msg("misplaced option \"%s\"", buf);
char *here;
char *there;
- result = bb_xasprintf(format, name, value);
+ result = xasprintf(format, name, value);
for (here = there = result; *there != '=' && *there; there++) {
if (*there == '-')
}
}
- buf = bb_xasprintf("run-parts /etc/network/if-%s.d", opt);
+ buf = xasprintf("run-parts /etc/network/if-%s.d", opt);
if (doit(buf) != 1) {
return 0;
}
int i, status;
pid_t pid;
- char *logical = bb_xstrdup(physical);
+ char *logical = xstrdup(physical);
/* Run the mapping script. */
pid = popen2(&in, &out, map->script, physical, NULL);
/* iface_down */
const llist_t *list = state_list;
while (list) {
- llist_add_to_end(&target_list, bb_xstrdup(list->data));
+ llist_add_to_end(&target_list, xstrdup(list->data));
list = list->link;
}
target_list = defn->autointerfaces;
int okay = 0;
int cmds_ret;
- iface = bb_xstrdup(target_list->data);
+ iface = xstrdup(target_list->data);
target_list = target_list->link;
pch = strchr(iface, '=');
if (pch) {
*pch = '\0';
- liface = bb_xstrdup(pch + 1);
+ liface = xstrdup(pch + 1);
} else {
- liface = bb_xstrdup(iface);
+ liface = xstrdup(iface);
}
if (!force) {
llist_t *iface_state = find_iface_state(state_list, iface);
if (cmds == iface_up) {
- char *newiface = bb_xasprintf("%s=%s", iface, liface);
+ char *newiface = xasprintf("%s=%s", iface, liface);
if (iface_state == NULL) {
llist_add_to_end(&state_list, newiface);
} else {
if (!no_act) {
FILE *state_fp = NULL;
- state_fp = bb_xfopen(statefile, "w");
+ state_fp = xfopen(statefile, "w");
while (state_list) {
if (state_list->data) {
fputs(state_list->data, state_fp);
*
*/
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/file.h>
-#include <sys/wait.h>
-#include <sys/resource.h>
-
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <signal.h>
-#include <netdb.h>
-#include <syslog.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#include <time.h>
-
#include "busybox.h"
+#include <syslog.h>
//#define CONFIG_FEATURE_INETD_RPC
//#define CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO
/* reexec for vfork() do continue parent */
vfork_daemon_rexec (0, 0, argc, argv, "-f");
#else
- bb_xdaemon (0, 0);
+ xdaemon (0, 0);
#endif
} else {
setsid ();
*/
#include "busybox.h"
-
-#include <sys/syslog.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
+#include <syslog.h>
#include <net/if.h>
#include <netinet/ether.h>
if (strlen(*a) > IF_NAMESIZE)
serror("interface name `%s' too long", *a);
ch = xzalloc(sizeof(mactable_t));
- ch->ifname = bb_xstrdup(*a++);
+ ch->ifname = xstrdup(*a++);
ch->mac = cc_macaddr(*a++);
if (clist)
clist->prev = ch;
clist = ch;
}
} else {
- ifh = bb_xfopen(fname, "r");
+ ifh = xfopen(fname, "r");
while ((line = bb_get_line_from_file(ifh)) != NULL) {
char *line_ptr;
}
name_length = strcspn(line_ptr, " \t");
ch = xzalloc(sizeof(mactable_t));
- ch->ifname = bb_xstrndup(line_ptr, name_length);
+ ch->ifname = xstrndup(line_ptr, name_length);
if (name_length > IF_NAMESIZE)
serror("interface name `%s' too long", ch->ifname);
line_ptr += name_length;
alarm(wsecs);
}
- if (infile) cfd = bb_xopen(infile, O_RDWR);
+ if (infile) cfd = xopen(infile, O_RDWR);
else {
opt = 1;
- sfd = bb_xsocket(AF_INET, SOCK_STREAM, 0);
+ sfd = xsocket(AF_INET, SOCK_STREAM, 0);
fcntl(sfd, F_SETFD, FD_CLOEXEC);
setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt));
address.sin_family = AF_INET;
if (lport != 0) {
address.sin_port = lport;
- bb_xbind(sfd, (struct sockaddr *) &address, sizeof(address));
+ xbind(sfd, (struct sockaddr *) &address, sizeof(address));
}
if (do_listen) {
socklen_t addrlen = sizeof(address);
- bb_xlisten(sfd, do_listen);
+ xlisten(sfd, do_listen);
// If we didn't specify a port number, query and print it to stderr.
* remove ridiculous amounts of bloat.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <unistd.h>
-#include <fcntl.h>
+#include "busybox.h"
+#include "inet_common.h"
#include <getopt.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
#include <net/route.h>
#include <net/if.h>
-#include "busybox.h"
-#include "inet_common.h"
+
#ifndef RTF_UP
/* Keep this in sync with /usr/src/linux/include/linux/route.h */
const char *netmask = NULL;
int skfd, isnet, xflag;
- assert((action == RTACTION_ADD) || (action == RTACTION_DEL));
-
/* Grab the -net or -host options. Remember they were transformed. */
xflag = kw_lookup(tbl_hash_net_host, &args);
}
/* Create a socket to the INET kernel. */
- skfd = bb_xsocket(AF_INET, SOCK_DGRAM, 0);
+ skfd = xsocket(AF_INET, SOCK_DGRAM, 0);
if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) {
bb_perror_msg_and_die("SIOC[ADD|DEL]RT");
int prefix_len, skfd;
const char *devname;
- assert((action == RTACTION_ADD) || (action == RTACTION_DEL));
-
- {
/* We know args isn't NULL from the check in route_main. */
const char *target = *args++;
bb_error_msg_and_die("resolving %s", target);
}
}
- }
/* Clean out the RTREQ structure. */
memset((char *) &rt, 0, sizeof(struct in6_rtmsg));
}
/* Create a socket to the INET6 kernel. */
- skfd = bb_xsocket(AF_INET6, SOCK_DGRAM, 0);
+ skfd = xsocket(AF_INET6, SOCK_DGRAM, 0);
rt.rtmsg_ifindex = 0;
struct sockaddr_in s_addr;
struct in_addr mask;
- FILE *fp = bb_xfopen("/proc/net/route", "r");
+ FILE *fp = xfopen("/proc/net/route", "r");
bb_printf("Kernel IP routing table\n"
"Destination Gateway Genmask"
int iflags, metric, refcnt, use, prefix_len, slen;
struct sockaddr_in6 snaddr6;
- FILE *fp = bb_xfopen("/proc/net/ipv6_route", "r");
+ FILE *fp = xfopen("/proc/net/ipv6_route", "r");
bb_printf("Kernel IPv6 routing table\n%-44s%-40s"
"Flags Metric Ref Use Iface\n",
#endif
displayroutes(noresolve, opt & ROUTE_OPT_e);
- bb_xferror_stdout();
+ xferror_stdout();
bb_fflush_stdout_and_exit(EXIT_SUCCESS);
}
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
* ------------------------------------------------------------------------- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include <fcntl.h>
-
#include "busybox.h"
char *buf=xmalloc(tftp_bufsize += 4);
if ((socketfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
- /* need to unlink the localfile, so don't use bb_xsocket here. */
+ /* need to unlink the localfile, so don't use xsocket here. */
bb_perror_msg("socket");
return EXIT_FAILURE;
}
len = sizeof(sa);
memset(&sa, 0, len);
- bb_xbind(socketfd, (struct sockaddr *)&sa, len);
+ xbind(socketfd, (struct sockaddr *)&sa, len);
sa.sin_family = host->h_addrtype;
sa.sin_port = port;
struct ifreq ibuf[(32 * 1024) / sizeof(struct ifreq)], ifr;
struct IFADDRLIST *st_ifaddrlist;
- fd = bb_xsocket(AF_INET, SOCK_DGRAM, 0);
+ fd = xsocket(AF_INET, SOCK_DGRAM, 0);
ifc.ifc_len = sizeof(ibuf);
ifc.ifc_buf = (caddr_t)ibuf;
struct IFADDRLIST *al;
char buf[256], tdevice[256], device[256];
- f = bb_xfopen(route, "r");
+ f = xfopen(route, "r");
/* Find the appropriate interface */
n = 0;
hi = xcalloc(1, sizeof(*hi));
addr = inet_addr(host);
if ((int32_t)addr != -1) {
- hi->name = bb_xstrdup(host);
+ hi->name = xstrdup(host);
hi->n = 1;
hi->addrs = xcalloc(1, sizeof(hi->addrs[0]));
hi->addrs[0] = addr;
hp = xgethostbyname(host);
if (hp->h_addrtype != AF_INET || hp->h_length != 4)
bb_perror_msg_and_die("bad host %s", host);
- hi->name = bb_xstrdup(hp->h_name);
+ hi->name = xstrdup(hp->h_name);
for (n = 0, p = hp->h_addr_list; *p != NULL; ++n, ++p)
continue;
hi->n = n;
bb_perror_msg_and_die("unknown protocol %s", cp);
/* Insure the socket fds won't be 0, 1 or 2 */
- do n = bb_xopen(bb_dev_null, O_RDONLY); while (n < 2);
+ do n = xopen(bb_dev_null, O_RDONLY); while (n < 2);
if (n > 2)
close(n);
- s = bb_xsocket(AF_INET, SOCK_RAW, pe->p_proto);
+ s = xsocket(AF_INET, SOCK_RAW, pe->p_proto);
#ifdef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG
if (op & USAGE_OP_DEBUG)
(void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on,
sizeof(on));
- sndsock = bb_xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);
+ sndsock = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);
#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE
#if defined(IP_OPTIONS)
outip->ip_src = from->sin_addr;
#ifndef IP_HDRINCL
- bb_xbind(sndsock, (struct sockaddr *)from, sizeof(*from));
+ xbind(sndsock, (struct sockaddr *)from, sizeof(*from));
#endif
fprintf(stderr, "traceroute to %s (%s)", hostname, inet_ntoa(to->sin_addr));
#define COMBINED_BINARY
-#define xfopen bb_xfopen
-
void udhcp_background(const char *pidfile);
void udhcp_start_log_and_pid(const char *client_server, const char *pidfile);
void udhcp_logging(int level, const char *fmt, ...);
envp = xzalloc(sizeof(char *) * (num_options + 5));
j = 0;
- envp[j++] = bb_xasprintf("interface=%s", client_config.interface);
- envp[j++] = bb_xasprintf("PATH=%s",
+ envp[j++] = xasprintf("interface=%s", client_config.interface);
+ envp[j++] = xasprintf("PATH=%s",
getenv("PATH") ? : "/bin:/usr/bin:/sbin:/usr/sbin");
- envp[j++] = bb_xasprintf("HOME=%s", getenv("HOME") ? : "/");
+ envp[j++] = xasprintf("HOME=%s", getenv("HOME") ? : "/");
if (packet == NULL) return envp;
/* Fill in a subnet bits option for things like /24 */
if (dhcp_options[i].code == DHCP_SUBNET) {
memcpy(&subnet, temp, 4);
- envp[j++] = bb_xasprintf("mask=%d", mton(&subnet));
+ envp[j++] = xasprintf("mask=%d", mton(&subnet));
}
}
if (packet->siaddr) {
if (!(over & FILE_FIELD) && packet->file[0]) {
/* watch out for invalid packets */
packet->file[sizeof(packet->file) - 1] = '\0';
- envp[j++] = bb_xasprintf("boot_file=%s", packet->file);
+ envp[j++] = xasprintf("boot_file=%s", packet->file);
}
if (!(over & SNAME_FIELD) && packet->sname[0]) {
/* watch out for invalid packets */
packet->sname[sizeof(packet->sname) - 1] = '\0';
- envp[j++] = bb_xasprintf("sname=%s", packet->sname);
+ envp[j++] = xasprintf("sname=%s", packet->sname);
}
return envp;
}
/* BB_AUDIT SUSv3 N/A */
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <string.h>
-#include <limits.h>
#include "busybox.h"
+#include <net/if.h>
/* Stuff from linux/if_vlan.h, kernel version 2.4.23 */
enum vlan_ioctl_cmds {
/* Don't bother closing the filedes. It will be closed on cleanup. */
/* Will die if 802.1q is not present */
- bb_xopen3(conf_file_name, O_RDONLY, 0);
+ xopen3(conf_file_name, O_RDONLY, 0);
memset(&ifr, 0, sizeof(struct vlan_ioctl_args));
}
}
- fd = bb_xsocket(AF_INET, SOCK_STREAM, 0);
+ fd = xsocket(AF_INET, SOCK_STREAM, 0);
if (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) {
bb_perror_msg_and_die("ioctl error for %s", *argv);
}
*/
#include "busybox.h"
-#include <errno.h>
-#include <signal.h>
-#include <sys/ioctl.h>
#include <getopt.h>
if (use_proxy) {
proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy");
if (proxy && *proxy) {
- parse_url(bb_xstrdup(proxy), &server);
+ parse_url(xstrdup(proxy), &server);
} else {
use_proxy = 0;
}
output = stdout;
quiet_flag = TRUE;
} else {
- output = bb_xfopen(fname_out, (do_continue ? "a" : "w"));
+ output = xfopen(fname_out, (do_continue ? "a" : "w"));
}
/*
}
if (strcasecmp(buf, "location") == 0) {
if (s[0] == '/')
- target.path = bb_xstrdup(s+1);
+ target.path = xstrdup(s+1);
else {
- parse_url(bb_xstrdup(s), &target);
+ parse_url(xstrdup(s), &target);
if (use_proxy == 0) {
server.host = target.host;
server.port = target.port;
* FTP session
*/
if (! target.user)
- target.user = bb_xstrdup("anonymous:busybox@");
+ target.user = xstrdup("anonymous:busybox@");
sfp = open_socket(&s_in);
if (ftpcmd(NULL, NULL, sfp, buf) != 220)
*sp++ = '\0';
h->path = sp;
} else
- h->path = bb_xstrdup("");
+ h->path = xstrdup("");
up = strrchr(h->host, '@');
if (up != NULL) {
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
/*
* Function Prototypes
return -2;
}
- tmpname = bb_xasprintf("%s%.*s", PROC_PATH, (int)(equals - name), name);
- outname = bb_xstrdup(tmpname + strlen(PROC_PATH));
+ tmpname = xasprintf("%s%.*s", PROC_PATH, (int)(equals - name), name);
+ outname = xstrdup(tmpname + strlen(PROC_PATH));
while ((cptr = strchr(tmpname, '.')) != NULL)
*cptr = '/';
bb_error_msg(ERR_INVALID_KEY, setting);
tmpname = concat_path_file(PROC_PATH, name);
- outname = bb_xstrdup(tmpname + strlen(PROC_PATH));
+ outname = xstrdup(tmpname + strlen(PROC_PATH));
while ((cptr = strchr(tmpname, '.')) != NULL)
*cptr = '/';
char *tmpdir;
struct stat ts;
- if (!(dp = bb_opendir(path))) {
+ if (!(dp = opendir(path))) {
retval = -1;
} else {
while ((de = readdir(dp)) != NULL) {
*/
#include "busybox.h"
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/ioctl.h>
//#define CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE /* + 2k */
-#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
-#include <time.h>
-#include <fcntl.h>
-#include <netinet/in.h> /* htons */
-#endif
-
-
typedef int (*cmp_t)(procps_status_t *P, procps_status_t *Q);
static procps_status_t *top; /* Hehe */
static void get_jiffy_counts(void)
{
- FILE* fp = bb_xfopen("stat", "r");
+ FILE* fp = xfopen("stat", "r");
prev_jif = jif;
if (fscanf(fp, "cpu %lld %lld %lld %lld %lld %lld %lld %lld",
&jif.usr,&jif.nic,&jif.sys,&jif.idle,
unsigned int needs_conversion = 1;
/* read memory info */
- fp = bb_xfopen("meminfo", "r");
+ fp = xfopen("meminfo", "r");
/*
* Old kernels (such as 2.4.x) had a nice summary of memory info that
fclose(fp);
/* read load average as a string */
- fp = bb_xfopen("loadavg", "r");
+ fp = xfopen("loadavg", "r");
buf[0] = '\0';
fgets(buf, sizeof(buf), fp);
end = strchr(buf, ' ');
}
/* change to /proc */
- bb_xchdir("/proc");
+ xchdir("/proc");
#ifdef CONFIG_FEATURE_USE_TERMIOS
tcgetattr(0, (void *) &initial_settings);
memcpy(&new_settings, &initial_settings, sizeof(struct termios));
{
#ifdef CONFIG_ASH_EXPAND_PRMT
free(cmdedit_prompt);
- cmdedit_prompt = bb_xstrdup(s);
+ cmdedit_prompt = xstrdup(s);
#else
cmdedit_prompt = s;
#endif
int status = 0;
for (sp = cmdenviron; sp; sp = sp->next)
- setvareq(bb_xstrdup(sp->text), VSTRFIXED | VTEXTFIXED);
+ setvareq(xstrdup(sp->text), VSTRFIXED | VTEXTFIXED);
if (argc >= 2) { /* That's what SVR2 does */
char *fullname;
printf("\033[7m%c\033[0m", c);
} else
#endif
- putchar(c);
+ if (initial_settings.c_lflag & ECHO) putchar(c);
if (++cmdedit_x >= cmdedit_termw) {
/* terminal is scrolled down */
cmdedit_y++;
my_euid = geteuid();
entry = getpwuid(my_euid);
if (entry) {
- user_buf = bb_xstrdup(entry->pw_name);
- home_pwd_buf = bb_xstrdup(entry->pw_dir);
+ user_buf = xstrdup(entry->pw_name);
+ home_pwd_buf = xstrdup(entry->pw_dir);
}
#endif
while ((entry = getpwent()) != NULL) {
/* Null usernames should result in all users as possible completions. */
if ( /*!userlen || */ !strncmp(ud, entry->pw_name, userlen)) {
- add_match(bb_xasprintf("~%s", entry->pw_name), '/');
+ add_match(xasprintf("~%s", entry->pw_name), '/');
}
}
*p = xmalloc(npth * sizeof(char *));
tmp = pth;
- (*p)[0] = bb_xstrdup(tmp);
+ (*p)[0] = xstrdup(tmp);
npth = 1; /* count words is + 1 count ':' */
for (;;) {
if (!matches)
return; /* not found */
/* find minimal match */
- tmp1 = bb_xstrdup(matches[0]);
+ tmp1 = xstrdup(matches[0]);
for (tmp = tmp1; *tmp; tmp++)
for (len_found = 1; len_found < num_matches; len_found++)
if (matches[len_found][(tmp - tmp1)] != *tmp) {
{
if(command_ps[0] != 0 || history[cur_history] == 0) {
free(history[cur_history]);
- history[cur_history] = bb_xstrdup(command_ps);
+ history[cur_history] = xstrdup(command_ps);
}
cur_history--;
}
for(i = 0; i < (MAX_HISTORY-1); i++)
history[i] = history[i+1];
}
- history[i++] = bb_xstrdup(command);
+ history[i++] = xstrdup(command);
cur_history = i;
n_history = i;
#if defined(CONFIG_FEATURE_SH_FANCY_PROMPT)
* variable. */
int export_me=0;
char *name, *value;
- name = bb_xstrdup(child->argv[i]);
+ name = xstrdup(child->argv[i]);
debug_printf("Local environment set: %s\n", name);
value = strchr(name, '=');
if (value)
debug_printf("\nrunning script '%s'\n", argv[optind]);
global_argv = argv+optind;
global_argc = argc-optind;
- input = bb_xfopen(argv[optind], "r");
+ input = xfopen(argv[optind], "r");
opt = parse_file_outer(input);
#ifdef CONFIG_FEATURE_CLEAN_UP
return NULL;
}
- token = bb_xstrndup(string, *ix);
+ token = xstrndup(string, *ix);
return token;
}
/* We need a clean copy, so strsep can mess up the copy while
* we write stuff into the original (in a minute) */
- cmd = cmd_copy = bb_xstrdup(command);
+ cmd = cmd_copy = xstrdup(command);
*command = '\0';
for (ix = 0, tmpcmd = cmd;
(tmpcmd = strsep_space(cmd, &ix)) != NULL; cmd += ix, ix=0) {
prog->argv[argc_l] = NULL;
if (!return_command) {
- job->text = bb_xstrdup(*command_ptr);
+ job->text = xstrdup(*command_ptr);
} else {
/* This leaves any trailing spaces, which is a bit sloppy */
- job->text = bb_xstrndup(*command_ptr, return_command - *command_ptr);
+ job->text = xstrndup(*command_ptr, return_command - *command_ptr);
}
*command_ptr = return_command;
input = NULL;
if (local_pending_command != 0)
bb_error_msg_and_die("multiple -c arguments");
- local_pending_command = bb_xstrdup(argv[optind]);
+ local_pending_command = xstrdup(argv[optind]);
optind++;
argv = argv+optind;
break;
}
} else if (!local_pending_command && argv[optind]) {
//printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
- input = bb_xfopen(argv[optind], "r");
+ input = xfopen(argv[optind], "r");
/* be lazy, never mark this closed */
llist_add_to(&close_me_list, (void *)(long)fileno(input));
}
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h> /* for our signal() handlers */
-#include <string.h> /* strncpy() */
-#include <errno.h> /* errno and friends */
-#include <unistd.h>
-#include <ctype.h>
#include <sys/syslog.h>
#include <sys/klog.h>
#ifdef BB_NOMMU
vfork_daemon_rexec(0, 1, argc, argv, "-n");
#else
- bb_xdaemon(0, 1);
+ xdaemon(0, 1);
#endif
}
}
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <netdb.h>
#include <paths.h>
-#include <signal.h>
-#include <stdarg.h>
#include <stdbool.h>
-#include <time.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <sys/types.h>
#include <sys/un.h>
-#include <sys/param.h>
/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
#define SYSLOG_NAMES
static void init_RemoteLog(void)
{
memset(&remoteaddr, 0, sizeof(remoteaddr));
- remotefd = bb_xsocket(AF_INET, SOCK_DGRAM, 0);
+ remotefd = xsocket(AF_INET, SOCK_DGRAM, 0);
remoteaddr.sin_family = AF_INET;
remoteaddr.sin_addr = *(struct in_addr *) *(xgethostbyname(RemoteHost))->h_addr_list;
remoteaddr.sin_port = htons(RemotePort);
memset(&sunx, 0, sizeof(sunx));
sunx.sun_family = AF_UNIX;
strncpy(sunx.sun_path, lfile, sizeof(sunx.sun_path));
- sock_fd = bb_xsocket(AF_UNIX, SOCK_DGRAM, 0);
+ sock_fd = xsocket(AF_UNIX, SOCK_DGRAM, 0);
addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path);
if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) {
bb_perror_msg_and_die("Could not connect to socket " _PATH_LOG);
#endif
#ifdef CONFIG_FEATURE_REMOTE_LOG
case 'R':
- RemoteHost = bb_xstrdup(optarg);
+ RemoteHost = xstrdup(optarg);
if ((p = strchr(RemoteHost, ':'))) {
RemotePort = atoi(p + 1);
*p = '\0';
#ifdef BB_NOMMU
vfork_daemon_rexec(0, 1, argc, argv, "-n");
#else
- bb_xdaemon(0, 1);
+ xdaemon(0, 1);
#endif
}
doSyslogd();
* Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdint.h>
-#include <sys/ioctl.h>
#include "busybox.h"
#define DEFAULTFBDEV FB_0
char buf[256];
char *p = buf;
- f = bb_xfopen(fn, "r");
+ f = xfopen(fn, "r");
while (!feof(f)) {
fgets(buf, sizeof(buf), f);
if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
}
}
- fh = bb_xopen(fbdev, O_RDONLY);
+ fh = xopen(fbdev, O_RDONLY);
if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
bb_perror_msg_and_die("fbset(ioctl)");
if (g_options & OPT_READMODE) {
* 5 July 2003 -- modified for Busybox by Erik Andersen
*/
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include "busybox.h"
va_start(arg, format);
bb_vfprintf(stdout, format, arg);
va_end(arg);
- bb_xfflush_stdout();
+ xfflush_stdout();
}
-static void bb_xioctl(int fd, int request, void *argp, const char *string)
+static void xioctl(int fd, int request, void *argp, const char *string)
{
if (ioctl (fd, request, argp) < 0) {
bb_perror_msg_and_die(string);
/* O_RDWR for formatting and verifying */
- fd = bb_xopen(*argv,O_RDWR );
+ fd = xopen(*argv,O_RDWR );
- bb_xioctl(fd, FDGETPRM, ¶m, "FDGETPRM");/*original message was: "Could not determine current format type" */
+ xioctl(fd, FDGETPRM, ¶m, "FDGETPRM");/*original message was: "Could not determine current format type" */
print_and_flush("%s-sided, %d tracks, %d sec/track. Total capacity %d kB.\n",
(param.head == 2) ? "Double" : "Single",
/* FORMAT */
print_and_flush("Formatting ... ", NULL);
- bb_xioctl(fd, FDFMTBEG,NULL,"FDFMTBEG");
+ xioctl(fd, FDFMTBEG,NULL,"FDFMTBEG");
/* n == track */
for (n = 0; n < param.track; n++)
{
descr.head = 0;
descr.track = n;
- bb_xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK");
+ xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK");
print_and_flush("%3d\b\b\b", n);
if (param.head == 2) {
descr.head = 1;
- bb_xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK");
+ xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK");
}
}
- bb_xioctl(fd,FDFMTEND,NULL,"FDFMTEND");
+ xioctl(fd,FDFMTEND,NULL,"FDFMTEND");
print_and_flush("done\n", NULL);
/* VERIFY */
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <stdlib.h>
-#include <unistd.h>
#include "busybox.h"
/* From <linux/fd.h> */
if (argc != 2) bb_show_usage();
- fd = bb_xopen(argv[1], O_RDWR);
+ fd = xopen(argv[1], O_RDWR);
// Act like freeramdisk, fdflush, or both depending on configuration.
result = ioctl(fd, (ENABLE_FREERAMDISK && bb_applet_name[1]=='r')
*
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <getopt.h>
-
#include "busybox.h"
+#include <getopt.h>
/* NON_OPT is the code that is returned when a non-option is found in '+'
mode */
free(BUFFER);
if (!quote) { /* Just copy arg */
- BUFFER=bb_xstrdup(arg);
+ BUFFER=xstrdup(arg);
return BUFFER;
}
long_options[long_options_nr-1].has_arg=has_arg;
long_options[long_options_nr-1].flag=NULL;
long_options[long_options_nr-1].val=LONG_OPT;
- long_options[long_options_nr-1].name=bb_xstrdup(name);
+ long_options[long_options_nr-1].name=xstrdup(name);
}
long_options_nr++;
}
#include "busybox.h"
#include <getopt.h>
-#include <string.h>
#include "dump.h"
static void bb_dump_addfile(char *name)
FILE *fp;
char *buf;
- fp = bb_xfopen(name, "r");
+ fp = xfopen(name, "r");
while ((buf = bb_get_chomped_line_from_file(fp)) != NULL) {
p = skip_whitespace(buf);
*/
#include "busybox.h"
-#include <ctype.h>
-#include <errno.h>
-#include <sys/mman.h>
-#include <sys/sysmacros.h>
#include "xregex.h"
#define DEV_PATH "/dev"
break;
}
if ((s2-s+1) & (1<<delete))
- command = bb_xstrndup(pos, end-pos);
+ command = xstrndup(pos, end-pos);
}
pos = end2;
int rc;
char *s;
- s=bb_xasprintf("MDEV=%s",device_name);
+ s=xasprintf("MDEV=%s",device_name);
putenv(s);
rc = system(command);
s[4]=0;
char *env_path;
RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
- bb_xchdir(DEV_PATH);
+ xchdir(DEV_PATH);
/* Scan */
* removed getopt based parser and added a hand rolled one.
*/
-#include <stdio.h>
-#include <time.h>
-#include <unistd.h>
-#include <string.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-#include <sys/param.h>
-#include <mntent.h>
#include "busybox.h"
+#include <mntent.h>
#define MINIX_ROOT_INO 1
#define MINIX_LINK_MAX 250
int fd;
long size;
- fd = bb_xopen3(file, O_RDWR, 0);
+ fd = xopen3(file, O_RDWR, 0);
if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
close(fd);
return (size * 512);
FILE *listfile;
unsigned long blockno;
- listfile = bb_xfopen(filename, "r");
+ listfile = xfopen(filename, "r");
while (!feof(listfile)) {
fscanf(listfile, "%ld\n", &blockno);
mark_zone(blockno);
tmp += dirsize;
*(short *) tmp = 2;
strcpy(tmp + 2, ".badblocks");
- DEV = bb_xopen3(device_name, O_RDWR, 0);
+ DEV = xopen3(device_name, O_RDWR, 0);
if (fstat(DEV, &statbuf) < 0)
bb_error_msg_and_die("unable to stat %s", device_name);
if (!S_ISBLK(statbuf.st_mode))
// Figure out how big the device is and announce our intentions.
- fd = bb_xopen(argv[1],O_RDWR);
+ fd = xopen(argv[1],O_RDWR);
len = fdlength(fd);
pagesize = getpagesize();
printf("Setting up swapspace version 1, size = %ld bytes\n", (long)(len-pagesize));
*
* Termios corrects by Vladimir Oleynik <dzo@simtreas.ru>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
+ * Licensed under GPLv2 or later, see file License in this tarball for details.
*/
-#include <stdio.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
#include "busybox.h"
if(isatty(STDOUT_FILENO)) {
cin = fopen(CURRENT_TTY, "r");
if (!cin)
- cin = bb_xfopen(CONSOLE_DEV, "r");
+ cin = xfopen(CONSOLE_DEV, "r");
please_display_more_prompt = 2;
#ifdef CONFIG_FEATURE_USE_TERMIOS
cin_fileno = fileno(cin);
*/
#include "busybox.h"
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
#include <mntent.h>
-#include <ctype.h>
-#include <fcntl.h> // for CONFIG_FEATURE_MOUNT_LOOP
-#include <sys/ioctl.h> // for CONFIG_FEATURE_MOUNT_LOOP
// These two aren't always defined in old headers
#ifndef MS_BIND
static void append_mount_options(char **oldopts, char *newopts)
{
if(*oldopts && **oldopts) {
- char *temp=bb_xasprintf("%s,%s",*oldopts,newopts);
+ char *temp=xasprintf("%s,%s",*oldopts,newopts);
free(*oldopts);
*oldopts=temp;
} else {
if (ENABLE_FEATURE_CLEAN_UP) free(*oldopts);
- *oldopts = bb_xstrdup(newopts);
+ *oldopts = xstrdup(newopts);
}
}
if(*fs=='#' || *fs=='*') continue;
if(!*fs) continue;
- llist_add_to_end(&list,bb_xstrdup(fs));
+ llist_add_to_end(&list,xstrdup(fs));
}
if (ENABLE_FEATURE_CLEAN_UP) fclose(f);
}
int mount_main(int argc, char **argv)
{
- char *cmdopts = bb_xstrdup(""), *fstabname, *fstype=0, *storage_path=0;
+ char *cmdopts = xstrdup(""), *fstabname, *fstype=0, *storage_path=0;
FILE *fstab;
int i, opt, all = FALSE, rc = 0;
struct mntent mtpair[2], *mtcur = mtpair;
// Mount the last thing we found.
mtcur = mtnext;
- mtcur->mnt_opts=bb_xstrdup(mtcur->mnt_opts);
+ mtcur->mnt_opts = xstrdup(mtcur->mnt_opts);
append_mount_options(&(mtcur->mnt_opts),cmdopts);
rc = singlemount(mtcur, 0);
free(mtcur->mnt_opts);
*/
#include "busybox.h"
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
#include <sys/utsname.h>
#undef TRUE
#undef FALSE
}
sprintf(new_opts, "%s%saddr=%s",
old_opts, *old_opts ? "," : "", s);
- *mount_opts = bb_xstrdup(new_opts);
+ *mount_opts = xstrdup(new_opts);
/* Set default options.
* rsize/wsize (and bsize, for ver >= 3) are left 0 in order to
else if (!strcmp(opt, "mountport"))
mountport = val;
else if (!strcmp(opt, "mounthost"))
- mounthost=bb_xstrndup(opteq+1,
+ mounthost=xstrndup(opteq+1,
strcspn(opteq+1," \t\n\r,"));
else if (!strcmp(opt, "mountprog"))
mountprog = val;
if (!bg)
goto fail;
if (!running_bg) {
- prev_bg_host = bb_xstrdup(hostname);
+ prev_bg_host = xstrdup(hostname);
if (retry > 0)
retval = EX_BG;
goto fail;
*
* Copyright (C) 1994,1996 Alessandro Rubini (rubini@ipvvis.unipv.it)
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/*
* Paul Mundt <lethal@linux-sh.org>.
*/
-#include <errno.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/utsname.h>
-
#include "busybox.h"
+#include <sys/utsname.h>
#define S_LEN 128
to_write = 1; /* sth different from sizeof(int) */
}
- fd = bb_xopen(defaultpro,O_WRONLY);
+ fd = xopen(defaultpro,O_WRONLY);
if (write(fd, &multiplier, to_write) != to_write)
bb_perror_msg_and_die("error writing %s", defaultpro);
* Use an fd for the profiling buffer, to skip stdio overhead
*/
- proFd = bb_xopen(proFile,O_RDONLY);
+ proFd = xopen(proFile,O_RDONLY);
if (((int)(len=lseek(proFd,0,SEEK_END)) < 0)
|| (lseek(proFd,0,SEEK_SET) < 0))
total = 0;
- map = bb_xfopen(mapFile, "r");
+ map = xfopen(mapFile, "r");
while (fgets(mapline,S_LEN,map)) {
if (sscanf(mapline,"%llx %s %s",&fn_add,mode,fn_name) != 3)
} else while (getmntent_r(fp,&me,path,sizeof(path))) {
m = xmalloc(sizeof(struct mtab_list));
m->next = mtl;
- m->device = bb_xstrdup(me.mnt_fsname);
- m->dir = bb_xstrdup(me.mnt_dir);
+ m->device = xstrdup(me.mnt_fsname);
+ m->dir = xstrdup(me.mnt_dir);
mtl = m;
}
endmntent(fp);