diff options
author | Ben Brewer <ben.brewer@codethink.co.uk> | 2014-05-29 11:44:45 +0100 |
---|---|---|
committer | Ben Brewer <ben.brewer@codethink.co.uk> | 2014-06-02 11:03:00 +0100 |
commit | 9bb191462e637bc97b6bcbcfe798cc254ba7a7e4 (patch) | |
tree | 0a3804c055cb396eabf49f27c5f02f0dac65a4b5 | |
parent | e9344787030b3ba052db9f79462ffa5da3a0ee32 (diff) | |
download | tbdiff-9bb191462e637bc97b6bcbcfe798cc254ba7a7e4.tar.gz |
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.
-rw-r--r-- | tbdiff/tbdiff-apply.c | 8 | ||||
-rw-r--r-- | tbdiff/tbdiff-common.h | 2 | ||||
-rw-r--r-- | 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; } |