summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto <alberto.ruiz@codethink.co.uk>2011-09-30 17:43:31 +0100
committerAlberto <alberto.ruiz@codethink.co.uk>2011-09-30 17:43:31 +0100
commit06dedc4631b4d8fcd589e71ba261baccc5fa1620 (patch)
treeb96b9763b3e0d6b836d631f073f6d5aaae511748
parentcca3e1e0f412a3f1d2d161521a3c1e8ce8df9d45 (diff)
downloadtbdiff-06dedc4631b4d8fcd589e71ba261baccc5fa1620.tar.gz
Remove return statement from tbd_error
-rw-r--r--libtbd_apply.c135
-rw-r--r--libtbd_create.c60
-rw-r--r--tbdiff.h7
3 files changed, 103 insertions, 99 deletions
diff --git a/libtbd_apply.c b/libtbd_apply.c
index 3bf4fc0..ce113f5 100644
--- a/libtbd_apply.c
+++ b/libtbd_apply.c
@@ -32,7 +32,6 @@
#include <unistd.h>
#include <utime.h>
-
char*
tbd_apply_fread_string(FILE *stream)
{
@@ -52,19 +51,19 @@ tbd_apply_identify(FILE *stream)
{
uint8_t cmd;
if(fread(&cmd, 1, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
if(cmd != TBD_CMD_IDENTIFY)
- tbd_error(TBD_ERROR_INVALID_PARAMETER);
+ return tbd_error(TBD_ERROR_INVALID_PARAMETER);
uint16_t nlen;
if(fread(&nlen, 2, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
if(strlen(TB_DIFF_PROTOCOL_ID) != nlen)
- tbd_error(TBD_ERROR_INVALID_PARAMETER);
+ return tbd_error(TBD_ERROR_INVALID_PARAMETER);
char nstr[nlen];
if(fread(nstr, 1, nlen, stream) != nlen)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
if(strncmp(nstr, TB_DIFF_PROTOCOL_ID, nlen) != 0)
- tbd_error(TBD_ERROR_INVALID_PARAMETER);
+ return tbd_error(TBD_ERROR_INVALID_PARAMETER);
return 0;
}
@@ -73,33 +72,33 @@ tbd_apply_cmd_dir_create(FILE *stream)
{
uint16_t dlen;
if(fread(&dlen, sizeof(uint16_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
char dname[dlen + 1];
if(fread(dname, 1, dlen, stream) != dlen)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
dname[dlen] = '\0';
fprintf(stderr, "cmd_dir_create %s\n", dname);
if(strchr(dname, '/') != NULL)
- tbd_error(TBD_ERROR_INVALID_PARAMETER);
+ return tbd_error(TBD_ERROR_INVALID_PARAMETER);
uint32_t mtime;
if(fread(&mtime, sizeof(uint32_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
uint32_t uid;
if(fread(&uid, sizeof(uint32_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
uint32_t gid;
if(fread(&gid, sizeof(uint32_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
uint32_t mode;
if(fread(&mode, sizeof(uint32_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
if(mkdir(dname, (mode_t)mode) != 0)
- tbd_error(TBD_ERROR_UNABLE_TO_CREATE_DIR);
+ return tbd_error(TBD_ERROR_UNABLE_TO_CREATE_DIR);
// Apply metadata.
struct utimbuf timebuff = { time(NULL), mtime };
@@ -117,19 +116,19 @@ tbd_apply_cmd_dir_enter(FILE *stream,
{
uint16_t dlen;
if(fread(&dlen, 2, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
char dname[dlen + 1];
if(fread(dname, 1, dlen, stream) != dlen)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
dname[dlen] = '\0';
fprintf(stderr, "cmd_dir_enter %s\n", dname);
if((strchr(dname, '/') != NULL) || (strcmp(dname, "..") == 0))
- tbd_error(TBD_ERROR_UNABLE_TO_CHANGE_DIR);
+ return tbd_error(TBD_ERROR_UNABLE_TO_CHANGE_DIR);
if(depth != NULL)
(*depth)++;
if(chdir(dname) != 0)
- tbd_error(TBD_ERROR_UNABLE_TO_CHANGE_DIR);
+ return tbd_error(TBD_ERROR_UNABLE_TO_CHANGE_DIR);
return 0;
}
@@ -139,17 +138,17 @@ tbd_apply_cmd_dir_leave(FILE *stream,
{
uint8_t count;
if(fread(&count, 1, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
uintptr_t rcount = count + 1;
fprintf(stderr, "cmd_dir_leave %"PRIuPTR"\n", rcount);
if((depth != NULL) && (*depth < rcount))
- tbd_error(TBD_ERROR_INVALID_PARAMETER);
+ return tbd_error(TBD_ERROR_INVALID_PARAMETER);
uintptr_t i;
for(i = 0; i < rcount; i++) {
if(chdir("..") != 0)
- tbd_error(TBD_ERROR_UNABLE_TO_CHANGE_DIR);
+ return tbd_error(TBD_ERROR_UNABLE_TO_CHANGE_DIR);
}
if(depth != NULL)
@@ -162,13 +161,13 @@ tbd_apply_cmd_file_create(FILE *stream)
{
uint16_t flen;
if(fread(&flen, 2, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
char fname[flen + 1];
if(fread(fname, 1, flen, stream) != flen)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
fname[flen] = '\0';
if((strchr(fname, '/') != NULL) || (strcmp(fname, "..") == 0))
- tbd_error(TBD_ERROR_INVALID_PARAMETER);
+ return tbd_error(TBD_ERROR_INVALID_PARAMETER);
uint32_t mtime;
uint32_t mode;
@@ -181,19 +180,19 @@ tbd_apply_cmd_file_create(FILE *stream)
fread(&uid, sizeof(uint32_t), 1, stream) != 1 ||
fread(&gid, sizeof(uint32_t), 1, stream) != 1 ||
fread(&fsize, 4, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
fprintf(stderr, "cmd_file_create %s:%"PRId32"\n", fname, fsize);
FILE *fp = fopen(fname, "rb");
if(fp != NULL) {
fclose(fp);
- tbd_error(TBD_ERROR_FILE_ALREADY_EXISTS);
+ return tbd_error(TBD_ERROR_FILE_ALREADY_EXISTS);
}
fp = fopen(fname, "wb");
if(fp == NULL)
- tbd_error(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_WRITING);
+ return tbd_error(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_WRITING);
uintptr_t block = 256;
uint8_t fbuff[block];
@@ -201,9 +200,9 @@ tbd_apply_cmd_file_create(FILE *stream)
if(fsize < block)
block = fsize;
if(fread(fbuff, 1, block, stream) != block)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
if(fwrite(fbuff, 1, block, fp) != block)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
}
fclose(fp);
@@ -230,17 +229,17 @@ tbd_apply_cmd_file_delta(FILE *stream)
uint32_t mode;
uint16_t flen;
if(fread(&flen, 2, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
char fname[flen + 1];
if(fread(fname, 1, flen, stream) != flen)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
fname[flen] = '\0';
fprintf(stderr, "cmd_file_delta %s\n", fname);
if((strchr(fname, '/') != NULL) ||
(strcmp(fname, "..") == 0))
- tbd_error(TBD_ERROR_INVALID_PARAMETER);
+ return tbd_error(TBD_ERROR_INVALID_PARAMETER);
/* Reading metadata */
if(fread(&mdata_mask, sizeof(uint16_t), 1, stream) != 1 ||
@@ -248,26 +247,26 @@ tbd_apply_cmd_file_delta(FILE *stream)
fread(&uid, sizeof(uint32_t), 1, stream) != 1 ||
fread(&gid, sizeof(uint32_t), 1, stream) != 1 ||
fread(&mode, sizeof(uint32_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
FILE *op = fopen(fname, "rb");
if(op == NULL)
- tbd_error(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING);
+ return tbd_error(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING);
if(remove(fname) != 0) {
fclose(op);
- tbd_error(TBD_ERROR_UNABLE_TO_REMOVE_FILE);
+ return tbd_error(TBD_ERROR_UNABLE_TO_REMOVE_FILE);
}
FILE *np = fopen(fname, "wb");
if(np == NULL) {
fclose(op);
- tbd_error(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_WRITING);
+ return tbd_error(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_WRITING);
}
uint32_t dstart, dend;
if(fread(&dstart, 4, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
if(fread(&dend, 4, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
uintptr_t block;
uint8_t fbuff[256];
@@ -275,34 +274,34 @@ tbd_apply_cmd_file_delta(FILE *stream)
if(dstart < block)
block = dstart;
if(fread(fbuff, 1, block, op) != block)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
if(fwrite(fbuff, 1, block, np) != block)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
}
uint32_t fsize;
if(fread(&fsize, 4, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
for(block = 256; fsize != 0; fsize -= block) {
if(fsize < block)
block = fsize;
if(fread(fbuff, 1, block, stream) != block)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
if(fwrite(fbuff, 1, block, np) != block)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
}
if(fseek(op, dend, SEEK_SET) != 0) {
fclose(np);
fclose(op);
- tbd_error(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM);
}
for(block = 256; block != 0;) {
block = fread(fbuff, 1, block, op);
if(fwrite(fbuff, 1, block, np) != block)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
}
fclose(np);
@@ -329,14 +328,14 @@ tbd_apply_cmd_entity_delete_for_name(const char *name)
DIR *dp = opendir(name);
if(dp == NULL) {
if(remove(name) != 0)
- tbd_error(TBD_ERROR_UNABLE_TO_REMOVE_FILE);
+ return tbd_error(TBD_ERROR_UNABLE_TO_REMOVE_FILE);
return 0;
}
if(chdir(name) != 0) {
closedir(dp);
- tbd_error(TBD_ERROR_UNABLE_TO_CHANGE_DIR);
+ return tbd_error(TBD_ERROR_UNABLE_TO_CHANGE_DIR);
}
struct dirent *entry;
@@ -350,7 +349,7 @@ tbd_apply_cmd_entity_delete_for_name(const char *name)
closedir(dp);
if(chdir("..") != 0)
- tbd_error(TBD_ERROR_UNABLE_TO_CHANGE_DIR);
+ return tbd_error(TBD_ERROR_UNABLE_TO_CHANGE_DIR);
return err;
}
@@ -358,9 +357,9 @@ tbd_apply_cmd_entity_delete_for_name(const char *name)
closedir(dp);
if(chdir("..") != 0)
- tbd_error(TBD_ERROR_UNABLE_TO_CHANGE_DIR);
+ return tbd_error(TBD_ERROR_UNABLE_TO_CHANGE_DIR);
if(remove(name) != 0)
- tbd_error(TBD_ERROR_UNABLE_TO_REMOVE_FILE);
+ return tbd_error(TBD_ERROR_UNABLE_TO_REMOVE_FILE);
return 0;
}
@@ -369,16 +368,16 @@ tbd_apply_cmd_entity_delete(FILE *stream)
{
uint16_t elen;
if(fread(&elen, 2, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
char ename[elen + 1];
if(fread(ename, 1, elen, stream) != elen)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
ename[elen] = '\0';
fprintf(stderr, "cmd_entity_delete %s\n", ename);
if((strchr(ename, '/') != NULL) || (strcmp(ename, "..") == 0))
- tbd_error(TBD_ERROR_INVALID_PARAMETER);
+ return tbd_error(TBD_ERROR_INVALID_PARAMETER);
return tbd_apply_cmd_entity_delete_for_name(ename);
}
@@ -393,25 +392,25 @@ tbd_apply_cmd_symlink_create(FILE *stream)
if(fread(&mtime, sizeof(uint32_t), 1, stream) != 1 ||
fread(&uid, sizeof(uint32_t), 1, stream) != 1 ||
fread(&gid, sizeof(uint32_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
/* Reading link file name */
if(fread(&len, sizeof(uint16_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
char linkname[len + 1];
linkname[len] = '\0';
if(fread(linkname, sizeof(char), len, stream) != len)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
/* Reading target path */
if(fread(&len, sizeof(uint16_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
char linkpath[len+1];
linkpath[len] = '\0';
if(fread(linkpath, sizeof(char), len, stream) != len)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
fprintf(stderr, "cmd_symlink_create %s -> %s\n", linkname, linkpath);
@@ -447,7 +446,7 @@ tbd_apply_cmd_special_create(FILE *stream)
fread(&gid, sizeof(uint32_t), 1, stream) != 1 ||
fread(&dev, sizeof(uint32_t), 1, stream) != 1) {
free(name);
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
}
fprintf(stderr, "cmd_special_create %s\n", name);
@@ -482,12 +481,12 @@ tbd_apply_cmd_dir_delta(FILE *stream)
fread(&uid, sizeof(uint32_t), 1, stream) != 1 ||
fread(&gid, sizeof(uint32_t), 1, stream) != 1 ||
fread(&mode, sizeof(uint32_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
int ret;
char *dname = tbd_apply_fread_string(stream);
if(dname == NULL)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
fprintf(stderr, "cmd_dir_delta %s\n", dname);
@@ -518,12 +517,12 @@ tbd_apply_cmd_file_mdata_update(FILE *stream)
fread(&uid, sizeof(uint32_t), 1, stream) != 1 ||
fread(&gid, sizeof(uint32_t), 1, stream) != 1 ||
fread(&mode, sizeof(uint32_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
int ret;
char *dname = tbd_apply_fread_string(stream);
if(dname == NULL)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
fprintf(stderr, "cmd_metadata_update %s\n", dname);
@@ -544,7 +543,7 @@ int
tbd_apply(FILE *stream)
{
if(stream == NULL)
- tbd_error(TBD_ERROR_NULL_POINTER);
+ return tbd_error(TBD_ERROR_NULL_POINTER);
int err;
if((err = tbd_apply_identify(stream)) != 0)
@@ -555,7 +554,7 @@ tbd_apply(FILE *stream)
while(!flush) {
uint8_t cmd;
if(fread(&cmd, 1, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
switch(cmd) {
case TBD_CMD_DIR_CREATE:
if((err = tbd_apply_cmd_dir_create(stream)) != 0)
@@ -595,7 +594,7 @@ tbd_apply(FILE *stream)
break;
case TBD_CMD_ENTITY_MOVE:
case TBD_CMD_ENTITY_COPY:
- tbd_error(TBD_ERROR_FEATURE_NOT_IMPLEMENTED); // TODO - Implement.
+ return tbd_error(TBD_ERROR_FEATURE_NOT_IMPLEMENTED); // TODO - Implement.
case TBD_CMD_ENTITY_DELETE:
if((err = tbd_apply_cmd_entity_delete(stream)) != 0)
return err;
@@ -605,7 +604,7 @@ tbd_apply(FILE *stream)
break;
default:
fprintf(stderr, "Error: Invalid command 0x%02"PRIx8".\n", cmd);
- tbd_error(TBD_ERROR_INVALID_PARAMETER);
+ return tbd_error(TBD_ERROR_INVALID_PARAMETER);
}
}
diff --git a/libtbd_create.c b/libtbd_create.c
index 985cd01..1ae823c 100644
--- a/libtbd_create.c
+++ b/libtbd_create.c
@@ -36,7 +36,7 @@ tbd_create_fwrite_cmd(FILE *stream,
uint8_t cmd)
{
if(fwrite(&cmd, 1, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
return 0;
}
@@ -47,7 +47,7 @@ tbd_create_fwrite_string(FILE *stream,
uint16_t slen = strlen(string);
if((fwrite(&slen, 2, 1, stream) != 1)
|| (fwrite(string, 1, slen, stream) != slen))
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
return 0;
}
@@ -56,7 +56,7 @@ tbd_create_fwrite_mdata_mask(FILE *stream,
uint16_t mask)
{
if(fwrite(&mask, sizeof(uint16_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
return 0;
}
@@ -65,7 +65,7 @@ tbd_create_fwrite_mtime(FILE *stream,
uint32_t mtime)
{
if(fwrite(&mtime, sizeof(uint32_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
return 0;
}
@@ -74,7 +74,7 @@ tbd_create_fwrite_mode(FILE *stream,
uint32_t mode)
{
if(fwrite(&mode, sizeof(uint32_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
return 0;
}
@@ -83,7 +83,7 @@ tbd_create_fwrite_gid(FILE *stream,
gid_t gid)
{
if(fwrite(&gid, sizeof(gid_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
return 0;
}
@@ -92,7 +92,7 @@ tbd_create_fwrite_uid(FILE *stream,
uid_t uid)
{
if(fwrite(&uid, sizeof(uid_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
return 0;
}
@@ -101,7 +101,7 @@ tbd_create_fwrite_dev(FILE *stream,
uint32_t dev)
{
if(fwrite(&dev, sizeof(uint32_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
return 0;
}
@@ -138,11 +138,11 @@ tbd_create_cmd_file_create(FILE *stream,
uint32_t size = f->size;
if(fwrite(&size, sizeof(uint32_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
FILE *fp = tbd_stat_fopen(f, "rb");
if(fp == NULL)
- tbd_error(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING);
+ return tbd_error(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING);
uint8_t buff[256];
uintptr_t b = 256;
@@ -150,7 +150,7 @@ tbd_create_cmd_file_create(FILE *stream,
b = fread(buff, 1, b, fp);
if(fwrite(buff, 1, b, stream) != b) {
fclose(fp);
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
}
}
fclose(fp);
@@ -206,11 +206,11 @@ tbd_create_cmd_file_delta(FILE *stream,
{
FILE *fpa = tbd_stat_fopen(a, "rb");
if(fpa == NULL)
- tbd_error(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING);
+ return tbd_error(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING);
FILE *fpb = tbd_stat_fopen(b, "rb");
if(fpb == NULL) {
fclose(fpa);
- tbd_error(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING);
+ return tbd_error(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING);
}
// Calculate start.
@@ -239,7 +239,7 @@ tbd_create_cmd_file_delta(FILE *stream,
if((fseek(fpa, 0, SEEK_END) != 0) || (fseek(fpb, 0, SEEK_END) != 0)) {
fclose(fpa);
fclose(fpb);
- tbd_error(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM);
}
// Find length.
@@ -249,7 +249,7 @@ tbd_create_cmd_file_delta(FILE *stream,
if((flena < 0) || (flenb < 0)) {
fclose(fpa);
fclose(fpb);
- tbd_error(TBD_ERROR_UNABLE_TO_DETECT_STREAM_POSITION);
+ return tbd_error(TBD_ERROR_UNABLE_TO_DETECT_STREAM_POSITION);
}
// Find end.
@@ -265,14 +265,14 @@ tbd_create_cmd_file_delta(FILE *stream,
|| (fseek(fpb, flenb - (o + blks[1]), SEEK_SET) != 0)) {
fclose(fpa);
fclose(fpb);
- tbd_error(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM);
}
if((fread(buff[0], 1, blks[0], fpa) != blks[0])
|| (fread(buff[1], 1, blks[1], fpb) != blks[1])) {
fclose(fpa);
fclose(fpb);
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
}
uintptr_t i, ja, jb;
@@ -321,22 +321,22 @@ tbd_create_cmd_file_delta(FILE *stream,
(fwrite(&end, sizeof(uint32_t), 1, stream) != 1) ||
(fwrite(&size, sizeof(uint32_t), 1, stream) != 1)) {
fclose(fpb);
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
}
if(fseek(fpb, start, SEEK_SET) != 0) {
fclose(fpb);
- tbd_error(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM);
}
for(o = 0; o < size; o += 256) {
uintptr_t csize = ((size - o) > 256 ? 256 : (size - o));
if(fread(buff[0], 1, csize, fpb) != csize) {
fclose(fpb);
- tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_READ_STREAM);
}
if(fwrite(buff[0], 1, csize, stream) != csize) {
fclose(fpb);
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
}
}
@@ -385,13 +385,13 @@ tbd_create_cmd_dir_leave(FILE *stream,
token = 255;
for(; count > 256; count -= 256) {
if(fwrite(&token, sizeof (uint8_t), 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
}
}
token = (count - 1);
if(fwrite(&token, 1, 1, stream) != 1)
- tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
+ return tbd_error(TBD_ERROR_UNABLE_TO_WRITE_STREAM);
return 0;
}
@@ -547,7 +547,7 @@ tbd_create_dir(FILE *stream,
tbd_stat_t *f = tbd_stat_entry(d, i);
if(f == NULL)
- tbd_error(TBD_ERROR_UNABLE_TO_STAT_FILE);
+ return tbd_error(TBD_ERROR_UNABLE_TO_STAT_FILE);
switch(f->type) {
case TBD_STAT_TYPE_FILE:
@@ -567,7 +567,7 @@ tbd_create_dir(FILE *stream,
break;
default:
tbd_stat_free(f);
- tbd_error(TBD_ERROR_FEATURE_NOT_IMPLEMENTED);
+ return tbd_error(TBD_ERROR_FEATURE_NOT_IMPLEMENTED);
break;
}
tbd_stat_free(f);
@@ -585,7 +585,7 @@ tbd_create_impl(FILE *stream,
bool top)
{
if((a == NULL) && (b == NULL))
- tbd_error(TBD_ERROR_NULL_POINTER);
+ return tbd_error(TBD_ERROR_NULL_POINTER);
int err;
if(((b == NULL) || ((a != NULL) && (a->type != b->type)))) {
@@ -612,7 +612,7 @@ tbd_create_impl(FILE *stream,
fprintf(stderr, "special new %s\n", b->name);
return tbd_create_cmd_special_create(stream, b);
default:
- tbd_error(TBD_ERROR_FEATURE_NOT_IMPLEMENTED);
+ return tbd_error(TBD_ERROR_FEATURE_NOT_IMPLEMENTED);
break;
}
}
@@ -648,7 +648,7 @@ tbd_create_impl(FILE *stream,
for(i = 0; i < b->size; i++) {
tbd_stat_t *_b = tbd_stat_entry(b, i);
if(_b == NULL)
- tbd_error(TBD_ERROR_UNABLE_TO_STAT_FILE);
+ return tbd_error(TBD_ERROR_UNABLE_TO_STAT_FILE);
tbd_stat_t *_a = tbd_stat_entry_find(a, _b->name);
err = tbd_create_impl(stream, _a, _b, false);
tbd_stat_free(_a);
@@ -661,7 +661,7 @@ tbd_create_impl(FILE *stream,
for(i = 0; i < a->size; i++) {
tbd_stat_t *_a = tbd_stat_entry(a, i);
if(_a == NULL)
- tbd_error(TBD_ERROR_UNABLE_TO_STAT_FILE);
+ return tbd_error(TBD_ERROR_UNABLE_TO_STAT_FILE);
tbd_stat_t *_b = tbd_stat_entry_find(b, _a->name);
fprintf(stderr, "file delete %s\n", _a->name);
err = (_b != NULL ? 0 : tbd_create_cmd_entity_delete(stream, _a->name));
@@ -683,7 +683,7 @@ tbd_create(FILE *stream,
{
int err;
if((stream == NULL) || (a == NULL) || (b == NULL))
- tbd_error(TBD_ERROR_NULL_POINTER);
+ return tbd_error(TBD_ERROR_NULL_POINTER);
if((err = tbd_create_cmd_ident(stream)) != 0 ||
(err = tbd_create_impl(stream, a, b, true)) != 0)
diff --git a/tbdiff.h b/tbdiff.h
index ece78cf..bf28022 100644
--- a/tbdiff.h
+++ b/tbdiff.h
@@ -77,7 +77,12 @@ typedef enum {
#ifdef NDEBUG
#define tbd_error(e) return e
#else
-#define tbd_error(e) { if(e != 0) fprintf(stderr, "TBDiff error '%s' in function '%s' at line %d of file '%s'.\n", #e, __FUNCTION__, __LINE__, __FILE__); return e; }
+/*#define tbd_error(e) { if(e != 0) fprintf(stderr, "TBDiff error '%s' in function '%s' at line %d of file '%s'.\n", #e, __FUNCTION__, __LINE__, __FILE__); return e; }*/
+#define tbd_error(e)\
+ ({if(e != 0) fprintf(stderr, \
+ "TBDiff error '%s' in function '%s' at line %d of file '%s'.\n", \
+ #e, __func__, __LINE__, __FILE__); \
+ e;})
#endif
extern int tbd_apply (FILE *stream);