Remove bb_ prefixes from xfuncs.c (and a few other places), consolidate

things like xasprintf() into xfuncs.c, remove xprint_file_by_name() (it only
had one user), clean up lots of #includes...  General cleanup pass.  What I've
been doing for the last couple days.

And it conflicts!  I've removed httpd.c from this checkin due to somebody else
touching that file.  It builds for me.  I have to catch a bus.  (Now you know
why I'm looking forward to Mercurial.)
This commit is contained in:
Rob Landley 2006-08-03 15:41:12 +00:00
parent 6dce0b6fa7
commit d921b2ecc0
143 changed files with 711 additions and 1721 deletions

View File

@ -14,16 +14,8 @@
* 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)
{
@ -81,7 +73,7 @@ int ar_main(int argc, char **argv)
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;

View File

@ -6,12 +6,6 @@
* 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"
@ -30,7 +24,7 @@ int bunzip2_main(int argc, char **argv)
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;
@ -53,7 +47,7 @@ int bunzip2_main(int argc, char **argv)
}
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) {

View File

@ -1,44 +1,39 @@
/* 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
*/
@ -163,7 +158,7 @@ static int search_name_hashtable(const char *key)
}
}
}
name_hashtable[probe_address] = bb_xstrdup(key);
name_hashtable[probe_address] = xstrdup(key);
return(probe_address);
}
@ -204,10 +199,10 @@ static int version_compare_part(const char *version1, const char *version2)
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);
@ -215,10 +210,10 @@ static int version_compare_part(const char *version1, const char *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);
@ -230,10 +225,10 @@ static int version_compare_part(const char *version1, const char *version2)
/* 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);
@ -292,8 +287,8 @@ static int version_compare(const unsigned int ver1, const unsigned int ver2)
}
/* 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, '-');
@ -429,7 +424,7 @@ static void add_edge_to_node(common_node_t *node, edge_t *edge)
*/
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;
@ -444,7 +439,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
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)) {
@ -538,6 +533,93 @@ static void free_package(common_node_t *node)
}
}
/*
* 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",
@ -631,7 +713,7 @@ static unsigned int get_status(const unsigned int status_node, const int num)
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);
@ -666,7 +748,7 @@ static void set_status(const unsigned int status_node_num, const char *new_value
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;
@ -705,7 +787,7 @@ static void index_status_file(const char *filename)
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) {
@ -715,7 +797,7 @@ static void index_status_file(const char *filename)
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);
}
@ -749,8 +831,8 @@ static void write_buffer_no_status(FILE *new_status_file, const char *control_bu
/* 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;
@ -768,14 +850,14 @@ static void write_status_file(deb_file_t **deb_file)
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;
}
@ -1181,7 +1263,7 @@ static int run_package_script(const char *package_name, const char *script_type)
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);
@ -1200,7 +1282,7 @@ static char **all_control_list(const char *package_name)
/* 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++;
}
@ -1296,8 +1378,8 @@ static void remove_package(const unsigned int package_num, int noisy)
/* 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);
@ -1361,7 +1443,7 @@ static archive_handle_t *init_archive_deb_ar(const char *filename)
/* 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);
}
@ -1428,7 +1510,7 @@ static void data_extract_all_prefix(archive_handle_t *archive_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;
@ -1457,12 +1539,12 @@ static void unpack_package(deb_file_t *deb_file)
}
/* 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++;
}
@ -1489,7 +1571,7 @@ static void unpack_package(deb_file_t *deb_file)
/* 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);
@ -1600,7 +1682,7 @@ int dpkg_main(int argc, char **argv)
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) {

View File

@ -4,13 +4,8 @@
*
* 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
@ -81,7 +76,7 @@ int dpkg_deb_main(int argc, char **argv)
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 */
@ -90,7 +85,7 @@ int dpkg_deb_main(int argc, char **argv)
}
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);

View File

@ -27,13 +27,6 @@
* 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"
@ -67,7 +60,7 @@ int gunzip_main(int argc, char **argv)
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);
@ -81,13 +74,13 @@ int gunzip_main(int argc, char **argv)
/* 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
@ -105,7 +98,7 @@ int gunzip_main(int argc, char **argv)
}
/* 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;

View File

@ -3,16 +3,6 @@
* 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"
@ -23,7 +13,7 @@ void data_extract_all(archive_handle_t *archive_handle)
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);
}
@ -68,7 +58,7 @@ void data_extract_all(archive_handle_t *archive_handle)
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;

View File

@ -28,15 +28,7 @@
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 */
@ -655,7 +647,7 @@ static int start_bunzip(bunzip_data **bdp, int in_fd, unsigned char *inbuf,
/* 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 */

View File

@ -34,8 +34,6 @@
*/
#include "libbb.h"
#include <sys/wait.h>
#include <signal.h>
#include "unarchive.h"
typedef struct huft_s {
@ -853,7 +851,7 @@ int inflate_unzip(int in, int out)
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 */

View File

@ -4,12 +4,8 @@
* 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)
{
@ -31,7 +27,7 @@ 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);
@ -85,14 +81,14 @@ char get_header_ar(archive_handle_t *archive_handle)
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';

View File

@ -4,13 +4,8 @@
* 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;
@ -123,7 +118,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
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;

View File

@ -11,12 +11,8 @@
* 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;
@ -106,7 +102,7 @@ char get_header_tar(archive_handle_t *archive_handle)
} 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;
@ -120,7 +116,7 @@ char get_header_tar(archive_handle_t *archive_handle)
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));

View File

@ -7,16 +7,6 @@
* 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"
@ -127,7 +117,7 @@ int rpm_main(int argc, char **argv)
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); }
@ -198,7 +188,7 @@ void extract_cpio_gz(int fd) {
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;
@ -302,7 +292,7 @@ void fileaction_dobackup(char *filename, int fileref)
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);
@ -328,7 +318,7 @@ void loop_through_files(int filetag, void (*fileaction)(char *filename, int file
{
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++);

View File

@ -6,11 +6,6 @@
*
* 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"
@ -63,7 +58,7 @@ int rpm2cpio_main(int argc, char **argv)
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));

View File

@ -5,13 +5,6 @@
* 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"
@ -36,7 +29,7 @@ int uncompress_main(int argc, char **argv)
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. */
@ -52,7 +45,7 @@ int uncompress_main(int argc, char **argv)
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)) {
@ -62,7 +55,7 @@ int uncompress_main(int argc, char **argv)
/* 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 */

View File

@ -8,12 +8,6 @@
* 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"
@ -31,7 +25,7 @@ int unlzma_main(int argc, char **argv)
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;
@ -50,7 +44,7 @@ int unlzma_main(int argc, char **argv)
}
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);

View File

@ -24,13 +24,8 @@
* - 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)
@ -68,7 +63,7 @@ static void unzip_skip(int fd, off_t skip)
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 */
}
@ -143,7 +138,7 @@ int unzip_main(int argc, char **argv)
break;
case 1 : /* The zip file */
src_fn = bb_xstrndup(optarg, strlen(optarg)+4);
src_fn = xstrndup(optarg, strlen(optarg)+4);
opt_range++;
break;
@ -212,7 +207,7 @@ int unzip_main(int argc, char **argv)
/* Change dir if necessary */
if (base_dir)
bb_xchdir(base_dir);
xchdir(base_dir);
if (verbosity != v_silent)
printf("Archive: %s\n", src_fn);
@ -338,7 +333,7 @@ int unzip_main(int argc, char **argv)
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);
@ -366,7 +361,7 @@ int unzip_main(int argc, char **argv)
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;

View File

@ -8,13 +8,6 @@
*
*/
#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> */
@ -38,7 +31,7 @@ int dumpkmap_main(int argc, char **argv)
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);

View File

@ -7,18 +7,8 @@
* 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,
@ -47,7 +37,7 @@ int loadfont_main(int argc, char **argv)
if (argc != 1)
bb_show_usage();
fd = bb_xopen(CURRENT_VC, O_RDWR);
fd = xopen(CURRENT_VC, O_RDWR);
loadnewfont(fd);
return EXIT_SUCCESS;

View File

@ -8,13 +8,6 @@
*
*/
#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"
@ -43,7 +36,7 @@ int loadkmap_main(int argc, char **argv)
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))

View File

@ -40,7 +40,7 @@ int openvt_main(int argc, char **argv)
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);

View File

@ -7,13 +7,6 @@
* 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
@ -47,7 +40,7 @@ int setconsole_main(int argc, char **argv)
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;

View File

@ -9,10 +9,6 @@
* 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)
@ -28,7 +24,7 @@ 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;

View File

@ -17,20 +17,8 @@
* 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 */
@ -135,7 +123,7 @@ int cal_main(int argc, char **argv)
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;

View File

@ -11,8 +11,6 @@
* 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)
{
@ -28,7 +26,7 @@ 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;

View File

@ -9,10 +9,6 @@
/* 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)
@ -25,7 +21,7 @@ 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) {

View File

@ -6,14 +6,11 @@
*
* 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;

View File

@ -21,9 +21,6 @@
* in the '-l' case.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "busybox.h"
static FILE *cmp_xfopen_input(const char *filename)
@ -105,12 +102,12 @@ int cmp_main(int argc, char **argv)
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) {
@ -129,8 +126,8 @@ int cmp_main(int argc, char **argv)
}
} while (c1 != EOF);
bb_xferror(fp1, filename1);
bb_xferror(fp2, filename2);
xferror(fp1, filename1);
xferror(fp2, filename2);
bb_fflush_stdout_and_exit(exit_val);
}

View File

@ -7,10 +7,6 @@
* 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
@ -57,7 +53,7 @@ static void cmp_files(char **infiles)
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]);
}

View File

@ -8,14 +8,6 @@
* 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[] = {
@ -110,7 +102,7 @@ int dd_main(int argc, char **argv)
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;
@ -123,7 +115,7 @@ int dd_main(int argc, char **argv)
oflag |= O_TRUNC;
}
ofd = bb_xopen3(outfile, oflag, 0666);
ofd = xopen3(outfile, oflag, 0666);
if (seek && trunc_flag) {
if (ftruncate(ofd, seek * obs) < 0) {

View File

@ -12,23 +12,6 @@
* 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
@ -917,21 +900,21 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
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)
@ -1004,19 +987,19 @@ static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
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)
@ -1051,7 +1034,7 @@ static int add_to_dirlist(const char *filename,
{
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;
@ -1077,7 +1060,7 @@ static char **get_dir(char *path)
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;
@ -1089,7 +1072,7 @@ static char **get_dir(char *path)
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;
@ -1104,7 +1087,7 @@ static char **get_dir(char *path)
/* 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;
}

View File

@ -12,10 +12,6 @@
* 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 {
@ -30,7 +26,7 @@ static int convert(char *fn)
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

View File

@ -25,14 +25,8 @@
/* 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 {
@ -116,9 +110,9 @@ static VALUE *str_value (char *s)
{
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;
}
@ -148,7 +142,7 @@ static int null (VALUE *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;
}
}
@ -366,7 +360,7 @@ static VALUE *eval6 (void)
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);

View File

@ -10,13 +10,6 @@
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;
@ -61,7 +54,7 @@ int fold_main(int argc, char **argv)
if (*a == '-' && !a[1])
break;
if (isdigit(*a)) {
argv[i] = bb_xasprintf("-w%s", a);
argv[i] = xasprintf("-w%s", a);
}
}
}

View File

@ -11,11 +11,6 @@
/* 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[] =
@ -137,7 +132,7 @@ int head_main(int argc, char **argv)
bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */
retval = EXIT_FAILURE;
}
bb_xferror_stdout();
xferror_stdout();
}
fmt = header_fmt_str;
} while (*++argv);

View File

@ -11,10 +11,6 @@
/* 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
@ -45,7 +41,7 @@ int ln_main(int argc, char **argv)
if (argc == optind + 1) {
*--argv = last;
last = bb_get_last_path_component(bb_xstrdup(last));
last = bb_get_last_path_component(xstrdup(last));
}
do {
@ -55,7 +51,7 @@ int ln_main(int argc, char **argv)
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;
@ -69,7 +65,7 @@ int ln_main(int argc, char **argv)
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;

View File

@ -37,15 +37,7 @@ enum {
/************************************************************************/
#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 */
@ -535,7 +527,7 @@ static struct dnode **list_dir(const char *path)
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 */

View File

@ -6,14 +6,6 @@
* 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;
@ -129,7 +121,7 @@ static int hash_files(int argc, char **argv, hash_algo_t hash_algo)
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) {

View File

@ -9,9 +9,6 @@
* 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[])
@ -25,7 +22,7 @@ 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);
@ -38,7 +35,7 @@ int nohup_main(int argc, char *argv[])
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);

View File

@ -12,13 +12,6 @@
* 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;
@ -104,7 +97,7 @@ static char *get_key(char *str, struct sort_key *key, int 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++)
@ -222,7 +215,6 @@ static int compare_keys(const void *xarg, const void *yarg)
/* 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;
}
@ -242,7 +234,7 @@ int sort_main(int argc, char **argv)
#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])
@ -289,7 +281,7 @@ int sort_main(int argc, char **argv)
/* 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;

View File

@ -12,18 +12,6 @@
* 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 */
@ -321,7 +309,7 @@ static void print_it(char const *masterformat, char const *filename,
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. */

View File

@ -21,31 +21,7 @@
*/
//#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)
@ -469,11 +445,7 @@ static const struct suffix_mult stty_suffixes[] = {
{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 *);
@ -541,7 +513,7 @@ int main(int argc, char **argv)
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");
@ -1299,9 +1271,3 @@ static const char *visible(unsigned int ch)
*bpout = '\0';
return (const char *) buf;
}
#ifdef TEST
const char *bb_applet_name = "stty";
#endif

View File

@ -10,10 +10,6 @@
/* 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)
@ -96,7 +92,7 @@ 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);

View File

@ -11,9 +11,6 @@
/* 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";
@ -23,7 +20,7 @@ static FILE *xgetoptfile_uniq_s(char **argv, int read0write2)
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;
@ -100,7 +97,7 @@ int uniq_main(int argc, char **argv)
}
} while (s1);
bb_xferror(in, input_filename);
xferror(in, input_filename);
bb_fflush_stdout_and_exit(EXIT_SUCCESS);
}

View File

@ -12,11 +12,6 @@
*/
#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)
@ -141,7 +136,7 @@ int uudecode_main(int argc, char **argv)
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();
}
@ -174,7 +169,7 @@ int uudecode_main(int argc, char **argv)
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);

View File

@ -7,12 +7,7 @@
*
* 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 */
@ -92,7 +87,7 @@ int uuencode_main(int argc, char **argv)
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) {
@ -128,7 +123,7 @@ int uuencode_main(int argc, char **argv)
}
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);
}

View File

@ -16,14 +16,6 @@
* 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)
@ -62,7 +54,7 @@ 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);
}
}

View File

@ -3,31 +3,22 @@
* 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;
@ -136,7 +127,7 @@ static void do_procinit(void)
return;
}
procdir = bb_xopendir("/proc");
procdir = xopendir("/proc");
foundany = 0;
while ((entry = readdir(procdir)) != NULL) {
@ -292,12 +283,12 @@ int start_stop_daemon_main(int argc, char **argv)
}
*--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);

View File

@ -155,7 +155,7 @@ int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array)
unsigned int mask;
int compat_type;
buf = bb_xstrdup(str);
buf = xstrdup(str);
cp = buf;
while (cp && *cp) {
neg = 0;

View File

@ -100,7 +100,7 @@ int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok)
int neg;
unsigned int mask;
buf = bb_xstrdup(str);
buf = xstrdup(str);
cp = buf;
while (cp && *cp) {
neg = 0;

View File

@ -33,7 +33,7 @@ char *e2p_os2string(int os_type)
else
os = "(unknown os)";
ret = bb_xstrdup(os);
ret = xstrdup(os);
return ret;
}

View File

@ -129,7 +129,7 @@ static char *base_device(const char *device)
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)
@ -544,7 +544,7 @@ static char *find_fsck(char *type)
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);
}
@ -583,7 +583,7 @@ static int execute(const char *type, const char *device, const char *mntpt,
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;

View File

@ -226,7 +226,7 @@ static void read_bb_file(ext2_filsys fs, badblocks_list *bb_list,
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");
@ -692,7 +692,7 @@ static void parse_extended_opts(struct ext2_super_block *sb_param,
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;

View File

@ -111,7 +111,7 @@ void parse_journal_opts(char **journal_device, int *journal_flags,
{
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;
@ -264,7 +264,7 @@ char *e2fs_set_sbin_path(void)
/* 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);

View File

@ -7,19 +7,9 @@
* 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
@ -610,7 +600,7 @@ static inline int isalnum_(int c)
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) -------- */
@ -672,7 +662,7 @@ static var *setvar_p(var *v, char *value)
/* 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 */
@ -709,7 +699,7 @@ static char *getvar_s(var *v)
/* 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;
@ -744,7 +734,7 @@ static var *copyvar(var *dest, const var *src)
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;
@ -1144,7 +1134,7 @@ static node *chain_node(uint32_t info)
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;
@ -1433,7 +1423,7 @@ static int awk_split(char *s, node *spl, char **slist)
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';
@ -1747,7 +1737,7 @@ static char *awk_printf(node *n)
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) {
@ -1941,7 +1931,7 @@ static var *exec_builtin(node *op, var *res)
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++;
@ -2118,7 +2108,7 @@ static var *evaluate(node *op, var *res)
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;
@ -2272,7 +2262,7 @@ re_cont:
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 {
@ -2564,7 +2554,7 @@ static int is_assignment(const char *expr)
{
char *exprc, *s, *s0, *s1;
exprc = bb_xstrdup(expr);
exprc = xstrdup(expr);
if (!isalnum_(*exprc) || (s = strchr(exprc, '=')) == NULL) {
free(exprc);
return FALSE;
@ -2659,7 +2649,7 @@ int awk_main(int argc, char **argv)
}
for (envp=environ; *envp; envp++) {
s = bb_xstrdup(*envp);
s = xstrdup(*envp);
s1 = strchr(s, '=');
if (!s1) {
goto keep_going;

View File

@ -67,7 +67,7 @@ static char *extract_filename(char *line, int patch_level)
filename_start_ptr = temp + 1;
}
return(bb_xstrdup(filename_start_ptr));
return(xstrdup(filename_start_ptr));
}
static int file_doesnt_exist(const char *filename)
@ -89,7 +89,7 @@ int patch_main(int argc, char **argv)
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;
}
@ -140,7 +140,7 @@ int patch_main(int argc, char **argv)
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);
@ -150,16 +150,16 @@ int patch_main(int argc, char **argv)
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");
}
}

View File

@ -132,7 +132,7 @@ void sed_free_and_close_stuff(void)
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);
@ -300,7 +300,7 @@ static int parse_file_cmd(sed_cmd_t *sed_cmd, char *filecmdstr, char **retval)
/* 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;
@ -406,7 +406,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
} 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 */
@ -415,7 +415,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
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;
@ -423,7 +423,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
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;
}
}
@ -466,7 +466,7 @@ static void add_cmd(char *cmdstr)
/* 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;
}
@ -474,7 +474,7 @@ static void add_cmd(char *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;
}
@ -671,7 +671,7 @@ static sed_cmd_t *branch_to(char *label)
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)
@ -852,7 +852,7 @@ restart:
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;
@ -907,7 +907,7 @@ 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;
@ -996,7 +996,7 @@ restart:
}
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 */
{
@ -1019,7 +1019,7 @@ restart:
}
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 */
{
@ -1072,7 +1072,7 @@ discard_line:
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");
@ -1121,14 +1121,14 @@ int sed_main(int argc, char **argv)
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;
}
@ -1172,7 +1172,7 @@ int sed_main(int argc, char **argv)
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");

View File

@ -23,18 +23,6 @@
#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))
@ -349,7 +337,7 @@ int vi_main(int argc, char **argv)
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);
}
}
@ -522,7 +510,7 @@ static Byte *get_one_address(Byte * p, int *addr) // get colon addr, if present
*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);
@ -736,7 +724,7 @@ static void colon(Byte * buf)
// 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
@ -788,7 +776,7 @@ static void colon(Byte * buf)
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
@ -996,7 +984,7 @@ static void colon(Byte * buf)
}
#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
@ -2313,7 +2301,7 @@ static Byte *get_input_line(Byte * prompt) // get input line- use "status line"
}
refresh(FALSE);
free(obufp);
obufp = (Byte *) bb_xstrdup((char *) buf);
obufp = (Byte *) xstrdup((char *) buf);
return (obufp);
}
@ -3199,7 +3187,7 @@ key_cmd_mode:
// 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 */
@ -3214,7 +3202,7 @@ key_cmd_mode:
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

View File

@ -11,14 +11,7 @@
*/
#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
@ -138,8 +131,8 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
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;
}
@ -300,7 +293,7 @@ int find_main(int argc, char **argv)
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)
@ -311,10 +304,10 @@ int find_main(int argc, char **argv)
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

View File

@ -17,11 +17,6 @@
*/
#include "busybox.h"
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <errno.h>
#include "xregex.h"
@ -203,7 +198,7 @@ static int grep_file(FILE *file)
/* 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;
}
}
@ -271,7 +266,7 @@ static void load_regexes_from_file(llist_t *fopt)
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));

View File

@ -18,15 +18,6 @@
*/
#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. */
@ -300,7 +291,7 @@ static int xargs_ask_confirmation(void)
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);
}

View File

@ -19,7 +19,9 @@
#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>
@ -27,18 +29,26 @@
#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"
@ -127,8 +137,8 @@ extern int bb_test(int argc, char** argv);
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);
@ -161,26 +171,24 @@ extern char *bb_get_chomped_line_from_file(FILE *file);
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);
@ -204,9 +212,9 @@ extern int bb_printf(const char * __restrict format, ...)
__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);
@ -224,8 +232,8 @@ extern void *xrealloc(void *old, size_t size);
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);
@ -321,7 +329,6 @@ char *concat_path_file(const char *path, const char *filename);
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);
@ -458,7 +465,8 @@ int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
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);
@ -476,8 +484,8 @@ extern int correct_password ( const struct passwd *pw );
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);
@ -550,7 +558,7 @@ void md5_begin(md5_ctx_t *ctx);
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. */

View File

@ -11,7 +11,7 @@ srcdir=$(top_srcdir)/libbb
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 \
@ -22,15 +22,14 @@ LIBBB-y:= \
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 \
@ -97,18 +96,12 @@ LIBBB_MOBJ6:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ6))
$(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))

View File

@ -1,37 +0,0 @@
/* 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;
}

View File

@ -1,18 +0,0 @@
/* 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");
}

View File

@ -1,17 +0,0 @@
/* 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);
}

View File

@ -1,19 +0,0 @@
/* 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

View File

@ -1,17 +0,0 @@
/* 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");
}

View File

@ -1,19 +0,0 @@
/* 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;
}

View File

@ -12,7 +12,6 @@
* not addition '/' if path name already have '/'
*/
#include <string.h>
#include "libbb.h"
char *concat_path_file(const char *path, const char *filename)
@ -24,5 +23,5 @@ 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);
}

View File

@ -9,8 +9,6 @@
*/
#include "libbb.h"
#include <utime.h>
#include <errno.h>
int copy_file(const char *source, const char *dest, int flags)
{
@ -77,7 +75,7 @@ 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;
}

View File

@ -14,11 +14,10 @@
* 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;

View File

@ -12,9 +12,6 @@
*/
#include "libbb.h"
#include <string.h>
#include <unistd.h>
#include <ctype.h> /* for isdigit() */
#include "dump.h"
enum _vflag bb_dump_vflag = FIRST;
@ -232,7 +229,7 @@ static void rewrite(FS * fs)
*/
savech = *p2;
p1[1] = '\0';
pr->fmt = bb_xstrdup(fmtp);
pr->fmt = xstrdup(fmtp);
*p2 = savech;
pr->cchar = pr->fmt + (p1 - fmtp);

View File

@ -7,11 +7,6 @@
* 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)
@ -28,7 +23,7 @@ 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;
}
}

View File

@ -7,11 +7,8 @@
* 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
@ -438,7 +435,7 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
#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;
}

View File

@ -11,16 +11,6 @@
#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";
@ -174,7 +164,7 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
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);

View File

@ -8,13 +8,6 @@
* 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. */
@ -59,7 +52,7 @@ char *query_loop(const char *device)
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);

View File

@ -39,11 +39,6 @@
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__));
@ -66,7 +61,7 @@ static int string_checker(const char *p1, const char *p2)
/* 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);

View File

@ -1,37 +0,0 @@
/* 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

View File

@ -1,55 +0,0 @@
/* 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;
}

View File

@ -51,7 +51,7 @@ procps_status_t * procps_scan(int save_user_arg0)
struct stat sb;
if (!dir) {
dir = bb_xopendir("/proc");
dir = xopendir("/proc");
}
for (;;) {
if ((entry = readdir(dir)) == NULL) {

View File

@ -1,101 +0,0 @@
/* 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);
}

View File

@ -7,11 +7,6 @@
* 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
@ -82,7 +77,7 @@ int recursive_action(const char *fileName,
} else if (status == SKIP)
return TRUE;
}
dir = bb_opendir(fileName);
dir = opendir(fileName);
if (!dir) {
return FALSE;
}

View File

@ -59,7 +59,7 @@ int remove_file(const char *path, int flags)
return 0;
}
if ((dp = bb_opendir(path)) == NULL) {
if ((dp = opendir(path)) == NULL) {
return -1;
}

View File

@ -82,10 +82,10 @@ void run_shell ( const char *shell, int loginshell, const char *command, const c
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";

View File

@ -7,7 +7,6 @@
* 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)
@ -15,7 +14,7 @@ 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);

View File

@ -6,16 +6,6 @@
*
*/
#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.
@ -61,7 +51,7 @@ void bb_lookup_host(struct sockaddr_in *s_in, const char *host)
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);

View File

@ -3,18 +3,12 @@
* 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
@ -59,7 +53,7 @@ void *xcalloc(size_t nmemb, size_t size)
#endif /* DMALLOC */
#ifdef L_xstrdup
char * bb_xstrdup (const char *s)
char * xstrdup (const char *s)
{
char *t;
@ -76,12 +70,12 @@ char * bb_xstrdup (const char *s)
#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);
@ -90,7 +84,7 @@ char * bb_xstrndup (const char *s, int 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)
@ -100,14 +94,14 @@ FILE *bb_xfopen(const char *path, const char *mode)
#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;
@ -175,7 +169,7 @@ unsigned char xread_char(int fd)
#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);
@ -184,14 +178,14 @@ void bb_xferror(FILE *fp, const char *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);
@ -201,7 +195,7 @@ void bb_xfflush_stdout(void)
#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;
@ -226,9 +220,9 @@ pid_t bb_spawn(char **argv)
#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;
}
@ -347,3 +341,107 @@ off_t fdlength(int fd)
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

View File

@ -9,11 +9,6 @@
*
*/
#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
@ -26,7 +21,7 @@ static int group_study(struct group *g)
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;
@ -67,13 +62,13 @@ static int addgroup(char *group, gid_t gid, const char *user)
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

View File

@ -8,14 +8,6 @@
* 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)
@ -32,7 +24,7 @@ static int passwd_study(const char *filename, struct passwd *p)
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))
@ -78,7 +70,7 @@ static void addgroup_wrapper(struct passwd *p)
{
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);
}
@ -99,7 +91,7 @@ static int adduser(struct passwd *p, unsigned long flags)
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)) {
@ -119,7 +111,7 @@ static int adduser(struct passwd *p, unsigned long flags)
#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 */

View File

@ -16,19 +16,6 @@
*
*/
#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
@ -324,7 +311,7 @@ static void parse_args(int argc, char **argv, struct options *op)
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) {
@ -858,7 +845,7 @@ int getty_main(int argc, char **argv)
};
#ifdef DEBUGGING
dbf = bb_xfopen(DEBUGTERM, "w");
dbf = xfopen(DEBUGTERM, "w");
{
int i;

View File

@ -3,20 +3,8 @@
* 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];
@ -170,7 +158,7 @@ int passwd_main(int argc, char **argv)
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];

View File

@ -6,11 +6,7 @@
*/
#include "busybox.h"
#include <signal.h>
#include <syslog.h>
#include <sys/resource.h>
#include <time.h>
int su_main ( int argc, char **argv )
{
@ -43,7 +39,7 @@ 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);
}

View File

@ -16,18 +16,8 @@
/* 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;
@ -71,7 +61,7 @@ int vlock_main(int argc, char **argv)
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");

View File

@ -13,22 +13,7 @@
#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]))
@ -193,7 +178,7 @@ int crond_main(int ac, char **av)
* change directory
*/
bb_xchdir(CDir);
xchdir(CDir);
signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
* version - his died. ;(
*/
@ -208,7 +193,7 @@ int crond_main(int ac, char **av)
/* reexec for vfork() do continue parent */
vfork_daemon_rexec(1, 0, ac, av, "-f");
#else
bb_xdaemon(1, 0);
xdaemon(1, 0);
#endif
}

View File

@ -11,22 +11,6 @@
*/
#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"
@ -47,8 +31,7 @@ static void EditFile(const char *user, const char *file);
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;
@ -147,7 +130,7 @@ crontab_main(int ac, char **av)
* Change directory to our crontab directory
*/
bb_xchdir(CDir);
xchdir(CDir);
/*
* Handle options as appropriate
@ -177,7 +160,7 @@ crontab_main(int ac, char **av)
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)
@ -244,8 +227,7 @@ crontab_main(int ac, char **av)
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;
@ -284,7 +266,7 @@ GetReplaceStream(const char *user, const char *file)
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) {
@ -293,8 +275,7 @@ GetReplaceStream(const char *user, const char *file)
exit(0);
}
static void
EditFile(const char *user, const char *file)
static void EditFile(const char *user, const char *file)
{
int pid;
@ -324,8 +305,7 @@ EditFile(const char *user, const char *file)
wait4(pid, NULL, 0, NULL);
}
static int
ChangeUser(const char *user, short dochdir)
static int ChangeUser(const char *user, short dochdir)
{
struct passwd *pas;
@ -349,7 +329,7 @@ ChangeUser(const char *user, short dochdir)
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);

View File

@ -475,7 +475,7 @@ int devfsd_main (int argc, char **argv)
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");
@ -704,7 +704,7 @@ static void process_config_line (const char *line, unsigned long *event_mask)
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;
@ -714,8 +714,8 @@ static void process_config_line (const char *line, unsigned long *event_mask)
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 */

View File

@ -13,22 +13,8 @@
*/
#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
@ -1619,7 +1605,7 @@ static void process_dev(char *devname)
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)

View File

@ -8,15 +8,7 @@
*/
#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
@ -43,7 +35,7 @@ int last_main(int argc, char **argv)
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) {

View File

@ -31,12 +31,6 @@
*/
#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"
@ -196,7 +190,7 @@ static void add_linenumbers(void)
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);
}
}
@ -206,15 +200,15 @@ static void data_readlines(void)
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;
@ -226,7 +220,7 @@ static void data_readlines(void)
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();
@ -357,12 +351,12 @@ static void buffer_init(void)
/* 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("");
}
}
@ -376,7 +370,7 @@ static void buffer_down(int nlines)
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 {
@ -386,7 +380,7 @@ static void buffer_down(int nlines)
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]);
}
}
}
@ -407,7 +401,7 @@ static void buffer_up(int nlines)
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 {
@ -417,7 +411,7 @@ static void buffer_up(int nlines)
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]);
}
}
}
@ -439,10 +433,10 @@ static void buffer_up(int nlines)
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");
}
}
}
@ -461,7 +455,7 @@ static void buffer_line(int linenum)
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();
@ -470,9 +464,9 @@ static void buffer_line(int linenum)
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 */
@ -508,7 +502,7 @@ static void examine_file(void)
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++;
@ -612,7 +606,7 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
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);
@ -622,17 +616,17 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
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);
@ -679,7 +673,7 @@ static void regex_process(void)
/* 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;
@ -693,7 +687,7 @@ static void regex_process(void)
/* 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;
@ -864,7 +858,7 @@ static void save_input_to_file(void)
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);

View File

@ -8,15 +8,6 @@
*/
#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)
@ -88,13 +79,13 @@ 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);

Some files were not shown because too many files have changed in this diff Show More