summaryrefslogtreecommitdiffstats
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Makefile.am5
-rw-r--r--libbb/error_msg.c46
-rw-r--r--libbb/error_msg_and_die.c47
-rw-r--r--libbb/gz_open.c18
-rw-r--r--libbb/libbb.h28
-rw-r--r--libbb/messages.c24
-rw-r--r--libbb/perror_msg.c45
-rw-r--r--libbb/perror_msg_and_die.c46
-rw-r--r--libbb/unarchive.c8
-rw-r--r--libbb/unzip.c10
-rw-r--r--libbb/verror_msg.c43
-rw-r--r--libbb/vperror_msg.c45
-rw-r--r--libbb/xfuncs.c8
-rw-r--r--libbb/xreadlink.c2
14 files changed, 37 insertions, 338 deletions
diff --git a/libbb/Makefile.am b/libbb/Makefile.am
index 2da2dfd..1cc82df 100644
--- a/libbb/Makefile.am
+++ b/libbb/Makefile.am
@@ -11,12 +11,9 @@ libbb_la_SOURCES = gz_open.c \
unarchive.c \
copy_file.c \
copy_file_chunk.c \
- error_msg.c error_msg_and_die.c \
- perror_msg.c perror_msg_and_die.c \
xreadlink.c \
concat_path_file.c \
- verror_msg.c vperror_msg.c \
- xfuncs.c messages.c \
+ xfuncs.c \
last_char_is.c \
make_directory.c \
safe_strncpy.c \
diff --git a/libbb/error_msg.c b/libbb/error_msg.c
deleted file mode 100644
index 58308b6..0000000
--- a/libbb/error_msg.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void error_msg(const char *s, ...)
-{
- va_list p;
-
- va_start(p, s);
- verror_msg(s, p);
- va_end(p);
- putc('\n', stderr);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff --git a/libbb/error_msg_and_die.c b/libbb/error_msg_and_die.c
deleted file mode 100644
index 67a79c3..0000000
--- a/libbb/error_msg_and_die.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void error_msg_and_die(const char *s, ...)
-{
- va_list p;
-
- va_start(p, s);
- verror_msg(s, p);
- va_end(p);
- putc('\n', stderr);
- exit(EXIT_FAILURE);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff --git a/libbb/gz_open.c b/libbb/gz_open.c
index 3d07b58..7c7c722 100644
--- a/libbb/gz_open.c
+++ b/libbb/gz_open.c
@@ -35,11 +35,11 @@ gz_open(FILE *compressed_file, int *pid)
int unzip_pipe[2];
if (pipe(unzip_pipe)!=0) {
- perror_msg("%s: pipe", __FUNCTION__);
+ perror_msg("pipe");
return(NULL);
}
if ((*pid = fork()) == -1) {
- perror_msg("%s: fork", __FUNCTION__);
+ perror_msg("fork");
return(NULL);
}
if (*pid==0) {
@@ -62,26 +62,26 @@ gz_close(int gunzip_pid)
int ret;
if (waitpid(gunzip_pid, &status, 0) == -1) {
- perror_msg("%s: waitpid", __FUNCTION__);
+ perror_msg("waitpid");
return -1;
}
if (WIFSIGNALED(status)) {
- error_msg("%s: unzip process killed by signal %d\n",
- __FUNCTION__, WTERMSIG(status));
+ error_msg("Unzip process killed by signal %d.\n",
+ WTERMSIG(status));
return -1;
}
if (!WIFEXITED(status)) {
/* shouldn't happen */
- error_msg("%s: Your system is broken: got status %d from waitpid\n",
- __FUNCTION__, status);
+ error_msg("Your system is broken: got status %d from waitpid.\n",
+ status);
return -1;
}
if ((ret = WEXITSTATUS(status))) {
- error_msg("%s: unzip process failed with return code %d.\n",
- __FUNCTION__, ret);
+ error_msg("Unzip process failed with return code %d.\n",
+ ret);
return -1;
}
diff --git a/libbb/libbb.h b/libbb/libbb.h
index 619b400..4e1fafc 100644
--- a/libbb/libbb.h
+++ b/libbb/libbb.h
@@ -24,10 +24,10 @@
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
-
+#include <stdlib.h>
#include <netdb.h>
-#include <features.h>
+#include "../libopkg/opkg_message.h"
#ifndef FALSE
#define FALSE ((int) 0)
@@ -37,15 +37,20 @@
#define TRUE ((int) 1)
#endif
-extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
-extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
-extern void perror_msg(const char *s, ...);
-extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
-extern void archive_xread_all(int fd, char *buf, size_t count);
+#define error_msg(fmt, args...) opkg_msg(ERROR, fmt"\n", ##args)
+#define perror_msg(fmt, args...) opkg_perror(ERROR, fmt, ##args)
+#define error_msg_and_die(fmt, args...) \
+ do { \
+ error_msg(fmt, ##args); \
+ exit(EXIT_FAILURE); \
+ } while (0)
+#define perror_msg_and_die(fmt, args...) \
+ do { \
+ perror_msg(fmt, ##args); \
+ exit(EXIT_FAILURE); \
+ } while (0)
-/* These two are used internally -- you shouldn't need to use them */
-extern void verror_msg(const char *s, va_list p);
-extern void vperror_msg(const char *s, va_list p);
+extern void archive_xread_all(int fd, char *buf, size_t count);
const char *mode_string(int mode);
const char *time_string(time_t timeVal);
@@ -115,7 +120,4 @@ enum {
FILEUTILS_FORCE = 8,
};
-extern const char *applet_name;
-extern const char * const memory_exhausted;
-
#endif /* __LIBBB_H__ */
diff --git a/libbb/messages.c b/libbb/messages.c
deleted file mode 100644
index b9334c4..0000000
--- a/libbb/messages.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-#include "libbb.h"
-
-const char * const memory_exhausted = "memory exhausted";
diff --git a/libbb/perror_msg.c b/libbb/perror_msg.c
deleted file mode 100644
index 8c57b0d..0000000
--- a/libbb/perror_msg.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void perror_msg(const char *s, ...)
-{
- va_list p;
-
- va_start(p, s);
- vperror_msg(s, p);
- va_end(p);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff --git a/libbb/perror_msg_and_die.c b/libbb/perror_msg_and_die.c
deleted file mode 100644
index 9004925..0000000
--- a/libbb/perror_msg_and_die.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void perror_msg_and_die(const char *s, ...)
-{
- va_list p;
-
- va_start(p, s);
- vperror_msg(s, p);
- va_end(p);
- exit(EXIT_FAILURE);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff --git a/libbb/unarchive.c b/libbb/unarchive.c
index 31c76d2..03a63bd 100644
--- a/libbb/unarchive.c
+++ b/libbb/unarchive.c
@@ -185,7 +185,7 @@ extract_archive(FILE *src_stream, FILE *out_stream,
goto cleanup;
}
archive_offset += file_entry->size;
- copy_file_chunk(src_stream, dst_stream, file_entry->size);
+ *err = copy_file_chunk(src_stream, dst_stream, file_entry->size);
fclose(dst_stream);
}
break;
@@ -194,7 +194,7 @@ extract_archive(FILE *src_stream, FILE *out_stream,
if (mkdir(full_name, file_entry->mode) < 0) {
if ((function & extract_quiet) != extract_quiet) {
*err = -1;
- perror_msg("%s: %s", __FUNCTION__, full_name);
+ perror_msg("Cannot make dir %s", full_name);
}
}
}
@@ -641,7 +641,8 @@ deb_extract(const char *package_filename, FILE *out_stream,
else if (extract_function & extract_data_tar_gz) {
ared_file = "data.tar.gz";
} else {
- fprintf(stderr, "no file specified to extract -- extract_function=%x\n", extract_function);
+ opkg_msg(ERROR, "Internal error: extract_function=%x\n",
+ extract_function);
*err = -1;
goto cleanup;
}
@@ -668,7 +669,6 @@ deb_extract(const char *package_filename, FILE *out_stream,
/* open a stream of decompressed data */
uncompressed_stream = gz_open(deb_stream, &gunzip_pid);
if (uncompressed_stream == NULL) {
- printf("%s: %d\n", __FUNCTION__, __LINE__);
*err = -1;
goto cleanup;
}
diff --git a/libbb/unzip.c b/libbb/unzip.c
index 7ff07a5..e0a2388 100644
--- a/libbb/unzip.c
+++ b/libbb/unzip.c
@@ -57,9 +57,6 @@ static unsigned long *crc_table = NULL;
static unsigned long crc; /* shift register contents */
-/* Return codes from gzip */
-static const int ERROR = 1;
-
/*
* window size--must be a power of two, and
* at least 32K for zip's deflate method
@@ -100,7 +97,7 @@ static const unsigned short mask_bits[] = {
static void abort_gzip()
{
error_msg("gzip aborted\n");
- _exit(ERROR);
+ _exit(-1);
}
static void make_crc_table()
@@ -975,8 +972,7 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file)
}
if (method < 0) {
- printf("it failed\n");
- return(exit_code); /* error message already emitted */
+ return(exit_code);
}
make_crc_table();
@@ -987,7 +983,7 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file)
int res = inflate();
if (res == 3) {
- error_msg(memory_exhausted);
+ perror_msg("inflate");
exit_code = 1;
} else if (res != 0) {
error_msg("invalid compressed data--format violated");
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c
deleted file mode 100644
index 21cde20..0000000
--- a/libbb/verror_msg.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void verror_msg(const char *s, va_list p)
-{
- fflush(stdout);
- fprintf(stderr, "%s: ", applet_name);
- vfprintf(stderr, s, p);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff --git a/libbb/vperror_msg.c b/libbb/vperror_msg.c
deleted file mode 100644
index 7da5bae..0000000
--- a/libbb/vperror_msg.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void vperror_msg(const char *s, va_list p)
-{
- int err=errno;
- if(s == 0) s = "";
- verror_msg(s, p);
- if (*s) s = ": ";
- fprintf(stderr, "%s%s\n", s, strerror(err));
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index c12b282..4374048 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -30,7 +30,7 @@ extern void *xmalloc(size_t size)
{
void *ptr = malloc(size);
if (ptr == NULL && size != 0)
- error_msg_and_die(memory_exhausted);
+ perror_msg_and_die("malloc");
return ptr;
}
@@ -38,7 +38,7 @@ extern void *xrealloc(void *ptr, size_t size)
{
ptr = realloc(ptr, size);
if (ptr == NULL && size != 0)
- error_msg_and_die(memory_exhausted);
+ perror_msg_and_die("realloc");
return ptr;
}
@@ -46,7 +46,7 @@ extern void *xcalloc(size_t nmemb, size_t size)
{
void *ptr = calloc(nmemb, size);
if (ptr == NULL && nmemb != 0 && size != 0)
- error_msg_and_die(memory_exhausted);
+ perror_msg_and_die("calloc");
return ptr;
}
@@ -59,7 +59,7 @@ extern char * xstrdup (const char *s) {
t = strdup (s);
if (t == NULL)
- error_msg_and_die(memory_exhausted);
+ perror_msg_and_die("strdup");
return t;
}
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c
index 932e487..5b0504c 100644
--- a/libbb/xreadlink.c
+++ b/libbb/xreadlink.c
@@ -24,7 +24,7 @@ extern char *xreadlink(const char *path)
buf = xrealloc(buf, bufsize += GROWBY);
readsize = readlink(path, buf, bufsize); /* 1st try */
if (readsize == -1) {
- perror_msg("%s:%s", applet_name, path);
+ perror_msg("%s", path);
return NULL;
}
}