summaryrefslogtreecommitdiffstats
path: root/opkg-opk/opk/write.c
diff options
context:
space:
mode:
Diffstat (limited to 'opkg-opk/opk/write.c')
-rw-r--r--opkg-opk/opk/write.c88
1 files changed, 38 insertions, 50 deletions
diff --git a/opkg-opk/opk/write.c b/opkg-opk/opk/write.c
index 520b5fd..996007d 100644
--- a/opkg-opk/opk/write.c
+++ b/opkg-opk/opk/write.c
@@ -28,6 +28,7 @@
#include <sys/sysmacros.h>
#include <unistd.h>
#include "defs.h"
+#include "error.h"
#include "../dirent.h"
#include "../gzip.h"
#include "../i18n.h"
@@ -120,8 +121,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
for (name_i = 0; children[children_i]->d_name[name_i] != '\0';
++name_i) {
if (path_off + name_i + 1 == OPKG_OPK_USTAR_NAME_SIZE) {
- fprintf(stderr, "Error: File name \"%s\" too "
- "long",
+ opkg_opk_error(_("File name \"%s\" too long"),
children[children_i]->d_name);
goto err;
}
@@ -130,7 +130,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
}
child_path[name_i] = '\0';
if (lstat(opk->path_real, &st) != 0) {
- fprintf(stderr, _("Error: Failed to stat \"%s\"\n"),
+ opkg_opk_error(_("Failed to stat \"%s\""),
opk->path_real);
goto err;
}
@@ -141,8 +141,8 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
gname = getgrgid(gid)->gr_name;
if (S_ISDIR(st.st_mode)) {
if (path_off + name_i + 2 == OPKG_OPK_USTAR_NAME_SIZE) {
- fprintf(stderr, "Error: File name \"%s\" too "
- "long", child_path);
+ opkg_opk_error(_("File name \"%s\" too long"),
+ child_path);
goto err;
}
child_path[name_i] = '/';
@@ -152,8 +152,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
uid, uname, gid, gname, 0, 0, 0,
opk->mtime, 'd', NULL) !=
OPKG_OPK_OK) {
- fputs(_("Error: Failed to write header\n"),
- stderr);
+ opkg_opk_error(_("Failed to write header"));
goto err;
}
if (_opkg_opk_opk_write_dir_read(opk, &child,
@@ -176,8 +175,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
uid, uname, gid, gname, 0, 0, 0,
opk->mtime, 'l', link) !=
OPKG_OPK_OK) {
- fputs(_("Error: Failed to write header\n"),
- stderr);
+ opkg_opk_error(_("Failed to write header"));
goto err;
}
} else if (S_ISCHR(st.st_mode)) {
@@ -188,8 +186,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
minor(st.st_rdev),
0, opk->mtime, 'c', NULL) !=
OPKG_OPK_OK) {
- fputs(_("Error: Failed to write header\n"),
- stderr);
+ opkg_opk_error(_("Failed to write header"));
goto err;
}
} else if (S_ISBLK(st.st_mode)) {
@@ -200,8 +197,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
minor(st.st_rdev),
0, opk->mtime, 'b', NULL) !=
OPKG_OPK_OK) {
- fputs(_("Error: Failed to write header\n"),
- stderr);
+ opkg_opk_error(_("Failed to write header"));
goto err;
}
} else if (S_ISFIFO(st.st_mode)) {
@@ -210,8 +206,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
uid, uname, gid, gname, 0, 0, 0,
opk->mtime, 'p', NULL) !=
OPKG_OPK_OK) {
- fputs(_("Error: Failed to write header\n"),
- stderr);
+ opkg_opk_error(_("Failed to write header"));
goto err;
}
} else if (S_ISREG(st.st_mode)) {
@@ -227,8 +222,8 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
devmajor, devminor, 0,
opk->mtime, type, NULL)
!= OPKG_OPK_OK) {
- fputs(_("Error: Failed to write header"
- "\n"), stderr);
+ opkg_opk_error(_("Failed to write "
+ "header"));
goto err;
}
continue;
@@ -238,14 +233,12 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
uid, uname, gid, gname, 0, 0,
st.st_size, opk->mtime, '-',
NULL) != OPKG_OPK_OK) {
- fputs(_("Error: Failed to write header\n"),
- stderr);
+ opkg_opk_error(_("Failed to write header"));
goto err;
}
fp = fopen(opk->path_real, "rb");
if (fp == NULL) {
- fprintf(stderr, _("Error: Failed to open file "
- "\"%s\"\n"),
+ opkg_opk_error(_("Failed to open file \"%s\""),
opk->path_real);
goto err;
}
@@ -258,25 +251,24 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
tot_read += num_read;
}
if (ferror(fp) != 0) {
- fputs(_("Error: Error reading file\n"), stderr);
+ opkg_opk_error(_("Error reading file"));
fclose(fp);
goto err;
}
if (fclose(fp) != 0) {
- fputs(_("Error: Failed to close file\n"),
- stderr);
+ opkg_opk_error(_("Failed to close file"));
goto err;
}
if ((uintmax_t) tot_read != (uintmax_t) st.st_size) {
- fprintf(stderr, _("Error: Expected %jd bytes "
- "but read %zu\n"),
+ opkg_opk_error(_("Expected %jd bytes "
+ "but read %zu"),
(intmax_t) st.st_size,
num_read);
goto err;
}
} else {
- fprintf(stderr, _("Error: Unknown type of file \"%s\"\n"
- ), opk->path_real);
+ opkg_opk_error(_("Unknown type of file \"%s\""),
+ opk->path_real);
goto err;
}
}
@@ -318,20 +310,20 @@ _opkg_opk_opk_build_inner_archive(struct opkg_opk_opk *opk,
}
fp = fopen(opk->temp_file_name, "w+b");
if (fp == NULL) {
- fprintf(stderr, _("Error: Failed to open file \"%s\"\n"),
+ opkg_opk_error(_("Failed to open file \"%s\""),
opk->temp_file_name);
goto err0;
}
opk->inner_gzip = opkg_opk_gzip_init_write(fp);
if (opk->inner_gzip == NULL) {
- fputs(_("Error: Failed to initialize compressor\n"), stderr);
+ opkg_opk_error(_("Failed to initialize compressor"));
goto err1;
}
/* Initialize inner ustar archiver. */
opk->inner_ustar = opkg_opk_ustar_init(opk->inner_gzip);
if (opk->inner_ustar == NULL) {
- fputs(_("Error: Failed to initialize archiver\n"), stderr);
+ opkg_opk_error(_("Failed to initialize archiver"));
goto err2;
}
@@ -346,8 +338,7 @@ _opkg_opk_opk_build_inner_archive(struct opkg_opk_opk *opk,
opk->path_virt = opk->path_real + opk->data_dir_len;
}
if (stat(opk->path_real, &st) != 0) {
- fprintf(stderr, _("Error: Failed to stat \"%s\"\n"),
- opk->path_real);
+ opkg_opk_error(_("Failed to stat \"%s\""), opk->path_real);
goto err3;
}
uid = st.st_uid;
@@ -357,8 +348,7 @@ _opkg_opk_opk_build_inner_archive(struct opkg_opk_opk *opk,
if (opkg_opk_ustar_write_header(opk->inner_ustar, &dirent,
st.st_mode & 0777, uid, uname, gid, gname, 0,
0, 0, opk->mtime, 'd', NULL) != OPKG_OPK_OK) {
- fputs(_("Error: Failed to write header\n"),
- stderr);
+ opkg_opk_error(_("Failed to write header"));
goto err3;
}
if (_opkg_opk_opk_write_dir_read(opk, &dirent, 1 /* Skip '/' */) !=
@@ -368,7 +358,7 @@ _opkg_opk_opk_build_inner_archive(struct opkg_opk_opk *opk,
/* Write trailer. */
if (opkg_opk_ustar_write_trailer(opk->inner_ustar) != OPKG_OPK_OK) {
- fputs(_("Error: Failed to write trailer\n"), stderr);
+ opkg_opk_error(_("Failed to write trailer"));
goto err3;
}
@@ -385,13 +375,13 @@ _opkg_opk_opk_build_inner_archive(struct opkg_opk_opk *opk,
0, opk->outer_uname, 0, opk->outer_gname, 0, 0,
written, opk->mtime, '-', NULL) !=
OPKG_OPK_OK) {
- fputs(_("Error: Failed to write header\n"), stderr);
+ opkg_opk_error(_("Failed to write header"));
goto err1;
}
/* Read temporary file into outer archive. */
if (fseek(fp, 0L, SEEK_SET) != 0) {
- fputs(_("Error: Failed to seek in file\n"), stderr);
+ opkg_opk_error(_("Failed to seek in file"));
goto err1;
}
opkg_opk_ustar_get_buffer(opk->outer_ustar, &buffer, &size);
@@ -401,17 +391,17 @@ _opkg_opk_opk_build_inner_archive(struct opkg_opk_opk *opk,
tot_read += num_read;
}
if (ferror(fp) != 0) {
- fputs(_("Error: Error reading file\n"), stderr);
+ opkg_opk_error(_("Error reading file"));
fclose(fp);
goto err1;
}
if (fclose(fp) != 0) {
- fputs(_("Error: Failed to close file\n"), stderr);
+ opkg_opk_error(_("Failed to close file"));
goto err1;
}
unlink(opk->temp_file_name);
if (tot_read != written) {
- fprintf(stderr, _("Error: Wrote %lu bytes but read %lu\n"),
+ opkg_opk_error(_("Wrote %lu bytes but read %lu"),
written, num_read);
goto err1;
}
@@ -440,8 +430,7 @@ opkg_opk_opk_write(struct opkg_opk_opk *opk, const char *file_name)
ret = OPKG_OPK_OK;
if (_opkg_opk_opk_source_date_epoch(&opk->mtime) == OPKG_OPK_ERROR) {
- fputs(_("Error: Missing or invalid SOURCE_DATE_EPOCH\n"),
- stderr);
+ opkg_opk_error(_("Missing or invalid SOURCE_DATE_EPOCH"));
ret = OPKG_OPK_ERROR;
goto out0;
}
@@ -451,8 +440,7 @@ opkg_opk_opk_write(struct opkg_opk_opk *opk, const char *file_name)
/* Open outer archive. */
opk->file = fopen(file_name, "wb");
if (opk->file == NULL) {
- fprintf(stderr, _("Error: Failed to open file \"%s\"\n"),
- file_name);
+ opkg_opk_error(_("Failed to open file \"%s\""), file_name);
ret = OPKG_OPK_ERROR;
goto out0;
}
@@ -460,7 +448,7 @@ opkg_opk_opk_write(struct opkg_opk_opk *opk, const char *file_name)
/* Initialize outer gzip compressor. */
opk->outer_gzip = opkg_opk_gzip_init_write(opk->file);
if (opk->outer_gzip == NULL) {
- fputs(_("Error: Failed to initialize\n"), stderr);
+ opkg_opk_error(_("Failed to initialize"));
ret = OPKG_OPK_ERROR;
goto out1;
}
@@ -468,7 +456,7 @@ opkg_opk_opk_write(struct opkg_opk_opk *opk, const char *file_name)
/* Initialize outer ustar archiver. */
opk->outer_ustar = opkg_opk_ustar_init(opk->outer_gzip);
if (opk->outer_ustar == NULL) {
- fputs(_("Error: Failed to initialize\n"), stderr);
+ opkg_opk_error(_("Failed to initialize"));
ret = OPKG_OPK_ERROR;
goto out2;
}
@@ -482,14 +470,14 @@ opkg_opk_opk_write(struct opkg_opk_opk *opk, const char *file_name)
if (opkg_opk_ustar_write_header(opk->outer_ustar, &dirent, 0644,
0, opk->outer_uname, 0, opk->outer_gname, 0, 0,
4, opk->mtime, '-', NULL) != OPKG_OPK_OK) {
- fputs(_("Error: Failed to write header\n"), stderr);
+ opkg_opk_error(_("Failed to write header"));
ret = OPKG_OPK_ERROR;
goto out3;
}
opkg_opk_ustar_get_buffer(opk->outer_ustar, &buffer, &size);
memcpy(buffer, "2.0\n", 4);
if (opkg_opk_ustar_write_data(opk->outer_ustar, 4) != OPKG_OPK_OK) {
- fputs(_("Error: Failed to write data\n"), stderr);
+ opkg_opk_error(_("Failed to write data"));
ret = OPKG_OPK_ERROR;
goto out3;
}
@@ -530,7 +518,7 @@ opkg_opk_opk_write(struct opkg_opk_opk *opk, const char *file_name)
/* Write trailer. */
if (opkg_opk_ustar_write_trailer(opk->outer_ustar) != OPKG_OPK_OK) {
- fputs(_("Error: Failed to write trailer\n"), stderr);
+ opkg_opk_error(_("Failed to write trailer"));
ret = OPKG_OPK_ERROR;
goto out5;
}