From 04dedff28d9295b5b926d9c9d2d2fb13fe0fc3a8 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 11:56:52 +0100 Subject: documentation: Remove issues which have already been resolved Some issues in the TODO file have been resolved and no longer apply, these issues have been removed. --- TODO | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/TODO b/TODO index a7c6da0..d2102d3 100644 --- a/TODO +++ b/TODO @@ -12,32 +12,18 @@ There has been a problem while testing on a real system directory tree, during d ---------------------------------------------- Right now the stream parsing and the filesystem operations are both made in one go. This operations should be made separately so that output the stream and dry runs can be performed. We should have a defined struct per command for easier understanding of what goes into the wire. -+ Abstract endianness -------------------- -At the moment the endianness of the file is the same than the one used in the image creation host. We need to state the endianness of the file and perform the transformations in those platforms that need it. - + Abstract the stream object -------------------------- Right now FILE* is used as the stream object. However abstracting the stream object is desirable. -+ Write atuotools or waf scripts to build and release ---------------------------------------------------- -A simple Makefile is not the best way to maintain a package. Waf or autotools scripts should be put in place. - General ======= - + Use sizeof(var) or (type) instead of fixed byte lengths on fread/fwrite - + Fix endian issues in case we run the generator on a different - endianness to the deployer. + Separate reading/writing stream data from actual file system operation + Create a manifest of deleted/created/modified files + Improve commandline for the deploy command - + Rename the project to trebuchet-differ (tbdiff) - + Create autotools scripts + Improve function namespaces to ease understanding - + Add copyright headers to all source files Features ======== -- cgit v1.2.1 From 3b703fd98b1bfb5d34c3668bf07412b1bc93cf54 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 15:01:55 +0100 Subject: Update gitignore file to ignore autotools generated files --- .gitignore | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.gitignore b/.gitignore index a2f5be1..6bb8de7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,31 @@ tbdiff-deploy/tbdiff-deploy *.o *.log *.d +*.la +*.lo +*.pc +.deps +.libs +INSTALL +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +compile +config.guess +config.h +config.h.in +config.h.in~ +config.status +config.sub +configure +depcomp +install-sh +libtool +ltmain.sh +m4/ +missing +sockbind +stamp-h1 +symtime +test-driver -- cgit v1.2.1 From 1dea1372f801e55d09e4abc0c429a479a1ea1bcc Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 14:31:42 +0100 Subject: Use sys/xattr from libc if attr/xattr is unavailable On my system tbdiff failed to build because attr/xattr doesn't exist, also the attr package was not easy to find. On searching I discovered that the functionality we use in attr.h is provided by modern versions of libc, as shown here: https://bugzilla.kernel.org/show_bug.cgi?id=70141 This patch falls back to using libc sys/xattr.h when attr/xattr.h is unavailable. --- tbdiff/tbdiff-apply.c | 8 +++++++- tbdiff/tbdiff-xattrs.c | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index e281d73..04f0b40 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 Codethink Ltd. + * Copyright (C) 2011-2014 Codethink Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as @@ -29,7 +29,13 @@ #include #include +#include "config.h" + +#if HAVE_ATTR_XATTR_H #include +#else +#include +#endif #include #include diff --git a/tbdiff/tbdiff-xattrs.c b/tbdiff/tbdiff-xattrs.c index 95d263f..0f2adc8 100644 --- a/tbdiff/tbdiff-xattrs.c +++ b/tbdiff/tbdiff-xattrs.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 Codethink Ltd. + * Copyright (C) 2011-2014 Codethink Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as @@ -18,7 +18,14 @@ #include #include +#include "config.h" + +#if HAVE_ATTR_XATTR_H #include +#else +#include +#endif + #include #include -- cgit v1.2.1 From 2e3bf668ae17aee6a499e8332541516ecc92e5b0 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 14:40:42 +0100 Subject: Use ENODATA instead of ENOATTR The man page for lsetxattr says that ENOATTR is a synonym of ENODATA, since ENOATTR is not always available in sys/xattr.h we'll use ENODATA instead. --- tbdiff/tbdiff-xattrs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tbdiff/tbdiff-xattrs.c b/tbdiff/tbdiff-xattrs.c index 0f2adc8..c020ee5 100644 --- a/tbdiff/tbdiff-xattrs.c +++ b/tbdiff/tbdiff-xattrs.c @@ -124,7 +124,7 @@ static int name_remove(char const *name, void *ud) { char const *path = ud; if (lremovexattr(path, name) < 0) { switch (errno) { - case ENOATTR: + case ENODATA: return TBD_ERROR(TBD_ERROR_XATTRS_MISSING_ATTR); case ENOTSUP: return TBD_ERROR(TBD_ERROR_XATTRS_NOT_SUPPORTED); -- cgit v1.2.1 From e36bf9fe7ea9509c9bff5e5eb1d323da919428ef Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 12:05:16 +0100 Subject: Fix memory leak of name in tbdiff-stat.c On error the duplicated string in 'name' would have leaked. --- tbdiff/tbdiff-stat.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tbdiff/tbdiff-stat.c b/tbdiff/tbdiff-stat.c index fd8964e..66e2caf 100644 --- a/tbdiff/tbdiff-stat.c +++ b/tbdiff/tbdiff-stat.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 Codethink Ltd. + * Copyright (C) 2011-2014 Codethink Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as @@ -144,8 +144,10 @@ tbd_stat_entry(tbd_stat_t *file, uint32_t entry) closedir (dp); char *spath = tbd_stat_subpath(file, name); - if(spath == NULL) + if(spath == NULL) { + free(name); return NULL; + } tbd_stat_t *ret = tbd_stat_from_path(name, (const char*)spath); -- cgit v1.2.1 From 52d38f16c87471ef9eabce8aa053b3c46c7a449b Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 12:21:04 +0100 Subject: Fix fp resource leaks in tbdiff-apply There were a lot of instances where on error the code would fail to close the opened file pointer. --- tbdiff/tbdiff-apply.c | 69 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index 04f0b40..ea0b0c0 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -252,10 +252,14 @@ tbd_apply_cmd_file_create(FILE *stream) for(; fsize != 0; fsize -= block) { if(fsize < block) block = fsize; - if(fread(fbuff, 1, block, stream) != block) + if(fread(fbuff, 1, block, stream) != block) { + fclose(fp); return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); - if(fwrite(fbuff, 1, block, fp) != block) + } + if(fwrite(fbuff, 1, block, fp) != block) { + fclose(fp); return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); + } } fclose(fp); @@ -280,6 +284,8 @@ tbd_apply_cmd_file_delta(FILE *stream) gid_t gid; mode_t mode; uint16_t flen; + int error; + if(tbd_read_uint16_t(&flen, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char fname[flen + 1]; @@ -315,45 +321,60 @@ tbd_apply_cmd_file_delta(FILE *stream) } uint32_t dstart, dend; - if(tbd_read_uint32_t(&dstart, stream) != 1) - return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); - if(tbd_read_uint32_t(&dend, stream) != 1) - return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); + if(tbd_read_uint32_t(&dstart, stream) != 1) { + error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); + goto tbd_apply_cmd_file_delta_error; + } + if(tbd_read_uint32_t(&dend, stream) != 1) { + error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); + goto tbd_apply_cmd_file_delta_error; + } uintptr_t block; uint8_t fbuff[256]; for(block = 256; dstart != 0; dstart -= block) { if(dstart < block) block = dstart; - if(fread(fbuff, 1, block, op) != block) - return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); - if(fwrite(fbuff, 1, block, np) != block) - return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); + if(fread(fbuff, 1, block, op) != block) { + error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); + goto tbd_apply_cmd_file_delta_error; + } + if(fwrite(fbuff, 1, block, np) != block) { + error = TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); + goto tbd_apply_cmd_file_delta_error; + } } uint32_t fsize; - if(tbd_read_uint32_t(&fsize, stream) != 1) - return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); + if(tbd_read_uint32_t(&fsize, stream) != 1) { + error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); + goto tbd_apply_cmd_file_delta_error; + } for(block = 256; fsize != 0; fsize -= block) { if(fsize < block) block = fsize; - if(fread(fbuff, 1, block, stream) != block) - return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); - if(fwrite(fbuff, 1, block, np) != block) - return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); + if(fread(fbuff, 1, block, stream) != block) { + error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); + goto tbd_apply_cmd_file_delta_error; + } + if(fwrite(fbuff, 1, block, np) != block) { + error = TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); + goto tbd_apply_cmd_file_delta_error; + } } if(fseek(op, dend, SEEK_SET) != 0) { - fclose(np); - fclose(op); - return TBD_ERROR(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM); + error = TBD_ERROR(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM); + goto tbd_apply_cmd_file_delta_error; } for(block = 256; block != 0;) { block = fread(fbuff, 1, block, op); - if(fwrite(fbuff, 1, block, np) != block) - return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); + if(fwrite(fbuff, 1, block, np) != block) { + error = TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); + goto tbd_apply_cmd_file_delta_error; + } } fclose(np); @@ -384,6 +405,12 @@ tbd_apply_cmd_file_delta(FILE *stream) } return 0; + +tbd_apply_cmd_file_delta_error: + fclose(np); + fclose(op); + + return error; } static int tbd_apply_cmd_entity_delete_for_name(const char*); -- cgit v1.2.1 From 8bbda9e95e86f97cf07a78a09c1c6db9a4e51d8e Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 11:48:58 +0100 Subject: style: Convert all cpp style comments to c style comments --- tbdiff/tbdiff-apply.c | 20 ++++++++++---------- tbdiff/tbdiff-create.c | 16 ++++++++-------- tbdiff/tbdiff-io.c | 4 ++-- tbdiff/tbdiff-stat.h | 4 ++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index ea0b0c0..dddc185 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -143,9 +143,9 @@ tbd_apply_cmd_dir_create(FILE *stream) if(mkdir(dname, (mode_t)mode) != 0) return TBD_ERROR(TBD_ERROR_UNABLE_TO_CREATE_DIR); - // Apply metadata. + /* Apply metadata. */ struct utimbuf timebuff = { time(NULL), mtime }; - utime(dname, &timebuff); // Don't care if it succeeds right now. + utime(dname, &timebuff); /* Don't care if it succeeds right now. */ chown(dname, (uid_t)uid, (gid_t)gid); chmod (dname, mode); @@ -263,10 +263,10 @@ tbd_apply_cmd_file_create(FILE *stream) } fclose(fp); - // Apply metadata. + /* Apply metadata. */ struct utimbuf timebuff = { time(NULL), mtime }; - // Don't care if it succeeds right now. + /* Don't care if it succeeds right now. */ utime(fname, &timebuff); /* Chown ALWAYS have to be done before chmod */ chown(fname, (uid_t)uid, (gid_t)gid); @@ -380,7 +380,7 @@ tbd_apply_cmd_file_delta(FILE *stream) fclose(np); fclose(op); - // Apply metadata. + /* Apply metadata. */ /* file was removed so old permissions were lost * all permissions need to be reapplied, all were sent in this protocol * if only changed sent will have to save mdata from file before it is @@ -529,7 +529,7 @@ tbd_apply_cmd_symlink_create(FILE *stream) tv[1].tv_sec = (long) mtime; tv[1].tv_usec = 0; - lutimes(linkname, tv); // Don't care if it succeeds right now. + lutimes(linkname, tv); /* Don't care if it succeeds right now. */ lchown(linkname, (uid_t)uid, (uid_t)gid); return TBD_ERROR_SUCCESS; @@ -563,7 +563,7 @@ tbd_apply_cmd_special_create(FILE *stream) } struct utimbuf timebuff = { time(NULL), mtime }; - utime(name, &timebuff); // Don't care if it succeeds right now. + utime(name, &timebuff); /* Don't care if it succeeds right now. */ chown(name, (uid_t)uid, (gid_t)gid); chmod(name, mode); @@ -596,7 +596,7 @@ tbd_apply_cmd_dir_delta(FILE *stream) if(metadata_mask & TBD_METADATA_MTIME) { struct utimbuf timebuff = { time(NULL), mtime }; - utime(dname, &timebuff); // Don't care if it succeeds right now. + utime(dname, &timebuff); /* Don't care if it succeeds right now. */ } if(metadata_mask & TBD_METADATA_UID || metadata_mask & TBD_METADATA_GID) chown(dname, (uid_t)uid, (gid_t)gid); @@ -631,7 +631,7 @@ tbd_apply_cmd_file_mdata_update(FILE *stream) if(metadata_mask & TBD_METADATA_MTIME) { struct utimbuf timebuff = { time(NULL), mtime }; - utime(dname, &timebuff); // Don't care if it succeeds right now. + utime(dname, &timebuff); /* Don't care if it succeeds right now. */ } if(metadata_mask & TBD_METADATA_UID || metadata_mask & TBD_METADATA_GID) chown(dname, (uid_t)uid, (gid_t)gid); @@ -755,7 +755,7 @@ tbd_apply(FILE *stream) break; case TBD_CMD_ENTITY_MOVE: case TBD_CMD_ENTITY_COPY: - return 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; diff --git a/tbdiff/tbdiff-create.c b/tbdiff/tbdiff-create.c index ec5a8ce..33881ed 100644 --- a/tbdiff/tbdiff-create.c +++ b/tbdiff/tbdiff-create.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 Codethink Ltd. + * Copyright (C) 2011-2014 Codethink Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as @@ -303,7 +303,7 @@ tbd_create_cmd_file_delta(FILE *stream, return TBD_ERROR(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING); } - // Calculate start. + /* Calculate start. */ uintptr_t blks[2] = { 256, 256 }; uint8_t buff[2][256]; @@ -332,7 +332,7 @@ tbd_create_cmd_file_delta(FILE *stream, return TBD_ERROR(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM); } - // Find length. + /* Find length. */ long flena = ftell(fpa); long flenb = ftell(fpb); @@ -342,7 +342,7 @@ tbd_create_cmd_file_delta(FILE *stream, return TBD_ERROR(TBD_ERROR_UNABLE_TO_DETECT_STREAM_POSITION); } - // Find end. + /* Find end. */ blks[0] = 256; blks[1] = 256; for(o = 0; true; o += blks[1]) { @@ -377,7 +377,7 @@ tbd_create_cmd_file_delta(FILE *stream, } fclose(fpa); - // Ensure that the start and end don't overlap for the new file. + /* Ensure that the start and end don't overlap for the new file. */ if((flenb - o) < start) o = (flenb - start); @@ -385,7 +385,7 @@ tbd_create_cmd_file_delta(FILE *stream, if(end < start) end = start; - uint32_t size = flenb - ((flena - end) + start); //(flenb - (o + start)); + uint32_t size = flenb - ((flena - end) + start); /* (flenb - (o + start)); */ /* Data is identical, only alter metadata */ if((end == start) && (size == 0)) { @@ -740,7 +740,7 @@ tbd_create_impl(FILE *stream, if(!top && ((err = tbd_create_cmd_dir_enter(stream, b->name)) != 0)) return err; - // Handle changes/additions. + /* Handle changes/additions. */ uintptr_t i; for(i = 0; i < b->size; i++) { tbd_stat_t *_b = tbd_stat_entry(b, i); @@ -754,7 +754,7 @@ tbd_create_impl(FILE *stream, return err; } - // Handle deletions. + /* Handle deletions. */ for(i = 0; i < a->size; i++) { err = 0; diff --git a/tbdiff/tbdiff-io.c b/tbdiff/tbdiff-io.c index 698273b..14249bd 100644 --- a/tbdiff/tbdiff-io.c +++ b/tbdiff/tbdiff-io.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 Codethink Ltd. + * Copyright (C) 2011-2014 Codethink Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as @@ -22,7 +22,7 @@ #include #if __BYTE_ORDER == __BIG_ENDIAN -//inverts the indices of an array of bytes. +/*inverts the indices of an array of bytes. */ static void byteswap (char* value, int size) { char tmp; int i; diff --git a/tbdiff/tbdiff-stat.h b/tbdiff/tbdiff-stat.h index d23cc80..2908ee9 100644 --- a/tbdiff/tbdiff-stat.h +++ b/tbdiff/tbdiff-stat.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 Codethink Ltd. + * Copyright (C) 2011-2014 Codethink Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as @@ -42,7 +42,7 @@ typedef struct { char* name; tbd_stat_type_e type; time_t mtime; - uint32_t size; // Count for directory. + uint32_t size; /* Count for directory. */ uid_t uid; gid_t gid; mode_t mode; -- cgit v1.2.1 From e5cc67a153629789b94ff04317caab86668aefa8 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 11:50:31 +0100 Subject: style: Fix alignment of tbd_stat_t struct members --- tbdiff/tbdiff-stat.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tbdiff/tbdiff-stat.h b/tbdiff/tbdiff-stat.h index 2908ee9..85d7e1b 100644 --- a/tbdiff/tbdiff-stat.h +++ b/tbdiff/tbdiff-stat.h @@ -43,9 +43,9 @@ typedef struct { tbd_stat_type_e type; time_t mtime; uint32_t size; /* Count for directory. */ - uid_t uid; - gid_t gid; - mode_t mode; + uid_t uid; + gid_t gid; + mode_t mode; uint32_t rdev; } tbd_stat_t; -- cgit v1.2.1 From d14fea7f73b1f2a96d5d4384e3bbbae98cf2965f Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 12:00:31 +0100 Subject: style: Fix indentation and whitespace in tbdiff-io.c --- tbdiff/tbdiff-io.c | 160 ++++++++++++++++++++++++++--------------------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/tbdiff/tbdiff-io.c b/tbdiff/tbdiff-io.c index 14249bd..c386a38 100644 --- a/tbdiff/tbdiff-io.c +++ b/tbdiff/tbdiff-io.c @@ -23,144 +23,144 @@ #if __BYTE_ORDER == __BIG_ENDIAN /*inverts the indices of an array of bytes. */ -static void byteswap (char* value, int size) { - char tmp; - int i; - for (i = 0; i < size/2; i++) { - tmp = value[i]; - value[i] = value[size-i-1]; - value[size-i-1] = tmp; - } +static void byteswap(char* value, int size) { + char tmp; + int i; + for (i = 0; i < size/2; i++) { + tmp = value[i]; + value[i] = value[size-i-1]; + value[size-i-1] = tmp; + } } #endif -size_t tbd_write_uint16_t (uint16_t value, FILE* stream) { +size_t tbd_write_uint16_t(uint16_t value, FILE* stream) { #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); + byteswap((char*)&value, sizeof(value)); #endif - return fwrite(&value, sizeof(value), 1, stream); + return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_uint32_t (uint32_t value, FILE* stream) { +size_t tbd_write_uint32_t(uint32_t value, FILE* stream) { #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); + byteswap((char*)&value, sizeof(value)); #endif - return fwrite(&value, sizeof(value), 1, stream); + return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_uint64_t (uint64_t value, FILE* stream) { +size_t tbd_write_uint64_t(uint64_t value, FILE* stream) { #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); + byteswap((char*)&value, sizeof(value)); #endif - return fwrite(&value, sizeof(value), 1, stream); + return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_time_t (time_t value, FILE* stream) { - uint64_t realv = value; +size_t tbd_write_time_t(time_t value, FILE* stream) { + uint64_t realv = value; #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&realv, sizeof(realv)); + byteswap((char*)&realv, sizeof(realv)); #endif - return fwrite(&realv, sizeof(realv), 1, stream); + return fwrite(&realv, sizeof(realv), 1, stream); } -size_t tbd_write_mode_t (mode_t value, FILE* stream) { +size_t tbd_write_mode_t(mode_t value, FILE* stream) { #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); + byteswap((char*)&value, sizeof(value)); #endif - return fwrite(&value, sizeof(value), 1, stream); + return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_uid_t (uid_t value, FILE* stream) { +size_t tbd_write_uid_t(uid_t value, FILE* stream) { #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); + byteswap((char*)&value, sizeof(value)); #endif - return fwrite(&value, sizeof(value), 1, stream); + return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_gid_t (gid_t value, FILE* stream) { +size_t tbd_write_gid_t(gid_t value, FILE* stream) { #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); + byteswap((char*)&value, sizeof(value)); #endif - return fwrite(&value, sizeof(value), 1, stream); + return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_size_t (size_t value, FILE* stream) { +size_t tbd_write_size_t(size_t value, FILE* stream) { #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); + byteswap((char*)&value, sizeof(value)); #endif - return fwrite(&value, sizeof(value), 1, stream); + return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_read_uint16_t (uint16_t *value, FILE* stream) { - assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); +size_t tbd_read_uint16_t(uint16_t *value, FILE* stream) { + assert(value != NULL); + size_t rval = fread(value, sizeof(*value), 1, stream); #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); + byteswap((char*)value, sizeof(*value)); #endif - return rval; + return rval; } -size_t tbd_read_uint32_t (uint32_t *value, FILE* stream) { - assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); +size_t tbd_read_uint32_t(uint32_t *value, FILE *stream) { + assert(value != NULL); + size_t rval = fread(value, sizeof(*value), 1, stream); #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); + byteswap((char*)value, sizeof(*value)); #endif - return rval; + return rval; } -size_t tbd_read_uint64_t (uint64_t *value, FILE* stream) { - assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); +size_t tbd_read_uint64_t(uint64_t *value, FILE *stream) { + assert(value != NULL); + size_t rval = fread(value, sizeof(*value), 1, stream); #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); + byteswap((char*)value, sizeof(*value)); #endif - return rval; + return rval; } -size_t tbd_read_time_t (time_t *value, FILE* stream) { - assert(value != NULL); - uint64_t realv; - size_t rval = fread(&realv, sizeof(realv), 1, stream); +size_t tbd_read_time_t(time_t *value, FILE *stream) { + assert(value != NULL); + uint64_t realv; + size_t rval = fread(&realv, sizeof(realv), 1, stream); #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&realv, sizeof(realv)); + byteswap((char*)&realv, sizeof(realv)); #endif - *value = realv; - return rval; - } + *value = realv; + return rval; +} -size_t tbd_read_mode_t (mode_t *value, FILE* stream) { - assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); +size_t tbd_read_mode_t(mode_t *value, FILE *stream) { + assert(value != NULL); + size_t rval = fread(value, sizeof(*value), 1, stream); #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); + byteswap((char*)value, sizeof(*value)); #endif - return rval; - } + return rval; +} -size_t tbd_read_uid_t (uid_t *value, FILE* stream) { - assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); +size_t tbd_read_uid_t(uid_t *value, FILE *stream) { + assert(value != NULL); + size_t rval = fread(value, sizeof(*value), 1, stream); #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); + byteswap((char*)value, sizeof(*value)); #endif - return rval; - } + return rval; +} -size_t tbd_read_gid_t (gid_t *value, FILE* stream) { - assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); +size_t tbd_read_gid_t(gid_t *value, FILE *stream) { + assert(value != NULL); + size_t rval = fread(value, sizeof(*value), 1, stream); #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); + byteswap((char*)value, sizeof(*value)); #endif - return rval; - } + return rval; +} -size_t tbd_read_size_t (size_t *value, FILE* stream) { - assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); +size_t tbd_read_size_t(size_t *value, FILE *stream) { + assert(value != NULL); + size_t rval = fread(value, sizeof(*value), 1, stream); #if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); + byteswap((char*)value, sizeof(*value)); #endif - return rval; - } + return rval; +} -- cgit v1.2.1 From 949840e4562054b3588ae591bf7f402279126054 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 12:33:20 +0100 Subject: style: Fix alignment and whitespace issues in tbdiff-create --- tbdiff/tbdiff-create.c | 120 +++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/tbdiff/tbdiff-create.c b/tbdiff/tbdiff-create.c index 33881ed..21738a5 100644 --- a/tbdiff/tbdiff-create.c +++ b/tbdiff/tbdiff-create.c @@ -53,7 +53,9 @@ tbd_create_fwrite_string(FILE *stream, } static int -tbd_create_fwrite_block(FILE *stream, void const *data, size_t size) +tbd_create_fwrite_block(FILE *stream, + void const *data, + size_t size) { if (fwrite(&size, 1, sizeof(size), stream) != sizeof(size)) { return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -75,8 +77,8 @@ tbd_create_fwrite_mdata_mask(FILE *stream, } static int -tbd_create_fwrite_mtime(FILE *stream, - time_t mtime) +tbd_create_fwrite_mtime(FILE *stream, + time_t mtime) { if(tbd_write_time_t(mtime, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -84,8 +86,8 @@ tbd_create_fwrite_mtime(FILE *stream, } static int -tbd_create_fwrite_mode(FILE *stream, - mode_t mode) +tbd_create_fwrite_mode(FILE *stream, + mode_t mode) { if(tbd_write_mode_t(mode, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -93,8 +95,8 @@ tbd_create_fwrite_mode(FILE *stream, } static int -tbd_create_fwrite_gid(FILE *stream, - gid_t gid) +tbd_create_fwrite_gid(FILE *stream, + gid_t gid) { if(tbd_write_gid_t(gid, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -102,8 +104,8 @@ tbd_create_fwrite_gid(FILE *stream, } static int -tbd_create_fwrite_uid(FILE *stream, - uid_t uid) +tbd_create_fwrite_uid(FILE *stream, + uid_t uid) { if(tbd_write_uid_t(uid, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -111,8 +113,8 @@ tbd_create_fwrite_uid(FILE *stream, } static int -tbd_create_fwrite_dev(FILE *stream, - uint32_t dev) +tbd_create_fwrite_dev(FILE *stream, + uint32_t dev) { if(tbd_write_uint32_t(dev, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -219,11 +221,11 @@ tbd_create_cmd_file_create(FILE *stream, { int err; if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_FILE_CREATE)) != 0 || - (err = tbd_create_fwrite_string(stream, f->name)) != 0 || - (err = tbd_create_fwrite_mtime (stream, f->mtime)) != 0 || - (err = tbd_create_fwrite_mode (stream, f->mode)) != 0 || - (err = tbd_create_fwrite_uid (stream, f->uid)) != 0 || - (err = tbd_create_fwrite_gid (stream, f->gid)) != 0) + (err = tbd_create_fwrite_string(stream, f->name)) != 0 || + (err = tbd_create_fwrite_mtime (stream, f->mtime)) != 0 || + (err = tbd_create_fwrite_mode (stream, f->mode)) != 0 || + (err = tbd_create_fwrite_uid (stream, f->uid)) != 0 || + (err = tbd_create_fwrite_gid (stream, f->gid)) != 0) return err; uint32_t size = f->size; @@ -268,7 +270,7 @@ tbd_metadata_mask(tbd_stat_t *a, } static int -tbd_create_cmd_file_metadata_update(FILE *stream, +tbd_create_cmd_file_metadata_update(FILE *stream, tbd_stat_t *a, tbd_stat_t *b) { @@ -279,11 +281,11 @@ tbd_create_cmd_file_metadata_update(FILE *stream, return 0; /* TODO: Optimize protocol by only sending useful metadata */ if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_FILE_METADATA_UPDATE)) != 0 || - (err = tbd_create_fwrite_mdata_mask (stream, metadata_mask)) != 0 || - (err = tbd_create_fwrite_mtime (stream, b->mtime)) != 0 || - (err = tbd_create_fwrite_uid (stream, b->uid)) != 0 || - (err = tbd_create_fwrite_gid (stream, b->gid)) != 0 || - (err = tbd_create_fwrite_mode (stream, b->mode)) != 0) + (err = tbd_create_fwrite_mdata_mask(stream, metadata_mask)) != 0 || + (err = tbd_create_fwrite_mtime (stream, b->mtime)) != 0 || + (err = tbd_create_fwrite_uid (stream, b->uid)) != 0 || + (err = tbd_create_fwrite_gid (stream, b->gid)) != 0 || + (err = tbd_create_fwrite_mode (stream, b->mode)) != 0) return err; return tbd_create_fwrite_string(stream, b->name); @@ -398,7 +400,7 @@ tbd_create_cmd_file_delta(FILE *stream, /* TODO: Optimize protocol by only sending useful metadata */ int err; - if(((err = tbd_create_fwrite_cmd(stream, TBD_CMD_FILE_DELTA)) != 0) || + if(((err = tbd_create_fwrite_cmd(stream, TBD_CMD_FILE_DELTA)) != 0) || ((err = tbd_create_fwrite_string(stream, b->name)) != 0) || ((err = tbd_create_fwrite_mdata_mask(stream, metadata_mask)) != 0) || ((err = tbd_create_fwrite_mtime (stream, b->mtime)) != 0) || @@ -436,16 +438,16 @@ tbd_create_cmd_file_delta(FILE *stream, } static int -tbd_create_cmd_dir_create(FILE *stream, - tbd_stat_t *d) +tbd_create_cmd_dir_create(FILE *stream, + tbd_stat_t *d) { int err; if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_DIR_CREATE)) != 0 || - (err = tbd_create_fwrite_string(stream, d->name)) != 0 || - (err = tbd_create_fwrite_mtime(stream, d->mtime)) != 0 || - (err = tbd_create_fwrite_uid(stream, d->uid)) != 0 || - (err = tbd_create_fwrite_gid(stream, d->gid)) != 0) + (err = tbd_create_fwrite_string(stream, d->name)) != 0 || + (err = tbd_create_fwrite_mtime(stream, d->mtime)) != 0 || + (err = tbd_create_fwrite_uid(stream, d->uid)) != 0 || + (err = tbd_create_fwrite_gid(stream, d->gid)) != 0) return err; return tbd_create_fwrite_mode(stream, d->mode); @@ -462,8 +464,8 @@ tbd_create_cmd_dir_enter(FILE *stream, } static int -tbd_create_cmd_dir_leave(FILE *stream, - tbd_stat_t *dir) +tbd_create_cmd_dir_leave(FILE *stream, + tbd_stat_t *dir) { int err; if ((err = tbd_create_fwrite_cmd(stream, TBD_CMD_DIR_LEAVE)) != @@ -495,7 +497,7 @@ tbd_create_cmd_dir_delta(FILE *stream, if(metadata_mask == TBD_METADATA_NONE) return 0; - if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_DIR_DELTA)) != 0 || + if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_DIR_DELTA)) != 0 || (err = tbd_create_fwrite_mdata_mask (stream, metadata_mask)) != 0 || (err = tbd_create_fwrite_mtime (stream, b->mtime)) != 0 || (err = tbd_create_fwrite_uid (stream, b->uid)) != 0 || @@ -507,8 +509,8 @@ tbd_create_cmd_dir_delta(FILE *stream, } static int -tbd_create_cmd_symlink_create(FILE *stream, - tbd_stat_t *symlink) +tbd_create_cmd_symlink_create(FILE *stream, + tbd_stat_t *symlink) { int err; char path[PATH_BUFFER_LENGTH]; @@ -521,19 +523,19 @@ tbd_create_cmd_symlink_create(FILE *stream, path[len] = '\0'; if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_SYMLINK_CREATE)) != 0 || - (err = tbd_create_fwrite_mtime (stream, symlink->mtime)) != 0 || - (err = tbd_create_fwrite_uid (stream, symlink->uid)) != 0 || - (err = tbd_create_fwrite_gid (stream, symlink->gid)) != 0 || - (err = tbd_create_fwrite_string(stream, symlink->name)) != 0) + (err = tbd_create_fwrite_mtime (stream, symlink->mtime)) != 0 || + (err = tbd_create_fwrite_uid (stream, symlink->uid)) != 0 || + (err = tbd_create_fwrite_gid (stream, symlink->gid)) != 0 || + (err = tbd_create_fwrite_string(stream, symlink->name)) != 0) return err; return tbd_create_fwrite_string(stream, path); } static int -tbd_create_cmd_symlink_delta(FILE *stream, - tbd_stat_t *a, - tbd_stat_t *b) +tbd_create_cmd_symlink_delta(FILE *stream, + tbd_stat_t *a, + tbd_stat_t *b) { int err; char path_a[PATH_BUFFER_LENGTH]; @@ -569,25 +571,25 @@ tbd_create_cmd_symlink_delta(FILE *stream, } static int -tbd_create_cmd_special_create(FILE *stream, - tbd_stat_t *nod) +tbd_create_cmd_special_create(FILE *stream, + tbd_stat_t *nod) { int err; if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_SPECIAL_CREATE)) != 0 || - (err = tbd_create_fwrite_string(stream, nod->name)) != 0 || - (err = tbd_create_fwrite_mtime (stream, nod->mtime)) != 0 || - (err = tbd_create_fwrite_mode (stream, nod->mode)) != 0 || - (err = tbd_create_fwrite_uid (stream, nod->uid)) != 0 || - (err = tbd_create_fwrite_gid (stream, nod->gid)) != 0) + (err = tbd_create_fwrite_string(stream, nod->name)) != 0 || + (err = tbd_create_fwrite_mtime (stream, nod->mtime)) != 0 || + (err = tbd_create_fwrite_mode (stream, nod->mode)) != 0 || + (err = tbd_create_fwrite_uid (stream, nod->uid)) != 0 || + (err = tbd_create_fwrite_gid (stream, nod->gid)) != 0) return err; return tbd_create_fwrite_dev(stream, nod->rdev); } static int -tbd_create_cmd_special_delta(FILE *stream, - tbd_stat_t *a, - tbd_stat_t *b) +tbd_create_cmd_special_delta(FILE *stream, + tbd_stat_t *a, + tbd_stat_t *b) { uint16_t metadata_mask = tbd_metadata_mask(a, b); if(a->rdev != b->rdev) @@ -670,10 +672,10 @@ tbd_create_dir(FILE *stream, } static int -tbd_create_impl(FILE *stream, - tbd_stat_t *a, - tbd_stat_t *b, - bool top) +tbd_create_impl(FILE *stream, + tbd_stat_t *a, + tbd_stat_t *b, + bool top) { if((a == NULL) && (b == NULL)) return TBD_ERROR(TBD_ERROR_NULL_POINTER); @@ -757,7 +759,7 @@ tbd_create_impl(FILE *stream, /* Handle deletions. */ for(i = 0; i < a->size; i++) { err = 0; - + tbd_stat_t *_a = tbd_stat_entry(a, i); if(_a == NULL) return TBD_ERROR(TBD_ERROR_UNABLE_TO_STAT_FILE); @@ -781,9 +783,9 @@ tbd_create_impl(FILE *stream, } int -tbd_create(FILE *stream, - tbd_stat_t *a, - tbd_stat_t *b) +tbd_create(FILE *stream, + tbd_stat_t *a, + tbd_stat_t *b) { int err; if((stream == NULL) || (a == NULL) || (b == NULL)) -- cgit v1.2.1 From 1c86c1cd05feb629e75ce50416c0de7038d879e6 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 15:44:37 +0100 Subject: style: Fix alignment and func defs in tbdiff-apply.c --- tbdiff/tbdiff-apply.c | 63 +++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index dddc185..ba2e5fc 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -66,7 +66,8 @@ tbd_apply_fread_string(FILE *stream) * - or realloc doesn't free old memory (though this will be a memory leak) * - or your allocator does nothing when asked to free non-allocated memory */ -int tbd_apply_fread_block(FILE *stream, void **data, size_t *size) +int +tbd_apply_fread_block(FILE *stream, void **data, size_t *size) { { size_t _size; @@ -228,11 +229,11 @@ tbd_apply_cmd_file_create(FILE *stream) gid_t gid; uint32_t fsize; - if(tbd_read_time_t(&mtime, stream) != 1 || - tbd_read_uint32_t(&mode, stream) != 1 || - tbd_read_uid_t(&uid, stream) != 1 || - tbd_read_gid_t(&gid, stream) != 1 || - tbd_read_uint32_t(&fsize, stream) != 1) + if(tbd_read_time_t (&mtime, stream) != 1 || + tbd_read_uint32_t(&mode , stream) != 1 || + tbd_read_uid_t (&uid , stream) != 1 || + tbd_read_gid_t (&gid , stream) != 1 || + tbd_read_uint32_t(&fsize, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); fprintf(stderr, "cmd_file_create %s:%"PRId32"\n", fname, fsize); @@ -301,10 +302,10 @@ tbd_apply_cmd_file_delta(FILE *stream) /* Reading metadata */ if(tbd_read_uint16_t(&mdata_mask, stream) != 1 || - tbd_read_time_t(&mtime, stream) != 1 || - tbd_read_uid_t(&uid, stream) != 1 || - tbd_read_gid_t(&gid, stream) != 1 || - tbd_read_uint32_t(&mode, stream) != 1) + tbd_read_time_t (&mtime , stream) != 1 || + tbd_read_uid_t (&uid , stream) != 1 || + tbd_read_gid_t (&gid , stream) != 1 || + tbd_read_uint32_t(&mode , stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); FILE *op = fopen(fname, "rb"); @@ -413,8 +414,11 @@ tbd_apply_cmd_file_delta_error: return error; } -static int tbd_apply_cmd_entity_delete_for_name(const char*); -static int tbd_apply_cmd_dir_delete(const char *name) +static int +tbd_apply_cmd_entity_delete_for_name(const char*); + +static int +tbd_apply_cmd_dir_delete(const char *name) { int err = TBD_ERROR_SUCCESS; DIR *dp; @@ -429,7 +433,7 @@ static int tbd_apply_cmd_dir_delete(const char *name) } while ((entry = readdir(dp)) != NULL) { - if ((strcmp(entry->d_name, ".") == 0) || + if ((strcmp(entry->d_name, "." ) == 0) || (strcmp(entry->d_name, "..") == 0)) { continue; } @@ -497,8 +501,8 @@ tbd_apply_cmd_symlink_create(FILE *stream) gid_t gid; if(tbd_read_time_t(&mtime, stream) != 1 || - tbd_read_uid_t(&uid, stream) != 1 || - tbd_read_gid_t(&gid, stream) != 1) + tbd_read_uid_t(&uid , stream) != 1 || + tbd_read_gid_t(&gid , stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); /* Reading link file name */ @@ -546,11 +550,11 @@ tbd_apply_cmd_special_create(FILE *stream) uint32_t dev; if(name == NULL || - tbd_read_time_t(&mtime, stream) != 1 || - tbd_read_mode_t(&mode, stream) != 1 || - tbd_read_uid_t(&uid, stream) != 1 || - tbd_read_gid_t(&gid, stream) != 1 || - tbd_read_uint32_t(&dev, stream) != 1) { + tbd_read_time_t (&mtime, stream) != 1 || + tbd_read_mode_t (&mode , stream) != 1 || + tbd_read_uid_t (&uid , stream) != 1 || + tbd_read_gid_t (&gid , stream) != 1 || + tbd_read_uint32_t(&dev , stream) != 1) { free(name); return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } @@ -582,10 +586,10 @@ tbd_apply_cmd_dir_delta(FILE *stream) mode_t mode; if(tbd_read_uint16_t(&metadata_mask, stream) != 1 || - tbd_read_time_t(&mtime, stream) != 1 || - tbd_read_uid_t(&uid, stream) != 1 || - tbd_read_gid_t(&gid, stream) != 1 || - tbd_read_uint32_t(&mode, stream) != 1) + tbd_read_time_t (&mtime , stream) != 1 || + tbd_read_uid_t (&uid , stream) != 1 || + tbd_read_gid_t (&gid , stream) != 1 || + tbd_read_uint32_t(&mode , stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char *dname = tbd_apply_fread_string(stream); @@ -617,10 +621,10 @@ tbd_apply_cmd_file_mdata_update(FILE *stream) mode_t mode; if(tbd_read_uint16_t(&metadata_mask, stream) != 1 || - tbd_read_time_t(&mtime, stream) != 1 || - tbd_read_uid_t(&uid, stream) != 1 || - tbd_read_gid_t(&gid, stream) != 1 || - tbd_read_uint32_t(&mode, stream) != 1) + tbd_read_time_t (&mtime , stream) != 1 || + tbd_read_uid_t (&uid , stream) != 1 || + tbd_read_gid_t (&gid , stream) != 1 || + tbd_read_uint32_t(&mode , stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char *dname = tbd_apply_fread_string(stream); @@ -642,7 +646,8 @@ tbd_apply_cmd_file_mdata_update(FILE *stream) return TBD_ERROR_SUCCESS; } -static int tbd_apply_cmd_xattrs_update(FILE *stream) +static int +tbd_apply_cmd_xattrs_update(FILE *stream) { int err = TBD_ERROR_SUCCESS; char *fname; -- cgit v1.2.1 From e9344787030b3ba052db9f79462ffa5da3a0ee32 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 15:35:05 +0100 Subject: style: Fix whitespace in tbdiff-common.h --- tbdiff/tbdiff-common.h | 54 +++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tbdiff/tbdiff-common.h b/tbdiff/tbdiff-common.h index d4ac2c8..06b3213 100644 --- a/tbdiff/tbdiff-common.h +++ b/tbdiff/tbdiff-common.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 Codethink Ltd. + * Copyright (C) 2011-2014 Codethink Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as @@ -55,31 +55,31 @@ typedef enum { } tbd_metadata_type_e; typedef enum { - TBD_ERROR_SUCCESS = 0, - TBD_ERROR_FAILURE = -1, - TBD_ERROR_OUT_OF_MEMORY = -2, - TBD_ERROR_NULL_POINTER = -3, - TBD_ERROR_INVALID_PARAMETER = -4, - TBD_ERROR_UNABLE_TO_READ_STREAM = -5, - TBD_ERROR_UNABLE_TO_WRITE_STREAM = -6, - TBD_ERROR_UNABLE_TO_CREATE_DIR = -7, - TBD_ERROR_UNABLE_TO_CHANGE_DIR = -8, - TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING = -9, - TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_WRITING = -10, - TBD_ERROR_FILE_ALREADY_EXISTS = -11, - TBD_ERROR_UNABLE_TO_REMOVE_FILE = -12, - TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM = -13, - TBD_ERROR_FEATURE_NOT_IMPLEMENTED = -14, - TBD_ERROR_FILE_DOES_NOT_EXIST = -15, + TBD_ERROR_SUCCESS = 0, + TBD_ERROR_FAILURE = -1, + TBD_ERROR_OUT_OF_MEMORY = -2, + TBD_ERROR_NULL_POINTER = -3, + TBD_ERROR_INVALID_PARAMETER = -4, + TBD_ERROR_UNABLE_TO_READ_STREAM = -5, + TBD_ERROR_UNABLE_TO_WRITE_STREAM = -6, + TBD_ERROR_UNABLE_TO_CREATE_DIR = -7, + TBD_ERROR_UNABLE_TO_CHANGE_DIR = -8, + TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING = -9, + TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_WRITING = -10, + TBD_ERROR_FILE_ALREADY_EXISTS = -11, + TBD_ERROR_UNABLE_TO_REMOVE_FILE = -12, + TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM = -13, + TBD_ERROR_FEATURE_NOT_IMPLEMENTED = -14, + TBD_ERROR_FILE_DOES_NOT_EXIST = -15, TBD_ERROR_UNABLE_TO_DETECT_STREAM_POSITION = -16, - TBD_ERROR_UNABLE_TO_STAT_FILE = -17, - TBD_ERROR_UNABLE_TO_READ_SYMLINK = -18, - TBD_ERROR_UNABLE_TO_CREATE_SYMLINK = -19, - TBD_ERROR_UNABLE_TO_READ_SPECIAL_FILE = -20, - TBD_ERROR_UNABLE_TO_CREATE_SPECIAL_FILE = -21, - TBD_ERROR_UNABLE_TO_CREATE_SOCKET_FILE = -22, - TBD_ERROR_XATTRS_NOT_SUPPORTED = -23, - TBD_ERROR_XATTRS_MISSING_ATTR = -24, + TBD_ERROR_UNABLE_TO_STAT_FILE = -17, + TBD_ERROR_UNABLE_TO_READ_SYMLINK = -18, + TBD_ERROR_UNABLE_TO_CREATE_SYMLINK = -19, + TBD_ERROR_UNABLE_TO_READ_SPECIAL_FILE = -20, + TBD_ERROR_UNABLE_TO_CREATE_SPECIAL_FILE = -21, + TBD_ERROR_UNABLE_TO_CREATE_SOCKET_FILE = -22, + TBD_ERROR_XATTRS_NOT_SUPPORTED = -23, + TBD_ERROR_XATTRS_MISSING_ATTR = -24, } tbd_error_e; #ifdef NDEBUG @@ -97,7 +97,7 @@ tbd_error(tbd_error_e e, char const *s, char const *func, int line, } #endif -extern int tbd_apply (FILE *stream); -extern int tbd_create(FILE *stream, tbd_stat_t *a, tbd_stat_t *b); +extern int tbd_apply (FILE *stream); +extern int tbd_create(FILE *stream, tbd_stat_t *a, tbd_stat_t *b); #endif /* !__TBDIFF_COMMON_H__ */ -- cgit v1.2.1 From 9bb191462e637bc97b6bcbcfe798cc254ba7a7e4 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 11:44:45 +0100 Subject: Create tbd_cmd_t type to for commands and use sizeof in write Previously commands were just treated as a uint8_t and given the value of and enum. This is now made more clear in the code by defining tbd_cmd_t as a uint8_t below the enum in tbdiff-common.h. --- tbdiff/tbdiff-apply.c | 8 ++++---- tbdiff/tbdiff-common.h | 2 ++ tbdiff/tbdiff-create.c | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index ba2e5fc..07a9961 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -93,8 +93,8 @@ tbd_apply_fread_block(FILE *stream, void **data, size_t *size) static int tbd_apply_identify(FILE *stream) { - uint8_t cmd; - if(fread(&cmd, 1, 1, stream) != 1) + tbd_cmd_t cmd; + if(fread(&cmd, sizeof(tbd_cmd_t), 1, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); if(cmd != TBD_CMD_IDENTIFY) return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); @@ -712,8 +712,8 @@ tbd_apply(FILE *stream) uintptr_t depth = 0; bool flush = false; while(!flush) { - uint8_t cmd; - if(fread(&cmd, 1, 1, stream) != 1) + tbd_cmd_t cmd; + if(fread(&cmd, sizeof(tbd_cmd_t), 1, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); switch(cmd) { case TBD_CMD_DIR_CREATE: diff --git a/tbdiff/tbdiff-common.h b/tbdiff/tbdiff-common.h index 06b3213..9e7fcd7 100644 --- a/tbdiff/tbdiff-common.h +++ b/tbdiff/tbdiff-common.h @@ -45,6 +45,8 @@ typedef enum { TBD_CMD_XATTRS_UPDATE = 0x60, } tbd_cmd_e; +typedef uint8_t tbd_cmd_t; + typedef enum { TBD_METADATA_NONE = 0x0, TBD_METADATA_MTIME = 0x1, diff --git a/tbdiff/tbdiff-create.c b/tbdiff/tbdiff-create.c index 21738a5..873f6ee 100644 --- a/tbdiff/tbdiff-create.c +++ b/tbdiff/tbdiff-create.c @@ -33,10 +33,10 @@ #define PATH_BUFFER_LENGTH 4096 static int -tbd_create_fwrite_cmd(FILE *stream, - uint8_t cmd) +tbd_create_fwrite_cmd(FILE *stream, + tbd_cmd_t cmd) { - if(fwrite(&cmd, 1, 1, stream) != 1) + if(fwrite(&cmd, sizeof(tbd_cmd_t), 1, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } -- cgit v1.2.1 From ab5dbf22791338239c72c8e9a0a1ae4dd5523e1b Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 12:02:38 +0100 Subject: Use correct pointer type for parent member in tbd_stat_t The parent pointer in tbd_stat_t was void since it pointed to itself, to make the code more clear I've typedef'd the struct above so that the pointer can now point to itself as an incomplete type. --- tbdiff/tbdiff-stat.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tbdiff/tbdiff-stat.h b/tbdiff/tbdiff-stat.h index 85d7e1b..22da466 100644 --- a/tbdiff/tbdiff-stat.h +++ b/tbdiff/tbdiff-stat.h @@ -37,8 +37,10 @@ typedef enum { TBD_STAT_TYPE_SOCKET = 's' } tbd_stat_type_e; -typedef struct { - void* parent; +typedef struct tbd_stat_s tbd_stat_t; + +struct tbd_stat_s { + tbd_stat_t* parent; char* name; tbd_stat_type_e type; time_t mtime; @@ -47,7 +49,7 @@ typedef struct { gid_t gid; mode_t mode; uint32_t rdev; -} tbd_stat_t; +}; extern tbd_stat_t* tbd_stat(const char *path); extern void tbd_stat_free(tbd_stat_t *file); -- cgit v1.2.1 From 83990c46886eaecd3b6ad3c4ebbc67757514f8ee Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 15:54:44 +0100 Subject: Make TB_DIFF_PROTOCOL_ID a static const char for type safety --- tbdiff/tbdiff-private.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tbdiff/tbdiff-private.h b/tbdiff/tbdiff-private.h index 8287670..296dbcb 100644 --- a/tbdiff/tbdiff-private.h +++ b/tbdiff/tbdiff-private.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 Codethink Ltd. + * Copyright (C) 2011-2014 Codethink Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as @@ -22,6 +22,6 @@ #ifndef __TBDIFF_PRIVATE_H__ #define __TBDIFF_PRIVATE_H__ -#define TB_DIFF_PROTOCOL_ID "Codethink:TBDIFFv0" +static const char* TB_DIFF_PROTOCOL_ID = "Codethink:TBDIFFv0"; #endif /* !__TBDIFF_PRIVATE_H__ */ -- cgit v1.2.1 From d1173fe9e53269a3e07499f3299019e464ab5774 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 16:26:35 +0100 Subject: Simplify endian swapping in tbdiff-io.c Simplify the endian swapping by always calling the endian macro and only implementing it when the platform is big-endain. The endian swapping function has also been made a little more obvious and now uses a byteswap inline function to swap the bytes. --- tbdiff/tbdiff-io.c | 116 +++++++++++++++++++++++------------------------------ 1 file changed, 51 insertions(+), 65 deletions(-) diff --git a/tbdiff/tbdiff-io.c b/tbdiff/tbdiff-io.c index c386a38..db3b437 100644 --- a/tbdiff/tbdiff-io.c +++ b/tbdiff/tbdiff-io.c @@ -21,100 +21,96 @@ #include +#if __STDC_VERSION__ >= 199901L +#define RESTRICT restrict +#elif defined(__GNUC__) +#define RESTRICT __restrict__ +#else +#define RESTRICT +#endif + #if __BYTE_ORDER == __BIG_ENDIAN +static inline void byteswap(char *RESTRICT a, char *RESTRICT b) +{ + char swap = *a; + *a = *b; + *b = swap; +} + /*inverts the indices of an array of bytes. */ -static void byteswap(char* value, int size) { - char tmp; - int i; - for (i = 0; i < size/2; i++) { - tmp = value[i]; - value[i] = value[size-i-1]; - value[size-i-1] = tmp; - } +static inline void endianswap(void* value, size_t size) +{ + + char* cvalue = value; + int i, j; + for (i = 0, j = (size - 1); i < (size / 2); i++, j--) + byteswap(&cvalue[i], &cvalue[j]); } -#endif -size_t tbd_write_uint16_t(uint16_t value, FILE* stream) { -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); +#define ENDIANSWAP(v) endianswap(v, sizeof(*v)) +#else +#define ENDIANSWAP(v) #endif + +size_t tbd_write_uint16_t(uint16_t value, FILE *stream) { + ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_uint32_t(uint32_t value, FILE* stream) { -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); -#endif +size_t tbd_write_uint32_t(uint32_t value, FILE *stream) { + ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_uint64_t(uint64_t value, FILE* stream) { -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); -#endif +size_t tbd_write_uint64_t(uint64_t value, FILE *stream) { + ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_time_t(time_t value, FILE* stream) { +size_t tbd_write_time_t(time_t value, FILE *stream) { uint64_t realv = value; -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&realv, sizeof(realv)); -#endif + ENDIANSWAP(&realv); return fwrite(&realv, sizeof(realv), 1, stream); } -size_t tbd_write_mode_t(mode_t value, FILE* stream) { -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); -#endif +size_t tbd_write_mode_t(mode_t value, FILE *stream) { + ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_uid_t(uid_t value, FILE* stream) { -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); -#endif +size_t tbd_write_uid_t(uid_t value, FILE *stream) { + ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_gid_t(gid_t value, FILE* stream) { -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); -#endif +size_t tbd_write_gid_t(gid_t value, FILE *stream) { + ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_size_t(size_t value, FILE* stream) { -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&value, sizeof(value)); -#endif +size_t tbd_write_size_t(size_t value, FILE *stream) { + ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_read_uint16_t(uint16_t *value, FILE* stream) { +size_t tbd_read_uint16_t(uint16_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); -#endif + ENDIANSWAP(value); return rval; } size_t tbd_read_uint32_t(uint32_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); -#endif + ENDIANSWAP(value); return rval; } size_t tbd_read_uint64_t(uint64_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); -#endif + ENDIANSWAP(value); return rval; } @@ -122,9 +118,7 @@ size_t tbd_read_time_t(time_t *value, FILE *stream) { assert(value != NULL); uint64_t realv; size_t rval = fread(&realv, sizeof(realv), 1, stream); -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)&realv, sizeof(realv)); -#endif + ENDIANSWAP(&realv); *value = realv; return rval; } @@ -132,35 +126,27 @@ size_t tbd_read_time_t(time_t *value, FILE *stream) { size_t tbd_read_mode_t(mode_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); -#endif + ENDIANSWAP(value); return rval; } size_t tbd_read_uid_t(uid_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); -#endif + ENDIANSWAP(value); return rval; } size_t tbd_read_gid_t(gid_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); -#endif + ENDIANSWAP(value); return rval; } size_t tbd_read_size_t(size_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); -#if __BYTE_ORDER == __BIG_ENDIAN - byteswap((char*)value, sizeof(*value)); -#endif + ENDIANSWAP(value); return rval; } -- cgit v1.2.1 From 120e5ad8b73585df0ef0c59164e5fa2f545515f3 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 16:43:43 +0100 Subject: Add externs to functions in tbdiff-io.h and cleanup The externs are not required but it's inkeeping with the other headers which all currently have them. --- tbdiff/tbdiff-io.h | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/tbdiff/tbdiff-io.h b/tbdiff/tbdiff-io.h index 73e7711..0e2e7e9 100644 --- a/tbdiff/tbdiff-io.h +++ b/tbdiff/tbdiff-io.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 Codethink Ltd. + * Copyright (C) 2011-2014 Codethink Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as @@ -28,36 +28,22 @@ #include -size_t tbd_write_uint16_t (uint16_t value, FILE* stream); - -size_t tbd_write_uint32_t (uint32_t value, FILE* stream); - -size_t tbd_write_uint64_t (uint64_t value, FILE* stream); - -size_t tbd_write_time_t (time_t value, FILE* stream); - -size_t tbd_write_mode_t (mode_t value, FILE* stream); - -size_t tbd_write_uid_t (uid_t value, FILE* stream); - -size_t tbd_write_gid_t (gid_t value, FILE* stream); - -size_t tbd_write_size_t (size_t value, FILE* stream); - -size_t tbd_read_uint16_t (uint16_t *value, FILE* stream); - -size_t tbd_read_uint32_t (uint32_t *value, FILE* stream); - -size_t tbd_read_uint64_t (uint64_t *value, FILE* stream); - -size_t tbd_read_time_t (time_t *value, FILE* stream); - -size_t tbd_read_mode_t (mode_t *value, FILE* stream); - -size_t tbd_read_uid_t (uid_t *value, FILE* stream); - -size_t tbd_read_gid_t (gid_t *value, FILE* stream); - -size_t tbd_read_size_t (size_t *value, FILE* stream); +extern size_t tbd_write_uint16_t(uint16_t value, FILE* stream); +extern size_t tbd_write_uint32_t(uint32_t value, FILE* stream); +extern size_t tbd_write_uint64_t(uint64_t value, FILE* stream); +extern size_t tbd_write_time_t(time_t value, FILE* stream); +extern size_t tbd_write_mode_t(mode_t value, FILE* stream); +extern size_t tbd_write_uid_t(uid_t value, FILE* stream); +extern size_t tbd_write_gid_t(gid_t value, FILE* stream); +extern size_t tbd_write_size_t(size_t value, FILE* stream); + +extern size_t tbd_read_uint16_t(uint16_t *value, FILE* stream); +extern size_t tbd_read_uint32_t(uint32_t *value, FILE* stream); +extern size_t tbd_read_uint64_t(uint64_t *value, FILE* stream); +extern size_t tbd_read_time_t(time_t *value, FILE* stream); +extern size_t tbd_read_mode_t(mode_t *value, FILE* stream); +extern size_t tbd_read_uid_t(uid_t *value, FILE* stream); +extern size_t tbd_read_gid_t(gid_t *value, FILE* stream); +extern size_t tbd_read_size_t(size_t *value, FILE* stream); #endif /* !__TBDIFF_IO_H__ */ -- cgit v1.2.1 From 8e85b1b2001f8d747a41e41f616d20d84bf65acc Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 17:09:15 +0100 Subject: style: Cleanup the names of the tbd read/write wrappers --- tbdiff/tbdiff-apply.c | 92 +++++++++++++++++++++++++------------------------- tbdiff/tbdiff-create.c | 24 ++++++------- tbdiff/tbdiff-io.c | 32 +++++++++--------- tbdiff/tbdiff-io.h | 32 +++++++++--------- 4 files changed, 90 insertions(+), 90 deletions(-) diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index 07a9961..754df5e 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -46,7 +46,7 @@ char* tbd_apply_fread_string(FILE *stream) { uint16_t dlen; - if(tbd_read_uint16_t(&dlen, stream) != 1) + if(tbd_read_uint16(&dlen, stream) != 1) return NULL; char dname[dlen + 1]; if(fread(dname, 1, dlen, stream) != dlen) @@ -99,7 +99,7 @@ tbd_apply_identify(FILE *stream) if(cmd != TBD_CMD_IDENTIFY) return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); uint16_t nlen; - if(tbd_read_uint16_t(&nlen, stream) != 1) + if(tbd_read_uint16(&nlen, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); if(strlen(TB_DIFF_PROTOCOL_ID) != nlen) return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); @@ -115,7 +115,7 @@ static int tbd_apply_cmd_dir_create(FILE *stream) { uint16_t dlen; - if(tbd_read_uint16_t(&dlen, stream) != 1) + if(tbd_read_uint16(&dlen, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char dname[dlen + 1]; if(fread(dname, 1, dlen, stream) != dlen) @@ -126,19 +126,19 @@ tbd_apply_cmd_dir_create(FILE *stream) return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); time_t mtime; - if(tbd_read_time_t(&mtime, stream) != 1) + if(tbd_read_time(&mtime, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); uid_t uid; - if(tbd_read_uid_t(&uid, stream) != 1) + if(tbd_read_uid(&uid, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); gid_t gid; - if(tbd_read_gid_t(&gid, stream) != 1) + if(tbd_read_gid(&gid, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); mode_t mode; - if(tbd_read_mode_t(&mode, stream) != 1) + if(tbd_read_mode(&mode, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); if(mkdir(dname, (mode_t)mode) != 0) @@ -159,7 +159,7 @@ tbd_apply_cmd_dir_enter(FILE *stream, uintptr_t *depth) { uint16_t dlen; - if(tbd_read_uint16_t(&dlen, stream) != 1) + if(tbd_read_uint16(&dlen, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char dname[dlen + 1]; if(fread(dname, 1, dlen, stream) != dlen) @@ -183,7 +183,7 @@ tbd_apply_cmd_dir_leave(FILE *stream, int err = TBD_ERROR_SUCCESS; struct utimbuf time; - if (tbd_read_time_t(&(time.modtime), stream) != 1) { + if (tbd_read_time(&(time.modtime), stream) != 1) { return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } time.actime = time.modtime;/* not sure what the best atime to use is */ @@ -214,7 +214,7 @@ static int tbd_apply_cmd_file_create(FILE *stream) { uint16_t flen; - if(tbd_read_uint16_t(&flen, stream) != 1) + if(tbd_read_uint16(&flen, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char fname[flen + 1]; if(fread(fname, 1, flen, stream) != flen) @@ -229,11 +229,11 @@ tbd_apply_cmd_file_create(FILE *stream) gid_t gid; uint32_t fsize; - if(tbd_read_time_t (&mtime, stream) != 1 || - tbd_read_uint32_t(&mode , stream) != 1 || - tbd_read_uid_t (&uid , stream) != 1 || - tbd_read_gid_t (&gid , stream) != 1 || - tbd_read_uint32_t(&fsize, stream) != 1) + if(tbd_read_time (&mtime, stream) != 1 || + tbd_read_uint32(&mode , stream) != 1 || + tbd_read_uid (&uid , stream) != 1 || + tbd_read_gid (&gid , stream) != 1 || + tbd_read_uint32(&fsize, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); fprintf(stderr, "cmd_file_create %s:%"PRId32"\n", fname, fsize); @@ -287,7 +287,7 @@ tbd_apply_cmd_file_delta(FILE *stream) uint16_t flen; int error; - if(tbd_read_uint16_t(&flen, stream) != 1) + if(tbd_read_uint16(&flen, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char fname[flen + 1]; if(fread(fname, 1, flen, stream) != flen) @@ -301,11 +301,11 @@ tbd_apply_cmd_file_delta(FILE *stream) return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); /* Reading metadata */ - if(tbd_read_uint16_t(&mdata_mask, stream) != 1 || - tbd_read_time_t (&mtime , stream) != 1 || - tbd_read_uid_t (&uid , stream) != 1 || - tbd_read_gid_t (&gid , stream) != 1 || - tbd_read_uint32_t(&mode , stream) != 1) + if(tbd_read_uint16(&mdata_mask, stream) != 1 || + tbd_read_time (&mtime , stream) != 1 || + tbd_read_uid (&uid , stream) != 1 || + tbd_read_gid (&gid , stream) != 1 || + tbd_read_uint32(&mode , stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); FILE *op = fopen(fname, "rb"); @@ -322,11 +322,11 @@ tbd_apply_cmd_file_delta(FILE *stream) } uint32_t dstart, dend; - if(tbd_read_uint32_t(&dstart, stream) != 1) { + if(tbd_read_uint32(&dstart, stream) != 1) { error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); goto tbd_apply_cmd_file_delta_error; } - if(tbd_read_uint32_t(&dend, stream) != 1) { + if(tbd_read_uint32(&dend, stream) != 1) { error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); goto tbd_apply_cmd_file_delta_error; } @@ -347,7 +347,7 @@ tbd_apply_cmd_file_delta(FILE *stream) } uint32_t fsize; - if(tbd_read_uint32_t(&fsize, stream) != 1) { + if(tbd_read_uint32(&fsize, stream) != 1) { error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); goto tbd_apply_cmd_file_delta_error; } @@ -478,7 +478,7 @@ static int tbd_apply_cmd_entity_delete(FILE *stream) { uint16_t elen; - if(tbd_read_uint16_t(&elen, stream) != 1) + if(tbd_read_uint16(&elen, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char ename[elen + 1]; if(fread(ename, 1, elen, stream) != elen) @@ -500,13 +500,13 @@ tbd_apply_cmd_symlink_create(FILE *stream) uid_t uid; gid_t gid; - if(tbd_read_time_t(&mtime, stream) != 1 || - tbd_read_uid_t(&uid , stream) != 1 || - tbd_read_gid_t(&gid , stream) != 1) + if(tbd_read_time(&mtime, stream) != 1 || + tbd_read_uid(&uid , stream) != 1 || + tbd_read_gid(&gid , stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); /* Reading link file name */ - if(tbd_read_uint16_t(&len, stream) != 1) + if(tbd_read_uint16(&len, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char linkname[len + 1]; @@ -515,7 +515,7 @@ tbd_apply_cmd_symlink_create(FILE *stream) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); /* Reading target path */ - if(tbd_read_uint16_t(&len, stream) != 1) + if(tbd_read_uint16(&len, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char linkpath[len+1]; linkpath[len] = '\0'; @@ -550,11 +550,11 @@ tbd_apply_cmd_special_create(FILE *stream) uint32_t dev; if(name == NULL || - tbd_read_time_t (&mtime, stream) != 1 || - tbd_read_mode_t (&mode , stream) != 1 || - tbd_read_uid_t (&uid , stream) != 1 || - tbd_read_gid_t (&gid , stream) != 1 || - tbd_read_uint32_t(&dev , stream) != 1) { + tbd_read_time (&mtime, stream) != 1 || + tbd_read_mode (&mode , stream) != 1 || + tbd_read_uid (&uid , stream) != 1 || + tbd_read_gid (&gid , stream) != 1 || + tbd_read_uint32(&dev , stream) != 1) { free(name); return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } @@ -585,11 +585,11 @@ tbd_apply_cmd_dir_delta(FILE *stream) gid_t gid; mode_t mode; - if(tbd_read_uint16_t(&metadata_mask, stream) != 1 || - tbd_read_time_t (&mtime , stream) != 1 || - tbd_read_uid_t (&uid , stream) != 1 || - tbd_read_gid_t (&gid , stream) != 1 || - tbd_read_uint32_t(&mode , stream) != 1) + if(tbd_read_uint16(&metadata_mask, stream) != 1 || + tbd_read_time (&mtime , stream) != 1 || + tbd_read_uid (&uid , stream) != 1 || + tbd_read_gid (&gid , stream) != 1 || + tbd_read_uint32(&mode , stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char *dname = tbd_apply_fread_string(stream); @@ -620,11 +620,11 @@ tbd_apply_cmd_file_mdata_update(FILE *stream) gid_t gid; mode_t mode; - if(tbd_read_uint16_t(&metadata_mask, stream) != 1 || - tbd_read_time_t (&mtime , stream) != 1 || - tbd_read_uid_t (&uid , stream) != 1 || - tbd_read_gid_t (&gid , stream) != 1 || - tbd_read_uint32_t(&mode , stream) != 1) + if(tbd_read_uint16(&metadata_mask, stream) != 1 || + tbd_read_time (&mtime , stream) != 1 || + tbd_read_uid (&uid , stream) != 1 || + tbd_read_gid (&gid , stream) != 1 || + tbd_read_uint32(&mode , stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char *dname = tbd_apply_fread_string(stream); @@ -665,7 +665,7 @@ tbd_apply_cmd_xattrs_update(FILE *stream) } /* read how many attributes to process */ - if (tbd_read_uint32_t(&count, stream) != 1) { + if (tbd_read_uint32(&count, stream) != 1) { err = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); goto cleanup; } diff --git a/tbdiff/tbdiff-create.c b/tbdiff/tbdiff-create.c index 873f6ee..c8a71ff 100644 --- a/tbdiff/tbdiff-create.c +++ b/tbdiff/tbdiff-create.c @@ -46,7 +46,7 @@ tbd_create_fwrite_string(FILE *stream, const char *string) { uint16_t slen = strlen(string); - if((tbd_write_uint16_t(slen, stream) != 1) + if((tbd_write_uint16(slen, stream) != 1) || (fwrite(string, 1, slen, stream) != slen)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; @@ -71,7 +71,7 @@ static int tbd_create_fwrite_mdata_mask(FILE *stream, uint16_t mask) { - if(tbd_write_uint16_t(mask, stream) != 1) + if(tbd_write_uint16(mask, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } @@ -80,7 +80,7 @@ static int tbd_create_fwrite_mtime(FILE *stream, time_t mtime) { - if(tbd_write_time_t(mtime, stream) != 1) + if(tbd_write_time(mtime, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } @@ -89,7 +89,7 @@ static int tbd_create_fwrite_mode(FILE *stream, mode_t mode) { - if(tbd_write_mode_t(mode, stream) != 1) + if(tbd_write_mode(mode, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } @@ -98,7 +98,7 @@ static int tbd_create_fwrite_gid(FILE *stream, gid_t gid) { - if(tbd_write_gid_t(gid, stream) != 1) + if(tbd_write_gid(gid, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } @@ -107,7 +107,7 @@ static int tbd_create_fwrite_uid(FILE *stream, uid_t uid) { - if(tbd_write_uid_t(uid, stream) != 1) + if(tbd_write_uid(uid, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } @@ -116,7 +116,7 @@ static int tbd_create_fwrite_dev(FILE *stream, uint32_t dev) { - if(tbd_write_uint32_t(dev, stream) != 1) + if(tbd_write_uint32(dev, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } @@ -199,7 +199,7 @@ tbd_create_cmd_fwrite_xattrs(FILE *stream, tbd_stat_t *f) goto cleanup_names; } - if (tbd_write_uint32_t(count, stream) != 1) { + if (tbd_write_uint32(count, stream) != 1) { err = TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); goto cleanup_names; } @@ -229,7 +229,7 @@ tbd_create_cmd_file_create(FILE *stream, return err; uint32_t size = f->size; - if(tbd_write_uint32_t(size, stream) != 1) + if(tbd_write_uint32(size, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); FILE *fp = tbd_stat_fopen(f, "rb"); @@ -410,9 +410,9 @@ tbd_create_cmd_file_delta(FILE *stream, fclose(fpb); return err; } - if((tbd_write_uint32_t(start, stream) != 1) || - (tbd_write_uint32_t(end, stream) != 1) || - (tbd_write_uint32_t(size, stream) != 1)) { + if((tbd_write_uint32(start, stream) != 1) || + (tbd_write_uint32(end, stream) != 1) || + (tbd_write_uint32(size, stream) != 1)) { fclose(fpb); return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); } diff --git a/tbdiff/tbdiff-io.c b/tbdiff/tbdiff-io.c index db3b437..d6be7c9 100644 --- a/tbdiff/tbdiff-io.c +++ b/tbdiff/tbdiff-io.c @@ -52,69 +52,69 @@ static inline void endianswap(void* value, size_t size) #define ENDIANSWAP(v) #endif -size_t tbd_write_uint16_t(uint16_t value, FILE *stream) { +size_t tbd_write_uint16(uint16_t value, FILE *stream) { ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_uint32_t(uint32_t value, FILE *stream) { +size_t tbd_write_uint32(uint32_t value, FILE *stream) { ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_uint64_t(uint64_t value, FILE *stream) { +size_t tbd_write_uint64(uint64_t value, FILE *stream) { ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_time_t(time_t value, FILE *stream) { +size_t tbd_write_time(time_t value, FILE *stream) { uint64_t realv = value; ENDIANSWAP(&realv); return fwrite(&realv, sizeof(realv), 1, stream); } -size_t tbd_write_mode_t(mode_t value, FILE *stream) { +size_t tbd_write_mode(mode_t value, FILE *stream) { ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_uid_t(uid_t value, FILE *stream) { +size_t tbd_write_uid(uid_t value, FILE *stream) { ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_gid_t(gid_t value, FILE *stream) { +size_t tbd_write_gid(gid_t value, FILE *stream) { ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_size_t(size_t value, FILE *stream) { +size_t tbd_write_size(size_t value, FILE *stream) { ENDIANSWAP(&value); return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_read_uint16_t(uint16_t *value, FILE *stream) { +size_t tbd_read_uint16(uint16_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); ENDIANSWAP(value); return rval; } -size_t tbd_read_uint32_t(uint32_t *value, FILE *stream) { +size_t tbd_read_uint32(uint32_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); ENDIANSWAP(value); return rval; } -size_t tbd_read_uint64_t(uint64_t *value, FILE *stream) { +size_t tbd_read_uint64(uint64_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); ENDIANSWAP(value); return rval; } -size_t tbd_read_time_t(time_t *value, FILE *stream) { +size_t tbd_read_time(time_t *value, FILE *stream) { assert(value != NULL); uint64_t realv; size_t rval = fread(&realv, sizeof(realv), 1, stream); @@ -123,28 +123,28 @@ size_t tbd_read_time_t(time_t *value, FILE *stream) { return rval; } -size_t tbd_read_mode_t(mode_t *value, FILE *stream) { +size_t tbd_read_mode(mode_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); ENDIANSWAP(value); return rval; } -size_t tbd_read_uid_t(uid_t *value, FILE *stream) { +size_t tbd_read_uid(uid_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); ENDIANSWAP(value); return rval; } -size_t tbd_read_gid_t(gid_t *value, FILE *stream) { +size_t tbd_read_gid(gid_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); ENDIANSWAP(value); return rval; } -size_t tbd_read_size_t(size_t *value, FILE *stream) { +size_t tbd_read_size(size_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); ENDIANSWAP(value); diff --git a/tbdiff/tbdiff-io.h b/tbdiff/tbdiff-io.h index 0e2e7e9..16601fb 100644 --- a/tbdiff/tbdiff-io.h +++ b/tbdiff/tbdiff-io.h @@ -28,22 +28,22 @@ #include -extern size_t tbd_write_uint16_t(uint16_t value, FILE* stream); -extern size_t tbd_write_uint32_t(uint32_t value, FILE* stream); -extern size_t tbd_write_uint64_t(uint64_t value, FILE* stream); -extern size_t tbd_write_time_t(time_t value, FILE* stream); -extern size_t tbd_write_mode_t(mode_t value, FILE* stream); -extern size_t tbd_write_uid_t(uid_t value, FILE* stream); -extern size_t tbd_write_gid_t(gid_t value, FILE* stream); -extern size_t tbd_write_size_t(size_t value, FILE* stream); +extern size_t tbd_write_uint16(uint16_t value, FILE* stream); +extern size_t tbd_write_uint32(uint32_t value, FILE* stream); +extern size_t tbd_write_uint64(uint64_t value, FILE* stream); +extern size_t tbd_write_time(time_t value, FILE* stream); +extern size_t tbd_write_mode(mode_t value, FILE* stream); +extern size_t tbd_write_uid(uid_t value, FILE* stream); +extern size_t tbd_write_gid(gid_t value, FILE* stream); +extern size_t tbd_write_size(size_t value, FILE* stream); -extern size_t tbd_read_uint16_t(uint16_t *value, FILE* stream); -extern size_t tbd_read_uint32_t(uint32_t *value, FILE* stream); -extern size_t tbd_read_uint64_t(uint64_t *value, FILE* stream); -extern size_t tbd_read_time_t(time_t *value, FILE* stream); -extern size_t tbd_read_mode_t(mode_t *value, FILE* stream); -extern size_t tbd_read_uid_t(uid_t *value, FILE* stream); -extern size_t tbd_read_gid_t(gid_t *value, FILE* stream); -extern size_t tbd_read_size_t(size_t *value, FILE* stream); +extern size_t tbd_read_uint16(uint16_t *value, FILE* stream); +extern size_t tbd_read_uint32(uint32_t *value, FILE* stream); +extern size_t tbd_read_uint64(uint64_t *value, FILE* stream); +extern size_t tbd_read_time(time_t *value, FILE* stream); +extern size_t tbd_read_mode(mode_t *value, FILE* stream); +extern size_t tbd_read_uid(uid_t *value, FILE* stream); +extern size_t tbd_read_gid(gid_t *value, FILE* stream); +extern size_t tbd_read_size(size_t *value, FILE* stream); #endif /* !__TBDIFF_IO_H__ */ -- cgit v1.2.1 From d806ee54230c46d1708a19598833ac47fbf341a9 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 17:21:04 +0100 Subject: Remove read/write_size from tbdiff-io since they're unused Also removed because size_t can vary in size across platforms, which makes it unsuitable for storing in our diff stream. --- tbdiff/tbdiff-io.c | 12 ------------ tbdiff/tbdiff-io.h | 2 -- 2 files changed, 14 deletions(-) diff --git a/tbdiff/tbdiff-io.c b/tbdiff/tbdiff-io.c index d6be7c9..c33364b 100644 --- a/tbdiff/tbdiff-io.c +++ b/tbdiff/tbdiff-io.c @@ -88,11 +88,6 @@ size_t tbd_write_gid(gid_t value, FILE *stream) { return fwrite(&value, sizeof(value), 1, stream); } -size_t tbd_write_size(size_t value, FILE *stream) { - ENDIANSWAP(&value); - return fwrite(&value, sizeof(value), 1, stream); -} - size_t tbd_read_uint16(uint16_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); @@ -143,10 +138,3 @@ size_t tbd_read_gid(gid_t *value, FILE *stream) { ENDIANSWAP(value); return rval; } - -size_t tbd_read_size(size_t *value, FILE *stream) { - assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); - ENDIANSWAP(value); - return rval; -} diff --git a/tbdiff/tbdiff-io.h b/tbdiff/tbdiff-io.h index 16601fb..585f670 100644 --- a/tbdiff/tbdiff-io.h +++ b/tbdiff/tbdiff-io.h @@ -35,7 +35,6 @@ extern size_t tbd_write_time(time_t value, FILE* stream); extern size_t tbd_write_mode(mode_t value, FILE* stream); extern size_t tbd_write_uid(uid_t value, FILE* stream); extern size_t tbd_write_gid(gid_t value, FILE* stream); -extern size_t tbd_write_size(size_t value, FILE* stream); extern size_t tbd_read_uint16(uint16_t *value, FILE* stream); extern size_t tbd_read_uint32(uint32_t *value, FILE* stream); @@ -44,6 +43,5 @@ extern size_t tbd_read_time(time_t *value, FILE* stream); extern size_t tbd_read_mode(mode_t *value, FILE* stream); extern size_t tbd_read_uid(uid_t *value, FILE* stream); extern size_t tbd_read_gid(gid_t *value, FILE* stream); -extern size_t tbd_read_size(size_t *value, FILE* stream); #endif /* !__TBDIFF_IO_H__ */ -- cgit v1.2.1 From 1a8cdd49a574dc947bca54fc7ee734c5525475c0 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 17:36:26 +0100 Subject: style: Rename fread/fwrite in function names to read and write The implementation currently uses fread and fwrite which are specific functions in stdlib, however this is an implementation detail and in the future these functions may not be used, so it doesn't make sense to name the higher level functions based on the function they use underneath. --- tbdiff/tbdiff-apply.c | 16 ++--- tbdiff/tbdiff-create.c | 156 ++++++++++++++++++++++++------------------------- 2 files changed, 86 insertions(+), 86 deletions(-) diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index 754df5e..0a1fe7c 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -43,7 +43,7 @@ #include char* -tbd_apply_fread_string(FILE *stream) +tbd_apply_read_string(FILE *stream) { uint16_t dlen; if(tbd_read_uint16(&dlen, stream) != 1) @@ -67,7 +67,7 @@ tbd_apply_fread_string(FILE *stream) * - or your allocator does nothing when asked to free non-allocated memory */ int -tbd_apply_fread_block(FILE *stream, void **data, size_t *size) +tbd_apply_read_block(FILE *stream, void **data, size_t *size) { { size_t _size; @@ -542,7 +542,7 @@ tbd_apply_cmd_symlink_create(FILE *stream) static int tbd_apply_cmd_special_create(FILE *stream) { - char *name = tbd_apply_fread_string(stream); + char *name = tbd_apply_read_string(stream); time_t mtime; mode_t mode; uid_t uid; @@ -592,7 +592,7 @@ tbd_apply_cmd_dir_delta(FILE *stream) tbd_read_uint32(&mode , stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); - char *dname = tbd_apply_fread_string(stream); + char *dname = tbd_apply_read_string(stream); if(dname == NULL) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); @@ -627,7 +627,7 @@ tbd_apply_cmd_file_mdata_update(FILE *stream) tbd_read_uint32(&mode , stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); - char *dname = tbd_apply_fread_string(stream); + char *dname = tbd_apply_read_string(stream); if(dname == NULL) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); @@ -655,7 +655,7 @@ tbd_apply_cmd_xattrs_update(FILE *stream) void *data = NULL; size_t dsize = 0; /* read the name of the file to operate on */ - if ((fname = tbd_apply_fread_string(stream)) == NULL) { + if ((fname = tbd_apply_read_string(stream)) == NULL) { return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } @@ -672,14 +672,14 @@ tbd_apply_cmd_xattrs_update(FILE *stream) /* operate on each attribute */ while (count > 0) { - char *aname = tbd_apply_fread_string(stream); + char *aname = tbd_apply_read_string(stream); if (aname == NULL) { err=TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); goto cleanup; } /* read a block of data, reallocating if needed */ - if ((err = tbd_apply_fread_block(stream, &data, &dsize)) + if ((err = tbd_apply_read_block(stream, &data, &dsize)) != TBD_ERROR_SUCCESS) { free(aname); goto cleanup; diff --git a/tbdiff/tbdiff-create.c b/tbdiff/tbdiff-create.c index c8a71ff..d855387 100644 --- a/tbdiff/tbdiff-create.c +++ b/tbdiff/tbdiff-create.c @@ -33,8 +33,8 @@ #define PATH_BUFFER_LENGTH 4096 static int -tbd_create_fwrite_cmd(FILE *stream, - tbd_cmd_t cmd) +tbd_create_write_cmd(FILE *stream, + tbd_cmd_t cmd) { if(fwrite(&cmd, sizeof(tbd_cmd_t), 1, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -42,8 +42,8 @@ tbd_create_fwrite_cmd(FILE *stream, } static int -tbd_create_fwrite_string(FILE *stream, - const char *string) +tbd_create_write_string(FILE *stream, + const char *string) { uint16_t slen = strlen(string); if((tbd_write_uint16(slen, stream) != 1) @@ -53,9 +53,9 @@ tbd_create_fwrite_string(FILE *stream, } static int -tbd_create_fwrite_block(FILE *stream, - void const *data, - size_t size) +tbd_create_write_block(FILE *stream, + void const *data, + size_t size) { if (fwrite(&size, 1, sizeof(size), stream) != sizeof(size)) { return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -68,8 +68,8 @@ tbd_create_fwrite_block(FILE *stream, } static int -tbd_create_fwrite_mdata_mask(FILE *stream, - uint16_t mask) +tbd_create_write_mdata_mask(FILE *stream, + uint16_t mask) { if(tbd_write_uint16(mask, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -77,8 +77,8 @@ tbd_create_fwrite_mdata_mask(FILE *stream, } static int -tbd_create_fwrite_mtime(FILE *stream, - time_t mtime) +tbd_create_write_mtime(FILE *stream, + time_t mtime) { if(tbd_write_time(mtime, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -86,8 +86,8 @@ tbd_create_fwrite_mtime(FILE *stream, } static int -tbd_create_fwrite_mode(FILE *stream, - mode_t mode) +tbd_create_write_mode(FILE *stream, + mode_t mode) { if(tbd_write_mode(mode, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -95,8 +95,8 @@ tbd_create_fwrite_mode(FILE *stream, } static int -tbd_create_fwrite_gid(FILE *stream, - gid_t gid) +tbd_create_write_gid(FILE *stream, + gid_t gid) { if(tbd_write_gid(gid, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -104,8 +104,8 @@ tbd_create_fwrite_gid(FILE *stream, } static int -tbd_create_fwrite_uid(FILE *stream, - uid_t uid) +tbd_create_write_uid(FILE *stream, + uid_t uid) { if(tbd_write_uid(uid, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -113,8 +113,8 @@ tbd_create_fwrite_uid(FILE *stream, } static int -tbd_create_fwrite_dev(FILE *stream, - uint32_t dev) +tbd_create_write_dev(FILE *stream, + uint32_t dev) { if(tbd_write_uint32(dev, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); @@ -126,9 +126,9 @@ tbd_create_cmd_ident(FILE *stream) { int err; - if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_IDENTIFY)) != 0) + if((err = tbd_create_write_cmd(stream, TBD_CMD_IDENTIFY)) != 0) return err; - if((err = tbd_create_fwrite_string(stream, TB_DIFF_PROTOCOL_ID)) != 0) + if((err = tbd_create_write_string(stream, TB_DIFF_PROTOCOL_ID)) != 0) return err; return 0; } @@ -136,7 +136,7 @@ tbd_create_cmd_ident(FILE *stream) static int tbd_create_cmd_update(FILE *stream) { - return tbd_create_fwrite_cmd(stream, TBD_CMD_UPDATE); + return tbd_create_write_cmd(stream, TBD_CMD_UPDATE); } /* callback function to pass to tbx_xattrs_pairs @@ -148,12 +148,12 @@ _write_pair(char const *name, void const *data, size_t size, void *ud) FILE *stream = ud; int err; - if ((err = tbd_create_fwrite_string(stream, name)) != + if ((err = tbd_create_write_string(stream, name)) != TBD_ERROR_SUCCESS) { return err; } - if ((err = tbd_create_fwrite_block(stream, data, size)) != + if ((err = tbd_create_write_block(stream, data, size)) != TBD_ERROR_SUCCESS) { return err; } @@ -188,13 +188,13 @@ tbd_create_cmd_fwrite_xattrs(FILE *stream, tbd_stat_t *f) goto cleanup_names; } - if ((err = tbd_create_fwrite_cmd(stream, + if ((err = tbd_create_write_cmd(stream, TBD_CMD_XATTRS_UPDATE) ) != TBD_ERROR_SUCCESS) { goto cleanup_names; } - if ((err = tbd_create_fwrite_string(stream, f->name))!= + if ((err = tbd_create_write_string(stream, f->name))!= TBD_ERROR_SUCCESS) { goto cleanup_names; } @@ -220,12 +220,12 @@ tbd_create_cmd_file_create(FILE *stream, tbd_stat_t *f) { int err; - if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_FILE_CREATE)) != 0 || - (err = tbd_create_fwrite_string(stream, f->name)) != 0 || - (err = tbd_create_fwrite_mtime (stream, f->mtime)) != 0 || - (err = tbd_create_fwrite_mode (stream, f->mode)) != 0 || - (err = tbd_create_fwrite_uid (stream, f->uid)) != 0 || - (err = tbd_create_fwrite_gid (stream, f->gid)) != 0) + if((err = tbd_create_write_cmd(stream, TBD_CMD_FILE_CREATE)) != 0 || + (err = tbd_create_write_string(stream, f->name)) != 0 || + (err = tbd_create_write_mtime (stream, f->mtime)) != 0 || + (err = tbd_create_write_mode (stream, f->mode)) != 0 || + (err = tbd_create_write_uid (stream, f->uid)) != 0 || + (err = tbd_create_write_gid (stream, f->gid)) != 0) return err; uint32_t size = f->size; @@ -280,15 +280,15 @@ tbd_create_cmd_file_metadata_update(FILE *stream, if(metadata_mask == TBD_METADATA_NONE) return 0; /* TODO: Optimize protocol by only sending useful metadata */ - if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_FILE_METADATA_UPDATE)) != 0 || - (err = tbd_create_fwrite_mdata_mask(stream, metadata_mask)) != 0 || - (err = tbd_create_fwrite_mtime (stream, b->mtime)) != 0 || - (err = tbd_create_fwrite_uid (stream, b->uid)) != 0 || - (err = tbd_create_fwrite_gid (stream, b->gid)) != 0 || - (err = tbd_create_fwrite_mode (stream, b->mode)) != 0) + if((err = tbd_create_write_cmd(stream, TBD_CMD_FILE_METADATA_UPDATE)) != 0 || + (err = tbd_create_write_mdata_mask(stream, metadata_mask)) != 0 || + (err = tbd_create_write_mtime (stream, b->mtime)) != 0 || + (err = tbd_create_write_uid (stream, b->uid)) != 0 || + (err = tbd_create_write_gid (stream, b->gid)) != 0 || + (err = tbd_create_write_mode (stream, b->mode)) != 0) return err; - return tbd_create_fwrite_string(stream, b->name); + return tbd_create_write_string(stream, b->name); } static int @@ -400,13 +400,13 @@ tbd_create_cmd_file_delta(FILE *stream, /* TODO: Optimize protocol by only sending useful metadata */ int err; - if(((err = tbd_create_fwrite_cmd(stream, TBD_CMD_FILE_DELTA)) != 0) || - ((err = tbd_create_fwrite_string(stream, b->name)) != 0) || - ((err = tbd_create_fwrite_mdata_mask(stream, metadata_mask)) != 0) || - ((err = tbd_create_fwrite_mtime (stream, b->mtime)) != 0) || - ((err = tbd_create_fwrite_uid (stream, b->uid)) != 0) || - ((err = tbd_create_fwrite_gid (stream, b->gid)) != 0) || - ((err = tbd_create_fwrite_mode (stream, b->mode)) != 0)) { + if(((err = tbd_create_write_cmd(stream, TBD_CMD_FILE_DELTA)) != 0) || + ((err = tbd_create_write_string(stream, b->name)) != 0) || + ((err = tbd_create_write_mdata_mask(stream, metadata_mask)) != 0) || + ((err = tbd_create_write_mtime (stream, b->mtime)) != 0) || + ((err = tbd_create_write_uid (stream, b->uid)) != 0) || + ((err = tbd_create_write_gid (stream, b->gid)) != 0) || + ((err = tbd_create_write_mode (stream, b->mode)) != 0)) { fclose(fpb); return err; } @@ -443,14 +443,14 @@ tbd_create_cmd_dir_create(FILE *stream, { int err; - if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_DIR_CREATE)) != 0 || - (err = tbd_create_fwrite_string(stream, d->name)) != 0 || - (err = tbd_create_fwrite_mtime(stream, d->mtime)) != 0 || - (err = tbd_create_fwrite_uid(stream, d->uid)) != 0 || - (err = tbd_create_fwrite_gid(stream, d->gid)) != 0) + if((err = tbd_create_write_cmd(stream, TBD_CMD_DIR_CREATE)) != 0 || + (err = tbd_create_write_string(stream, d->name)) != 0 || + (err = tbd_create_write_mtime(stream, d->mtime)) != 0 || + (err = tbd_create_write_uid(stream, d->uid)) != 0 || + (err = tbd_create_write_gid(stream, d->gid)) != 0) return err; - return tbd_create_fwrite_mode(stream, d->mode); + return tbd_create_write_mode(stream, d->mode); } static int @@ -458,9 +458,9 @@ tbd_create_cmd_dir_enter(FILE *stream, const char *name) { int err; - if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_DIR_ENTER)) != 0) + if((err = tbd_create_write_cmd(stream, TBD_CMD_DIR_ENTER)) != 0) return err; - return tbd_create_fwrite_string(stream, name); + return tbd_create_write_string(stream, name); } static int @@ -468,12 +468,12 @@ tbd_create_cmd_dir_leave(FILE *stream, tbd_stat_t *dir) { int err; - if ((err = tbd_create_fwrite_cmd(stream, TBD_CMD_DIR_LEAVE)) != + if ((err = tbd_create_write_cmd(stream, TBD_CMD_DIR_LEAVE)) != TBD_ERROR_SUCCESS) { return err; } - return tbd_create_fwrite_mtime(stream, dir->mtime); + return tbd_create_write_mtime(stream, dir->mtime); } static int @@ -481,9 +481,9 @@ tbd_create_cmd_entity_delete(FILE *stream, const char *name) { int err; - if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_ENTITY_DELETE)) != 0) + if((err = tbd_create_write_cmd(stream, TBD_CMD_ENTITY_DELETE)) != 0) return err; - return tbd_create_fwrite_string(stream, name); + return tbd_create_write_string(stream, name); } static int @@ -497,15 +497,15 @@ tbd_create_cmd_dir_delta(FILE *stream, if(metadata_mask == TBD_METADATA_NONE) return 0; - if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_DIR_DELTA)) != 0 || - (err = tbd_create_fwrite_mdata_mask (stream, metadata_mask)) != 0 || - (err = tbd_create_fwrite_mtime (stream, b->mtime)) != 0 || - (err = tbd_create_fwrite_uid (stream, b->uid)) != 0 || - (err = tbd_create_fwrite_gid (stream, b->gid)) != 0 || - (err = tbd_create_fwrite_mode (stream, b->mode)) != 0) + if((err = tbd_create_write_cmd(stream, TBD_CMD_DIR_DELTA)) != 0 || + (err = tbd_create_write_mdata_mask (stream, metadata_mask)) != 0 || + (err = tbd_create_write_mtime (stream, b->mtime)) != 0 || + (err = tbd_create_write_uid (stream, b->uid)) != 0 || + (err = tbd_create_write_gid (stream, b->gid)) != 0 || + (err = tbd_create_write_mode (stream, b->mode)) != 0) return err; - return tbd_create_fwrite_string(stream, b->name); + return tbd_create_write_string(stream, b->name); } static int @@ -522,14 +522,14 @@ tbd_create_cmd_symlink_create(FILE *stream, return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_SYMLINK); path[len] = '\0'; - if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_SYMLINK_CREATE)) != 0 || - (err = tbd_create_fwrite_mtime (stream, symlink->mtime)) != 0 || - (err = tbd_create_fwrite_uid (stream, symlink->uid)) != 0 || - (err = tbd_create_fwrite_gid (stream, symlink->gid)) != 0 || - (err = tbd_create_fwrite_string(stream, symlink->name)) != 0) + if((err = tbd_create_write_cmd(stream, TBD_CMD_SYMLINK_CREATE)) != 0 || + (err = tbd_create_write_mtime (stream, symlink->mtime)) != 0 || + (err = tbd_create_write_uid (stream, symlink->uid)) != 0 || + (err = tbd_create_write_gid (stream, symlink->gid)) != 0 || + (err = tbd_create_write_string(stream, symlink->name)) != 0) return err; - return tbd_create_fwrite_string(stream, path); + return tbd_create_write_string(stream, path); } static int @@ -576,14 +576,14 @@ tbd_create_cmd_special_create(FILE *stream, { int err; - if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_SPECIAL_CREATE)) != 0 || - (err = tbd_create_fwrite_string(stream, nod->name)) != 0 || - (err = tbd_create_fwrite_mtime (stream, nod->mtime)) != 0 || - (err = tbd_create_fwrite_mode (stream, nod->mode)) != 0 || - (err = tbd_create_fwrite_uid (stream, nod->uid)) != 0 || - (err = tbd_create_fwrite_gid (stream, nod->gid)) != 0) + if((err = tbd_create_write_cmd(stream, TBD_CMD_SPECIAL_CREATE)) != 0 || + (err = tbd_create_write_string(stream, nod->name)) != 0 || + (err = tbd_create_write_mtime (stream, nod->mtime)) != 0 || + (err = tbd_create_write_mode (stream, nod->mode)) != 0 || + (err = tbd_create_write_uid (stream, nod->uid)) != 0 || + (err = tbd_create_write_gid (stream, nod->gid)) != 0) return err; - return tbd_create_fwrite_dev(stream, nod->rdev); + return tbd_create_write_dev(stream, nod->rdev); } static int -- cgit v1.2.1 From e39253f8632c83c289ab118e044175950d8e902e Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 17:59:59 +0100 Subject: Cleanup writing of xattr pairs in tbdiff-create.c --- tbdiff/tbdiff-create.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tbdiff/tbdiff-create.c b/tbdiff/tbdiff-create.c index d855387..73a40bb 100644 --- a/tbdiff/tbdiff-create.c +++ b/tbdiff/tbdiff-create.c @@ -143,26 +143,26 @@ tbd_create_cmd_update(FILE *stream) * this will write the attribute name, then the data representing that block */ static int -_write_pair(char const *name, void const *data, size_t size, void *ud) +tbd_create_cmd_write_xattr_pair(char const *name, + void const *data, + size_t size, + void *stream) { - FILE *stream = ud; int err; if ((err = tbd_create_write_string(stream, name)) != - TBD_ERROR_SUCCESS) { + TBD_ERROR_SUCCESS) return err; - } if ((err = tbd_create_write_block(stream, data, size)) != - TBD_ERROR_SUCCESS) { + TBD_ERROR_SUCCESS) return err; - } return TBD_ERROR_SUCCESS; } static int -tbd_create_cmd_fwrite_xattrs(FILE *stream, tbd_stat_t *f) +tbd_create_cmd_write_xattrs(FILE *stream, tbd_stat_t *f) { int err = TBD_ERROR_SUCCESS; tbd_xattrs_names_t names; @@ -206,7 +206,10 @@ tbd_create_cmd_fwrite_xattrs(FILE *stream, tbd_stat_t *f) } /* write the name:data pairs */ - err = tbd_xattrs_pairs(&names, path, _write_pair, stream); + err = tbd_xattrs_pairs(&names, + path, + tbd_create_cmd_write_xattr_pair, + stream); cleanup_names: tbd_xattrs_names_free(&names); @@ -247,7 +250,7 @@ tbd_create_cmd_file_create(FILE *stream, } fclose(fp); - return tbd_create_cmd_fwrite_xattrs(stream, f); + return tbd_create_cmd_write_xattrs(stream, f); } static uint16_t @@ -393,7 +396,7 @@ tbd_create_cmd_file_delta(FILE *stream, if((end == start) && (size == 0)) { tbd_create_cmd_file_metadata_update(stream, a, b); fclose(fpb); - return tbd_create_cmd_fwrite_xattrs(stream, b); + return tbd_create_cmd_write_xattrs(stream, b); } uint16_t metadata_mask = tbd_metadata_mask(a, b); @@ -434,7 +437,7 @@ tbd_create_cmd_file_delta(FILE *stream, } fclose(fpb); - return tbd_create_cmd_fwrite_xattrs(stream, b); + return tbd_create_cmd_write_xattrs(stream, b); } static int -- cgit v1.2.1 From 7a91ea67a98c54fcdb9d1b092bba524200c726dd Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 14:54:12 +0100 Subject: Added warning and debug mechanism to tbdiff-common.h Added TBD_WARN and TBD_DEBUG macros to allow for warnings and debug messages to be printed. This will make current debugging messages cleaner and allow us to warn when the chown operation fails. --- tbdiff/tbdiff-common.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tbdiff/tbdiff-common.h b/tbdiff/tbdiff-common.h index 9e7fcd7..cbb5c0d 100644 --- a/tbdiff/tbdiff-common.h +++ b/tbdiff/tbdiff-common.h @@ -24,6 +24,7 @@ #include #include +#include #include @@ -85,16 +86,42 @@ typedef enum { } tbd_error_e; #ifdef NDEBUG +#define TBD_DEBUG(d) +#define TBD_WARN(w) #define TBD_ERROR(e) (e) +#define TBD_DEBUGF(d, ...) +#define TBD_WARNF(w, ...) #else +#define TBD_DEBUG(d) \ + tbd_log("debug", "%s", __func__, __LINE__, __FILE__, d) +#define TBD_WARN(w) \ + tbd_log("warning", "%s", __func__, __LINE__, __FILE__, w) +#define TBD_DEBUGF(d, ...) \ + tbd_log("debug", d, __func__, __LINE__, __FILE__, __VA_ARGS__) +#define TBD_WARNF(w, ...) \ + tbd_log("warning", w, __func__, __LINE__, __FILE__, __VA_ARGS__) +static inline +tbd_log(char const *t, char const *s, char const *func, int line, + char const *file, ...) +{ + va_list args; + va_start(args, file); + + fprintf(stderr, "TBDiff %s '", t); + vfprintf(stderr, s, args); + fprintf(stderr, "' in function '%s' at line %d of file '%s'.\n", + func, line, file); + + va_end(args); +} + #define TBD_ERROR(e) tbd_error(e, #e, __func__, __LINE__, __FILE__) static inline tbd_error_e tbd_error(tbd_error_e e, char const *s, char const *func, int line, char const* file) { if (e != TBD_ERROR_SUCCESS) - fprintf(stderr, "TBDiff error '%s' in function '%s' at line %d " - "of file '%s'.\n", s, func, line, file); + tbd_log("error", "%s", func, line, file, s); return e; } #endif -- cgit v1.2.1 From 22af73f152d48af1b7ecc78b32ef3b7bc43ca3d3 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 15:33:02 +0100 Subject: Use TBD_DEBUG macro instead of fprint for debug messages We now use the TBD_DEBUG macro rather than fprintf, this means that debug messages aren't printed when debugging is disabled. --- tbdiff/tbdiff-apply.c | 20 ++++++++++---------- tbdiff/tbdiff-create.c | 22 +++++++++++----------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index 0a1fe7c..c5bb4ae 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -121,7 +121,7 @@ tbd_apply_cmd_dir_create(FILE *stream) if(fread(dname, 1, dlen, stream) != dlen) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); dname[dlen] = '\0'; - fprintf(stderr, "cmd_dir_create %s\n", dname); + TBD_DEBUGF("cmd_dir_create %s\n", dname); if(strchr(dname, '/') != NULL) return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); @@ -165,7 +165,7 @@ tbd_apply_cmd_dir_enter(FILE *stream, if(fread(dname, 1, dlen, stream) != dlen) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); dname[dlen] = '\0'; - fprintf(stderr, "cmd_dir_enter %s\n", dname); + TBD_DEBUGF("cmd_dir_enter %s\n", dname); if((strchr(dname, '/') != NULL) || (strcmp(dname, "..") == 0)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_CHANGE_DIR); if(depth != NULL) @@ -188,7 +188,7 @@ tbd_apply_cmd_dir_leave(FILE *stream, } time.actime = time.modtime;/* not sure what the best atime to use is */ - fprintf(stderr, "cmd_dir_leave\n"); + TBD_DEBUG("cmd_dir_leave\n"); /* test for leaving shallowest depth */ if ((depth != NULL) && (*depth < 1)) { @@ -236,7 +236,7 @@ tbd_apply_cmd_file_create(FILE *stream) tbd_read_uint32(&fsize, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); - fprintf(stderr, "cmd_file_create %s:%"PRId32"\n", fname, fsize); + TBD_DEBUGF("cmd_file_create %s:%"PRId32"\n", fname, fsize); FILE *fp = fopen(fname, "rb"); if(fp != NULL) { @@ -294,7 +294,7 @@ tbd_apply_cmd_file_delta(FILE *stream) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); fname[flen] = '\0'; - fprintf(stderr, "cmd_file_delta %s\n", fname); + TBD_DEBUGF("cmd_file_delta %s\n", fname); if((strchr(fname, '/') != NULL) || (strcmp(fname, "..") == 0)) @@ -485,7 +485,7 @@ tbd_apply_cmd_entity_delete(FILE *stream) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); ename[elen] = '\0'; - fprintf(stderr, "cmd_entity_delete %s\n", ename); + TBD_DEBUGF("cmd_entity_delete %s\n", ename); if((strchr(ename, '/') != NULL) || (strcmp(ename, "..") == 0)) return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); @@ -523,7 +523,7 @@ tbd_apply_cmd_symlink_create(FILE *stream) if(fread(linkpath, sizeof(char), len, stream) != len) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); - fprintf(stderr, "cmd_symlink_create %s -> %s\n", linkname, linkpath); + TBD_DEBUGF("cmd_symlink_create %s -> %s\n", linkname, linkpath); if(symlink(linkpath, linkname)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_CREATE_SYMLINK); @@ -559,7 +559,7 @@ tbd_apply_cmd_special_create(FILE *stream) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } - fprintf(stderr, "cmd_special_create %s\n", name); + TBD_DEBUGF("cmd_special_create %s\n", name); if(mknod(name, mode, (dev_t)dev) != 0) { free(name); @@ -596,7 +596,7 @@ tbd_apply_cmd_dir_delta(FILE *stream) if(dname == NULL) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); - fprintf(stderr, "cmd_dir_delta %s\n", dname); + TBD_DEBUGF("cmd_dir_delta %s\n", dname); if(metadata_mask & TBD_METADATA_MTIME) { struct utimbuf timebuff = { time(NULL), mtime }; @@ -631,7 +631,7 @@ tbd_apply_cmd_file_mdata_update(FILE *stream) if(dname == NULL) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); - fprintf(stderr, "cmd_metadata_update %s\n", dname); + TBD_DEBUGF("cmd_metadata_update %s\n", dname); if(metadata_mask & TBD_METADATA_MTIME) { struct utimbuf timebuff = { time(NULL), mtime }; diff --git a/tbdiff/tbdiff-create.c b/tbdiff/tbdiff-create.c index 73a40bb..edfb985 100644 --- a/tbdiff/tbdiff-create.c +++ b/tbdiff/tbdiff-create.c @@ -685,7 +685,7 @@ tbd_create_impl(FILE *stream, int err; if(((b == NULL) || ((a != NULL) && (a->type != b->type)))) { - fprintf(stderr, "file delete %s\n", a->name); + TBD_DEBUGF("file delete %s\n", a->name); if((err = tbd_create_cmd_entity_delete(stream, a->name)) != 0) return err; } @@ -693,21 +693,21 @@ tbd_create_impl(FILE *stream, if((a == NULL) || ((b != NULL) && (a->type != b->type))) { switch(b->type) { case TBD_STAT_TYPE_FILE: - fprintf(stderr, "file new %s\n", b->name); + TBD_DEBUGF("file new %s\n", b->name); return tbd_create_cmd_file_create(stream, b); case TBD_STAT_TYPE_DIR: - fprintf(stderr, "dir new %s\n", b->name); + TBD_DEBUGF("dir new %s\n", b->name); return tbd_create_dir(stream, b); case TBD_STAT_TYPE_SYMLINK: - fprintf(stderr, "symlink new %s\n", b->name); + TBD_DEBUGF("symlink new %s\n", b->name); return tbd_create_cmd_symlink_create(stream, b); case TBD_STAT_TYPE_CHRDEV: case TBD_STAT_TYPE_BLKDEV: case TBD_STAT_TYPE_FIFO: - fprintf(stderr, "special new %s\n", b->name); + TBD_DEBUGF("special new %s\n", b->name); return tbd_create_cmd_special_create(stream, b); case TBD_STAT_TYPE_SOCKET: - fprintf(stderr, "socket new %s\n", b->name); + TBD_DEBUGF("socket new %s\n", b->name); return tbd_create_cmd_socket_create(stream, b); default: return TBD_ERROR(TBD_ERROR_FEATURE_NOT_IMPLEMENTED); @@ -716,22 +716,22 @@ tbd_create_impl(FILE *stream, switch(b->type) { case TBD_STAT_TYPE_FILE: - fprintf(stderr, "file delta %s\n", a->name); + TBD_DEBUGF("file delta %s\n", a->name); return tbd_create_cmd_file_delta(stream, a, b); case TBD_STAT_TYPE_SYMLINK: - fprintf(stderr, "symlink delta %s\n", a->name); + TBD_DEBUGF("symlink delta %s\n", a->name); return tbd_create_cmd_symlink_delta(stream, a, b); case TBD_STAT_TYPE_CHRDEV: case TBD_STAT_TYPE_BLKDEV: case TBD_STAT_TYPE_FIFO: - fprintf(stderr, "special delta %s\n", a->name); + TBD_DEBUGF("special delta %s\n", a->name); return tbd_create_cmd_special_delta(stream, a, b); case TBD_STAT_TYPE_SOCKET: - fprintf(stderr, "socket delta %s\n", a->name); + TBD_DEBUGF("socket delta %s\n", a->name); return tbd_create_cmd_socket_delta(stream, a, b); case TBD_STAT_TYPE_DIR: if(!top) { - fprintf(stderr, "dir delta %s\n", a->name); + TBD_DEBUGF("dir delta %s\n", a->name); if ((err = tbd_create_cmd_dir_delta(stream, a, b)) != TBD_ERROR_SUCCESS) { return err; -- cgit v1.2.1 From 9ce137fa7b1564786b93697f3ccadcd61370cd4e Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 15:38:34 +0100 Subject: Use TBD_DEBUG macro to print the value of an invalid command Use the TBD_DEBUG macro since it will be disabled when debug is disabled, otherwise we'd always print the error message. --- tbdiff/tbdiff-apply.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index c5bb4ae..2bbc9cc 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -769,7 +769,7 @@ tbd_apply(FILE *stream) flush = true; break; default: - fprintf(stderr, "Error: Invalid command 0x%02"PRIx8".\n", cmd); + TBD_DEBUGF("Invalid command 0x%02"PRIx8".\n", cmd); return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); } } -- cgit v1.2.1 From fb454c327097dda283c35a911fef141382aa383f Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Thu, 29 May 2014 14:55:14 +0100 Subject: Print warning using TBD_WARN when chown fails The compiler currently warns that the result of chown is ignored, for now we'll print a warning when the chown operation fails, but it'll need to be handled as an error eventually. --- tbdiff/tbdiff-apply.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index 2bbc9cc..666d876 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -148,7 +148,8 @@ tbd_apply_cmd_dir_create(FILE *stream) struct utimbuf timebuff = { time(NULL), mtime }; utime(dname, &timebuff); /* Don't care if it succeeds right now. */ - chown(dname, (uid_t)uid, (gid_t)gid); + if (chown(dname, (uid_t)uid, (gid_t)gid) < 0) + TBD_WARN("Failed to change ownership of directory"); chmod (dname, mode); return 0; @@ -270,7 +271,8 @@ tbd_apply_cmd_file_create(FILE *stream) /* Don't care if it succeeds right now. */ utime(fname, &timebuff); /* Chown ALWAYS have to be done before chmod */ - chown(fname, (uid_t)uid, (gid_t)gid); + if (chown(fname, (uid_t)uid, (gid_t)gid) < 0) + TBD_WARN("Failed to change ownership of file"); chmod(fname, mode); return 0; @@ -534,7 +536,8 @@ tbd_apply_cmd_symlink_create(FILE *stream) tv[1].tv_usec = 0; lutimes(linkname, tv); /* Don't care if it succeeds right now. */ - lchown(linkname, (uid_t)uid, (uid_t)gid); + if (lchown(linkname, (uid_t)uid, (uid_t)gid) < 0) + TBD_WARN("Failed to change ownership of symlink"); return TBD_ERROR_SUCCESS; } @@ -569,7 +572,8 @@ tbd_apply_cmd_special_create(FILE *stream) struct utimbuf timebuff = { time(NULL), mtime }; utime(name, &timebuff); /* Don't care if it succeeds right now. */ - chown(name, (uid_t)uid, (gid_t)gid); + if (chown(name, (uid_t)uid, (gid_t)gid) < 0) + TBD_WARN("Failed to change ownership of node"); chmod(name, mode); free(name); @@ -602,8 +606,10 @@ tbd_apply_cmd_dir_delta(FILE *stream) struct utimbuf timebuff = { time(NULL), mtime }; utime(dname, &timebuff); /* Don't care if it succeeds right now. */ } - if(metadata_mask & TBD_METADATA_UID || metadata_mask & TBD_METADATA_GID) - chown(dname, (uid_t)uid, (gid_t)gid); + if(metadata_mask & TBD_METADATA_UID || metadata_mask & TBD_METADATA_GID) { + if (chown(dname, (uid_t)uid, (gid_t)gid) < 0) + TBD_WARN("Failed to change ownership during file modification"); + } if(metadata_mask | TBD_METADATA_MODE) chmod(dname, mode); @@ -637,8 +643,11 @@ tbd_apply_cmd_file_mdata_update(FILE *stream) struct utimbuf timebuff = { time(NULL), mtime }; utime(dname, &timebuff); /* Don't care if it succeeds right now. */ } - if(metadata_mask & TBD_METADATA_UID || metadata_mask & TBD_METADATA_GID) - chown(dname, (uid_t)uid, (gid_t)gid); + if(metadata_mask & TBD_METADATA_UID || metadata_mask & TBD_METADATA_GID) { + if (chown(dname, (uid_t)uid, (gid_t)gid) < 0) + TBD_WARN("Failed to change ownership" + " during file attribute modification"); + } if(metadata_mask | TBD_METADATA_MODE) chmod(dname, mode); -- cgit v1.2.1