From 5e7c9554d4685026e80c95e9efa8a4dae0f399de Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Fri, 30 May 2014 15:20:37 +0100 Subject: Remove extern keyword since it's not needed The extern keyword is not needed since it's the default property for a function, it also takes up extra space on the line which leads to more wrapping. --- tbdiff/tbdiff-common.h | 4 ++-- tbdiff/tbdiff-io.h | 28 ++++++++++++++-------------- tbdiff/tbdiff-stat.h | 18 +++++++++--------- tbdiff/tbdiff-xattrs.h | 14 +++++++------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tbdiff/tbdiff-common.h b/tbdiff/tbdiff-common.h index cbb5c0d..c60139d 100644 --- a/tbdiff/tbdiff-common.h +++ b/tbdiff/tbdiff-common.h @@ -126,7 +126,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); +int tbd_apply (FILE *stream); +int tbd_create(FILE *stream, tbd_stat_t *a, tbd_stat_t *b); #endif /* !__TBDIFF_COMMON_H__ */ diff --git a/tbdiff/tbdiff-io.h b/tbdiff/tbdiff-io.h index 585f670..dc18475 100644 --- a/tbdiff/tbdiff-io.h +++ b/tbdiff/tbdiff-io.h @@ -28,20 +28,20 @@ #include -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); +size_t tbd_write_uint16(uint16_t value, FILE* stream); +size_t tbd_write_uint32(uint32_t value, FILE* stream); +size_t tbd_write_uint64(uint64_t value, FILE* stream); +size_t tbd_write_time(time_t value, FILE* stream); +size_t tbd_write_mode(mode_t value, FILE* stream); +size_t tbd_write_uid(uid_t value, FILE* stream); +size_t tbd_write_gid(gid_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); +size_t tbd_read_uint16(uint16_t *value, FILE* stream); +size_t tbd_read_uint32(uint32_t *value, FILE* stream); +size_t tbd_read_uint64(uint64_t *value, FILE* stream); +size_t tbd_read_time(time_t *value, FILE* stream); +size_t tbd_read_mode(mode_t *value, FILE* stream); +size_t tbd_read_uid(uid_t *value, FILE* stream); +size_t tbd_read_gid(gid_t *value, FILE* stream); #endif /* !__TBDIFF_IO_H__ */ diff --git a/tbdiff/tbdiff-stat.h b/tbdiff/tbdiff-stat.h index 22da466..e4703d9 100644 --- a/tbdiff/tbdiff-stat.h +++ b/tbdiff/tbdiff-stat.h @@ -51,14 +51,14 @@ struct tbd_stat_s { uint32_t rdev; }; -extern tbd_stat_t* tbd_stat(const char *path); -extern void tbd_stat_free(tbd_stat_t *file); -extern void tbd_stat_print(tbd_stat_t *file); -extern tbd_stat_t* tbd_stat_entry(tbd_stat_t *file, uint32_t entry); -extern tbd_stat_t* tbd_stat_entry_find(tbd_stat_t *file, const char *name); -extern char* tbd_stat_subpath(tbd_stat_t *file, const char *entry); -extern char* tbd_stat_path(tbd_stat_t *file); -extern int tbd_stat_open(tbd_stat_t *file, int flags); -extern FILE* tbd_stat_fopen(tbd_stat_t *file, const char *mode); +tbd_stat_t* tbd_stat(const char *path); +void tbd_stat_free(tbd_stat_t *file); +void tbd_stat_print(tbd_stat_t *file); +tbd_stat_t* tbd_stat_entry(tbd_stat_t *file, uint32_t entry); +tbd_stat_t* tbd_stat_entry_find(tbd_stat_t *file, const char *name); +char* tbd_stat_subpath(tbd_stat_t *file, const char *entry); +char* tbd_stat_path(tbd_stat_t *file); +int tbd_stat_open(tbd_stat_t *file, int flags); +FILE* tbd_stat_fopen(tbd_stat_t *file, const char *mode); #endif /* !__TBDIFF_STAT_H__ */ diff --git a/tbdiff/tbdiff-xattrs.h b/tbdiff/tbdiff-xattrs.h index ba4a79e..7052e1a 100644 --- a/tbdiff/tbdiff-xattrs.h +++ b/tbdiff/tbdiff-xattrs.h @@ -32,33 +32,33 @@ typedef struct tbd_xattrs_names { } tbd_xattrs_names_t; /* gets a list of the names of the file referenced by path */ -extern int tbd_xattrs_names(char const *path, tbd_xattrs_names_t *names_out); +int tbd_xattrs_names(char const *path, tbd_xattrs_names_t *names_out); /* frees up the INTERNAL resources of the list, doesn't free the list itself */ -extern void tbd_xattrs_names_free(tbd_xattrs_names_t *names); +void tbd_xattrs_names_free(tbd_xattrs_names_t *names); /* calls f with every name in the list */ -extern int tbd_xattrs_names_each(tbd_xattrs_names_t const *names, +int tbd_xattrs_names_each(tbd_xattrs_names_t const *names, int (*f)(char const *name, void *ud), void *ud); /* gets how many different attributes there are in the list */ -extern int tbd_xattrs_names_count(tbd_xattrs_names_t const *names, uint32_t *count); +int tbd_xattrs_names_count(tbd_xattrs_names_t const *names, uint32_t *count); /* puts the value of the attribute called name into *buf with size *bufsize * if *buf is NULL or *bufsize is 0 then memory will be allocated for it * if *buf was too small it will be reallocated * if it is successful, *buf will contain *valsize bytes of data */ -extern int tbd_xattrs_get(char const *path, char const* name, void **buf, +int tbd_xattrs_get(char const *path, char const* name, void **buf, size_t *bufsize, size_t *valsize); /* removes all attributes of the file referenced by path */ -extern int tbd_xattrs_removeall(char const *path); +int tbd_xattrs_removeall(char const *path); /* calls f for every attribute:value pair in the list */ typedef int (*tbd_xattrs_pairs_callback_t)(char const *name, void const *data, size_t size, void *ud); -extern int tbd_xattrs_pairs(tbd_xattrs_names_t const *names, char const *path, +int tbd_xattrs_pairs(tbd_xattrs_names_t const *names, char const *path, tbd_xattrs_pairs_callback_t f, void *ud); #endif /* !__TBDIFF_XATTRS_H__ */ -- cgit v1.2.1 From 539ccd77d3017965cd70444ba80ce95799d9337d Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Fri, 30 May 2014 16:04:21 +0100 Subject: Remove use of typedef to avoid naming conflicts with POSIX POSIX reserves the use of the underscore T postfix for types, since most of the time we don't actually need to typedef the types and since it's more clear to prefix structs and enums with the struct and enum keywords, I've removed all uses of typedef and gone with the more simple approach used in the kernel. One typedef remains which is tbd_cmd_type, since this should be a native type of a fixed size. The postfix changed to type to show that it's a type and to ensure it doesn't collide with POSIX. --- tbdiff-create/main.c | 4 +- tbdiff/tbdiff-apply.c | 8 ++-- tbdiff/tbdiff-common.h | 20 +++++----- tbdiff/tbdiff-create.c | 100 ++++++++++++++++++++++++------------------------- tbdiff/tbdiff-stat.c | 59 ++++++++++++++++------------- tbdiff/tbdiff-stat.h | 44 +++++++++++----------- tbdiff/tbdiff-xattrs.c | 26 +++++++------ tbdiff/tbdiff-xattrs.h | 19 +++++----- 8 files changed, 142 insertions(+), 138 deletions(-) diff --git a/tbdiff-create/main.c b/tbdiff-create/main.c index d20feba..79b35e2 100644 --- a/tbdiff-create/main.c +++ b/tbdiff-create/main.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 @@ -38,7 +38,7 @@ main(int argc, if(getcwd(cwd_buff, cwd_size) == NULL) return EXIT_FAILURE; - tbd_stat_t *tstat[2]; + struct tbd_stat *tstat[2]; tstat[0] = tbd_stat(argv[2]); if(tstat[0] == NULL) { diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index 666d876..225da27 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -93,8 +93,8 @@ tbd_apply_read_block(FILE *stream, void **data, size_t *size) static int tbd_apply_identify(FILE *stream) { - tbd_cmd_t cmd; - if(fread(&cmd, sizeof(tbd_cmd_t), 1, stream) != 1) + tbd_cmd_type cmd; + if(fread(&cmd, sizeof(tbd_cmd_type), 1, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); if(cmd != TBD_CMD_IDENTIFY) return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); @@ -721,8 +721,8 @@ tbd_apply(FILE *stream) uintptr_t depth = 0; bool flush = false; while(!flush) { - tbd_cmd_t cmd; - if(fread(&cmd, sizeof(tbd_cmd_t), 1, stream) != 1) + tbd_cmd_type cmd; + if(fread(&cmd, sizeof(tbd_cmd_type), 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 c60139d..193b462 100644 --- a/tbdiff/tbdiff-common.h +++ b/tbdiff/tbdiff-common.h @@ -28,7 +28,7 @@ #include -typedef enum { +enum tbd_cmd { TBD_CMD_IDENTIFY = 0x00, TBD_CMD_UPDATE = 0x01, TBD_CMD_DIR_CREATE = 0x10, @@ -44,20 +44,20 @@ typedef enum { TBD_CMD_SYMLINK_CREATE = 0x40, TBD_CMD_SPECIAL_CREATE = 0x50, TBD_CMD_XATTRS_UPDATE = 0x60, -} tbd_cmd_e; +}; -typedef uint8_t tbd_cmd_t; +typedef uint8_t tbd_cmd_type; -typedef enum { +enum tbd_metadata_type { TBD_METADATA_NONE = 0x0, TBD_METADATA_MTIME = 0x1, TBD_METADATA_MODE = 0x2, TBD_METADATA_UID = 0x4, TBD_METADATA_GID = 0x8, TBD_METADATA_RDEV = 0x10, -} tbd_metadata_type_e; +}; -typedef enum { +enum tbd_error { TBD_ERROR_SUCCESS = 0, TBD_ERROR_FAILURE = -1, TBD_ERROR_OUT_OF_MEMORY = -2, @@ -83,7 +83,7 @@ typedef enum { 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 #define TBD_DEBUG(d) @@ -116,8 +116,8 @@ tbd_log(char const *t, char const *s, char const *func, int line, } #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, +static inline enum tbd_error +tbd_error(enum tbd_error e, char const *s, char const *func, int line, char const* file) { if (e != TBD_ERROR_SUCCESS) @@ -127,6 +127,6 @@ tbd_error(tbd_error_e e, char const *s, char const *func, int line, #endif int tbd_apply (FILE *stream); -int tbd_create(FILE *stream, tbd_stat_t *a, tbd_stat_t *b); +int tbd_create(FILE *stream, struct tbd_stat *a, struct tbd_stat *b); #endif /* !__TBDIFF_COMMON_H__ */ diff --git a/tbdiff/tbdiff-create.c b/tbdiff/tbdiff-create.c index edfb985..9e6d8ac 100644 --- a/tbdiff/tbdiff-create.c +++ b/tbdiff/tbdiff-create.c @@ -33,10 +33,10 @@ #define PATH_BUFFER_LENGTH 4096 static int -tbd_create_write_cmd(FILE *stream, - tbd_cmd_t cmd) +tbd_create_write_cmd(FILE *stream, + tbd_cmd_type cmd) { - if(fwrite(&cmd, sizeof(tbd_cmd_t), 1, stream) != 1) + if(fwrite(&cmd, sizeof(tbd_cmd_type), 1, stream) != 1) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } @@ -162,10 +162,10 @@ tbd_create_cmd_write_xattr_pair(char const *name, } static int -tbd_create_cmd_write_xattrs(FILE *stream, tbd_stat_t *f) +tbd_create_cmd_write_xattrs(FILE *stream, struct tbd_stat *f) { int err = TBD_ERROR_SUCCESS; - tbd_xattrs_names_t names; + struct tbd_xattrs_names names; char *path = tbd_stat_path(f); if (path == NULL) { return TBD_ERROR(TBD_ERROR_OUT_OF_MEMORY); @@ -219,8 +219,8 @@ cleanup_path: } static int -tbd_create_cmd_file_create(FILE *stream, - tbd_stat_t *f) +tbd_create_cmd_file_create(FILE *stream, + struct tbd_stat *f) { int err; if((err = tbd_create_write_cmd(stream, TBD_CMD_FILE_CREATE)) != 0 || @@ -254,8 +254,8 @@ tbd_create_cmd_file_create(FILE *stream, } static uint16_t -tbd_metadata_mask(tbd_stat_t *a, - tbd_stat_t *b) +tbd_metadata_mask(struct tbd_stat *a, + struct tbd_stat *b) { uint16_t metadata_mask = TBD_METADATA_NONE; @@ -273,9 +273,9 @@ tbd_metadata_mask(tbd_stat_t *a, } static int -tbd_create_cmd_file_metadata_update(FILE *stream, - tbd_stat_t *a, - tbd_stat_t *b) +tbd_create_cmd_file_metadata_update(FILE *stream, + struct tbd_stat *a, + struct tbd_stat *b) { int err; uint16_t metadata_mask = tbd_metadata_mask(a, b); @@ -295,9 +295,9 @@ tbd_create_cmd_file_metadata_update(FILE *stream, } static int -tbd_create_cmd_file_delta(FILE *stream, - tbd_stat_t *a, - tbd_stat_t *b) +tbd_create_cmd_file_delta(FILE *stream, + struct tbd_stat *a, + struct tbd_stat *b) { FILE *fpa = tbd_stat_fopen(a, "rb"); if(fpa == NULL) @@ -441,8 +441,8 @@ 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, + struct tbd_stat *d) { int err; @@ -467,8 +467,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, + struct tbd_stat *dir) { int err; if ((err = tbd_create_write_cmd(stream, TBD_CMD_DIR_LEAVE)) != @@ -490,9 +490,9 @@ tbd_create_cmd_entity_delete(FILE *stream, } static int -tbd_create_cmd_dir_delta(FILE *stream, - tbd_stat_t *a, - tbd_stat_t *b) +tbd_create_cmd_dir_delta(FILE *stream, + struct tbd_stat *a, + struct tbd_stat *b) { int err; uint16_t metadata_mask = tbd_metadata_mask(a, b); @@ -512,8 +512,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, + struct tbd_stat *symlink) { int err; char path[PATH_BUFFER_LENGTH]; @@ -536,9 +536,9 @@ tbd_create_cmd_symlink_create(FILE *stream, } static int -tbd_create_cmd_symlink_delta(FILE *stream, - tbd_stat_t *a, - tbd_stat_t *b) +tbd_create_cmd_symlink_delta(FILE *stream, + struct tbd_stat *a, + struct tbd_stat *b) { int err; char path_a[PATH_BUFFER_LENGTH]; @@ -574,8 +574,8 @@ 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, + struct tbd_stat *nod) { int err; @@ -590,9 +590,9 @@ tbd_create_cmd_special_create(FILE *stream, } static int -tbd_create_cmd_special_delta(FILE *stream, - tbd_stat_t *a, - tbd_stat_t *b) +tbd_create_cmd_special_delta(FILE *stream, + struct tbd_stat *a, + struct tbd_stat *b) { uint16_t metadata_mask = tbd_metadata_mask(a, b); if(a->rdev != b->rdev) @@ -610,8 +610,8 @@ tbd_create_cmd_special_delta(FILE *stream, } static int -tbd_create_cmd_socket_create(FILE *stream, - tbd_stat_t *nod) +tbd_create_cmd_socket_create(FILE *stream, + struct tbd_stat *nod) { (void)stream; (void)nod; @@ -619,9 +619,9 @@ tbd_create_cmd_socket_create(FILE *stream, } static int -tbd_create_cmd_socket_delta(FILE *stream, - tbd_stat_t *a, - tbd_stat_t *b) +tbd_create_cmd_socket_delta(FILE *stream, + struct tbd_stat *a, + struct tbd_stat *b) { (void)stream; (void)a; @@ -630,8 +630,8 @@ tbd_create_cmd_socket_delta(FILE *stream, } static int -tbd_create_dir(FILE *stream, - tbd_stat_t *d) +tbd_create_dir(FILE *stream, + struct tbd_stat *d) { int err; if(((err =tbd_create_cmd_dir_create(stream, d)) != 0) || @@ -640,7 +640,7 @@ tbd_create_dir(FILE *stream, uintptr_t i; for(i = 0; i < d->size; i++) { - tbd_stat_t *f = tbd_stat_entry(d, i); + struct tbd_stat *f = tbd_stat_entry(d, i); if(f == NULL) return TBD_ERROR(TBD_ERROR_UNABLE_TO_STAT_FILE); @@ -675,9 +675,9 @@ tbd_create_dir(FILE *stream, } static int -tbd_create_impl(FILE *stream, - tbd_stat_t *a, - tbd_stat_t *b, +tbd_create_impl(FILE *stream, + struct tbd_stat *a, + struct tbd_stat *b, bool top) { if((a == NULL) && (b == NULL)) @@ -748,10 +748,10 @@ tbd_create_impl(FILE *stream, /* Handle changes/additions. */ uintptr_t i; for(i = 0; i < b->size; i++) { - tbd_stat_t *_b = tbd_stat_entry(b, i); + struct tbd_stat *_b = tbd_stat_entry(b, i); if(_b == NULL) return TBD_ERROR(TBD_ERROR_UNABLE_TO_STAT_FILE); - tbd_stat_t *_a = tbd_stat_entry_find(a, _b->name); + struct tbd_stat *_a = tbd_stat_entry_find(a, _b->name); err = tbd_create_impl(stream, _a, _b, false); tbd_stat_free(_a); tbd_stat_free(_b); @@ -763,10 +763,10 @@ tbd_create_impl(FILE *stream, for(i = 0; i < a->size; i++) { err = 0; - tbd_stat_t *_a = tbd_stat_entry(a, i); + struct tbd_stat *_a = tbd_stat_entry(a, i); if(_a == NULL) return TBD_ERROR(TBD_ERROR_UNABLE_TO_STAT_FILE); - tbd_stat_t *_b = tbd_stat_entry_find(b, _a->name); + struct tbd_stat *_b = tbd_stat_entry_find(b, _a->name); if (_b == NULL) err = tbd_create_cmd_entity_delete(stream, _a->name); @@ -786,9 +786,9 @@ tbd_create_impl(FILE *stream, } int -tbd_create(FILE *stream, - tbd_stat_t *a, - tbd_stat_t *b) +tbd_create(FILE *stream, + struct tbd_stat *a, + struct tbd_stat *b) { int err; if((stream == NULL) || (a == NULL) || (b == NULL)) diff --git a/tbdiff/tbdiff-stat.c b/tbdiff/tbdiff-stat.c index 66e2caf..dce0cf4 100644 --- a/tbdiff/tbdiff-stat.c +++ b/tbdiff/tbdiff-stat.c @@ -29,7 +29,7 @@ #include -static tbd_stat_t* +static struct tbd_stat* tbd_stat_from_path(const char *name, const char *path) { @@ -39,13 +39,15 @@ tbd_stat_from_path(const char *name, return NULL; size_t nlen = strlen(name); - tbd_stat_t *ret = (tbd_stat_t*)malloc(sizeof(tbd_stat_t) + (nlen + 1)); + struct tbd_stat *ret = (struct tbd_stat*)malloc( + sizeof(struct tbd_stat) + (nlen + 1)); if(ret == NULL) return NULL; ret->parent = NULL; ret->size = 0; - ret->name = (char*)((uintptr_t)ret + sizeof(tbd_stat_t)); + ret->name = (char*)((uintptr_t)ret + + sizeof(struct tbd_stat)); memcpy(ret->name, name, (nlen + 1)); if(S_ISREG(info.st_mode)) { @@ -93,27 +95,27 @@ tbd_stat_from_path(const char *name, return ret; } -tbd_stat_t* +struct tbd_stat* tbd_stat(const char *path) { - tbd_stat_t *ret = tbd_stat_from_path(path, path); + struct tbd_stat *ret = tbd_stat_from_path(path, path); return ret; } void -tbd_stat_free(tbd_stat_t *file) +tbd_stat_free(struct tbd_stat *file) { free(file); } void -tbd_stat_print(tbd_stat_t *file) +tbd_stat_print(struct tbd_stat *file) { (void)file; } -tbd_stat_t* -tbd_stat_entry(tbd_stat_t *file, uint32_t entry) +struct tbd_stat* +tbd_stat_entry(struct tbd_stat *file, uint32_t entry) { if((file == NULL) || (file->type != TBD_STAT_TYPE_DIR) @@ -140,16 +142,17 @@ tbd_stat_entry(tbd_stat_t *file, uint32_t entry) (strcmp(ds->d_name, "..") == 0)) i--; } - char *name = strndup(ds->d_name, ds->d_reclen-offsetof(struct dirent, d_name)); + char *name = strndup(ds->d_name, + ds->d_reclen-offsetof(struct dirent, d_name)); closedir (dp); - char *spath = tbd_stat_subpath(file, name); + char *spath = tbd_statubpath(file, name); if(spath == NULL) { free(name); return NULL; } - tbd_stat_t *ret = tbd_stat_from_path(name, (const char*)spath); + struct tbd_stat *ret = tbd_stat_from_path(name, (const char*)spath); free(name); free(spath); @@ -161,9 +164,9 @@ tbd_stat_entry(tbd_stat_t *file, uint32_t entry) return ret; } -tbd_stat_t* -tbd_stat_entry_find(tbd_stat_t *file, - const char *name) +struct tbd_stat* +tbd_stat_entry_find(struct tbd_stat *file, + const char *name) { if((file == NULL) || (file->type != TBD_STAT_TYPE_DIR)) @@ -179,14 +182,15 @@ tbd_stat_entry_find(tbd_stat_t *file, struct dirent *ds; for(ds = readdir(dp); ds != NULL; ds = readdir(dp)) { if(strcmp(ds->d_name, name) == 0) { - char *spath = tbd_stat_subpath(file, ds->d_name); + char *spath = tbd_statubpath(file, ds->d_name); if(spath == NULL) { closedir (dp); return NULL; } - tbd_stat_t *ret = tbd_stat_from_path(ds->d_name, (const char*)spath); + struct tbd_stat *ret = tbd_stat_from_path(ds->d_name, + (const char*)spath); free(spath); ret->parent = file; @@ -200,8 +204,8 @@ tbd_stat_entry_find(tbd_stat_t *file, } char* -tbd_stat_subpath(tbd_stat_t *file, - const char *entry) +tbd_statubpath(struct tbd_stat *file, + const char *entry) { if(file == NULL) return NULL; @@ -209,10 +213,11 @@ tbd_stat_subpath(tbd_stat_t *file, size_t elen = ((entry == NULL) ? 0 : (strlen(entry) + 1)); size_t plen; - tbd_stat_t *root; + struct tbd_stat *root; for(root = file, plen = 0; root != NULL; - plen += (strlen(root->name) + 1), root = (tbd_stat_t*)root->parent); + plen += (strlen(root->name) + 1), + root = (struct tbd_stat*)root->parent); plen += elen; @@ -226,7 +231,7 @@ tbd_stat_subpath(tbd_stat_t *file, memcpy(ptr, entry, elen); } - for(root = file; root != NULL; root = (tbd_stat_t*)root->parent) { + for(root = file; root != NULL; root = (struct tbd_stat*)root->parent) { size_t rlen = strlen(root->name) + 1; ptr = (char*)((uintptr_t)ptr - rlen); memcpy(ptr, root->name, rlen); @@ -238,13 +243,13 @@ tbd_stat_subpath(tbd_stat_t *file, } char* -tbd_stat_path(tbd_stat_t *file) +tbd_stat_path(struct tbd_stat *file) { - return tbd_stat_subpath(file, NULL); + return tbd_statubpath(file, NULL); } int -tbd_stat_open(tbd_stat_t *file, int flags) +tbd_stat_open(struct tbd_stat *file, int flags) { char *path = tbd_stat_path(file); if(path == NULL) @@ -255,8 +260,8 @@ tbd_stat_open(tbd_stat_t *file, int flags) } FILE* -tbd_stat_fopen(tbd_stat_t *file, - const char *mode) +tbd_stat_fopen(struct tbd_stat *file, + const char *mode) { char *path = tbd_stat_path(file); if(path == NULL) diff --git a/tbdiff/tbdiff-stat.h b/tbdiff/tbdiff-stat.h index e4703d9..6f4c93e 100644 --- a/tbdiff/tbdiff-stat.h +++ b/tbdiff/tbdiff-stat.h @@ -27,7 +27,7 @@ #include #include -typedef enum { +enum tbd_stat_type { TBD_STAT_TYPE_FILE = 'f', TBD_STAT_TYPE_DIR = 'd', TBD_STAT_TYPE_SYMLINK = 'l', @@ -35,30 +35,28 @@ typedef enum { TBD_STAT_TYPE_BLKDEV = 'b', TBD_STAT_TYPE_FIFO = 'p', TBD_STAT_TYPE_SOCKET = 's' -} tbd_stat_type_e; - -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; - uint32_t size; /* Count for directory. */ - uid_t uid; - gid_t gid; - mode_t mode; - uint32_t rdev; +struct tbd_stat { + struct tbd_stat* parent; + char* name; + enum tbd_stat_type type; + time_t mtime; + uint32_t size; /* Count for directory. */ + uid_t uid; + gid_t gid; + mode_t mode; + uint32_t rdev; }; -tbd_stat_t* tbd_stat(const char *path); -void tbd_stat_free(tbd_stat_t *file); -void tbd_stat_print(tbd_stat_t *file); -tbd_stat_t* tbd_stat_entry(tbd_stat_t *file, uint32_t entry); -tbd_stat_t* tbd_stat_entry_find(tbd_stat_t *file, const char *name); -char* tbd_stat_subpath(tbd_stat_t *file, const char *entry); -char* tbd_stat_path(tbd_stat_t *file); -int tbd_stat_open(tbd_stat_t *file, int flags); -FILE* tbd_stat_fopen(tbd_stat_t *file, const char *mode); +struct tbd_stat* tbd_stat(const char *path); +void tbd_stat_free(struct tbd_stat *file); +void tbd_stat_print(struct tbd_stat *file); +struct tbd_stat* tbd_stat_entry(struct tbd_stat *file, uint32_t entry); +struct tbd_stat* tbd_stat_entry_find(struct tbd_stat *file, const char *name); +char* tbd_statubpath(struct tbd_stat *file, const char *entry); +char* tbd_stat_path(struct tbd_stat *file); +int tbd_stat_open(struct tbd_stat *file, int flags); +FILE* tbd_stat_fopen(struct tbd_stat *file, const char *mode); #endif /* !__TBDIFF_STAT_H__ */ diff --git a/tbdiff/tbdiff-xattrs.c b/tbdiff/tbdiff-xattrs.c index c020ee5..96330b2 100644 --- a/tbdiff/tbdiff-xattrs.c +++ b/tbdiff/tbdiff-xattrs.c @@ -31,7 +31,7 @@ #include #include -int tbd_xattrs_names(char const *path, tbd_xattrs_names_t *names) +int tbd_xattrs_names(char const *path, struct tbd_xattrs_names *names) { char *attrnames = NULL; /* get size of names list */ @@ -85,12 +85,12 @@ int tbd_xattrs_names(char const *path, tbd_xattrs_names_t *names) return TBD_ERROR_SUCCESS; } -void tbd_xattrs_names_free(tbd_xattrs_names_t *names) +void tbd_xattrs_names_free(struct tbd_xattrs_names *names) { free((void *)names->begin); } -int tbd_xattrs_names_each(tbd_xattrs_names_t const *names, +int tbd_xattrs_names_each(struct tbd_xattrs_names const *names, int (*f)(char const *name, void *ud), void *ud) { char const *name; @@ -110,7 +110,8 @@ static int names_sum(char const *name, void *ud) { (*((uint32_t*)ud))++; return TBD_ERROR_SUCCESS; } -int tbd_xattrs_names_count(tbd_xattrs_names_t const *names, uint32_t *count) { +int tbd_xattrs_names_count(struct tbd_xattrs_names const *names, + uint32_t *count) { uint32_t _count = 0; int err; if ((err = tbd_xattrs_names_each(names, &names_sum, &_count)) == @@ -137,7 +138,7 @@ static int name_remove(char const *name, void *ud) { int tbd_xattrs_removeall(char const *path) { int err = TBD_ERROR_SUCCESS; - tbd_xattrs_names_t list; + struct tbd_xattrs_names list; /* get the list of attributes */ if ((err = tbd_xattrs_names(path, &list)) != TBD_ERROR_SUCCESS) { @@ -202,16 +203,16 @@ int tbd_xattrs_get(char const *path, char const* name, void **buf, return TBD_ERROR_SUCCESS; } -typedef struct { +struct tbd_xattrs_pairs_params { char const *path; - tbd_xattrs_pairs_callback_t f; + int (*f)(char const *, void const *, size_t, void *); void *pairs_ud; void *data; size_t data_size; -} tbd_xattrs_pairs_params_t; +}; static int call_with_data(char const *name, void *ud) { - tbd_xattrs_pairs_params_t *params; + struct tbd_xattrs_pairs_params *params; params = ud; size_t value_size; int err; @@ -222,10 +223,11 @@ static int call_with_data(char const *name, void *ud) } return params->f(name, params->data, value_size, params->pairs_ud); } -int tbd_xattrs_pairs(tbd_xattrs_names_t const *names, char const *path, - tbd_xattrs_pairs_callback_t f, void *ud) +int tbd_xattrs_pairs(struct tbd_xattrs_names const *names, char const *path, + int (*f)(char const *, void const *, size_t, void *), + void *ud) { - tbd_xattrs_pairs_params_t params = { + struct tbd_xattrs_pairs_params params = { path, f, ud, NULL, 0, }; int err = tbd_xattrs_names_each(names, &call_with_data, ¶ms); diff --git a/tbdiff/tbdiff-xattrs.h b/tbdiff/tbdiff-xattrs.h index 7052e1a..c263e18 100644 --- a/tbdiff/tbdiff-xattrs.h +++ b/tbdiff/tbdiff-xattrs.h @@ -26,24 +26,24 @@ #include /* structure for names data */ -typedef struct tbd_xattrs_names { +struct tbd_xattrs_names { char const *begin; char const *end; -} tbd_xattrs_names_t; +}; /* gets a list of the names of the file referenced by path */ -int tbd_xattrs_names(char const *path, tbd_xattrs_names_t *names_out); +int tbd_xattrs_names(char const *path, struct tbd_xattrs_names *names_out); /* frees up the INTERNAL resources of the list, doesn't free the list itself */ -void tbd_xattrs_names_free(tbd_xattrs_names_t *names); +void tbd_xattrs_names_free(struct tbd_xattrs_names *names); /* calls f with every name in the list */ -int tbd_xattrs_names_each(tbd_xattrs_names_t const *names, +int tbd_xattrs_names_each(struct tbd_xattrs_names const *names, int (*f)(char const *name, void *ud), void *ud); /* gets how many different attributes there are in the list */ -int tbd_xattrs_names_count(tbd_xattrs_names_t const *names, uint32_t *count); +int tbd_xattrs_names_count(struct tbd_xattrs_names const *names, uint32_t *count); /* puts the value of the attribute called name into *buf with size *bufsize * if *buf is NULL or *bufsize is 0 then memory will be allocated for it @@ -57,8 +57,7 @@ int tbd_xattrs_get(char const *path, char const* name, void **buf, int tbd_xattrs_removeall(char const *path); /* calls f for every attribute:value pair in the list */ -typedef int (*tbd_xattrs_pairs_callback_t)(char const *name, void const *data, - size_t size, void *ud); -int tbd_xattrs_pairs(tbd_xattrs_names_t const *names, char const *path, - tbd_xattrs_pairs_callback_t f, void *ud); +int tbd_xattrs_pairs(struct tbd_xattrs_names const *names, char const *path, + int (*f)(char const *, void const *, size_t, void *), + void *ud); #endif /* !__TBDIFF_XATTRS_H__ */ -- cgit v1.2.1 From 56bb60f7e0a4b79ec8da62dccd054b87d7469fb6 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Fri, 30 May 2014 16:08:06 +0100 Subject: Use quoted includes for local headers in tbdiff source files Quoted includes should be used when including headers which represent declarations in local source files. The source files have been modified to reflect this. This makes it more clear which headers are system headers and which are part of the tbdiff codebase. --- tbdiff/tbdiff-apply.c | 8 ++++---- tbdiff/tbdiff-create.c | 8 ++++---- tbdiff/tbdiff-io.c | 2 +- tbdiff/tbdiff-stat.c | 2 +- tbdiff/tbdiff-xattrs.c | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index 225da27..5281c37 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -37,10 +37,10 @@ #include #endif -#include -#include -#include -#include +#include "tbdiff-common.h" +#include "tbdiff-io.h" +#include "tbdiff-private.h" +#include "tbdiff-xattrs.h" char* tbd_apply_read_string(FILE *stream) diff --git a/tbdiff/tbdiff-create.c b/tbdiff/tbdiff-create.c index 9e6d8ac..57ab4fe 100644 --- a/tbdiff/tbdiff-create.c +++ b/tbdiff/tbdiff-create.c @@ -25,10 +25,10 @@ #include #include -#include -#include -#include -#include +#include "tbdiff-common.h" +#include "tbdiff-io.h" +#include "tbdiff-private.h" +#include "tbdiff-xattrs.h" #define PATH_BUFFER_LENGTH 4096 diff --git a/tbdiff/tbdiff-io.c b/tbdiff/tbdiff-io.c index c33364b..f9324aa 100644 --- a/tbdiff/tbdiff-io.c +++ b/tbdiff/tbdiff-io.c @@ -19,7 +19,7 @@ #include #include -#include +#include "tbdiff-stat.h" #if __STDC_VERSION__ >= 199901L #define RESTRICT restrict diff --git a/tbdiff/tbdiff-stat.c b/tbdiff/tbdiff-stat.c index dce0cf4..b0876ec 100644 --- a/tbdiff/tbdiff-stat.c +++ b/tbdiff/tbdiff-stat.c @@ -27,7 +27,7 @@ #include #include -#include +#include "tbdiff-stat.h" static struct tbd_stat* tbd_stat_from_path(const char *name, diff --git a/tbdiff/tbdiff-xattrs.c b/tbdiff/tbdiff-xattrs.c index 96330b2..5150199 100644 --- a/tbdiff/tbdiff-xattrs.c +++ b/tbdiff/tbdiff-xattrs.c @@ -28,8 +28,8 @@ #include -#include -#include +#include "tbdiff-common.h" +#include "tbdiff-xattrs.h" int tbd_xattrs_names(char const *path, struct tbd_xattrs_names *names) { -- cgit v1.2.1 From 0398b8bca477daf22f549fa3152a04abdc8da947 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Fri, 30 May 2014 16:45:53 +0100 Subject: Use POSIX file functions for tbdiff-create stream POSIX file functions are more consistent and simple, originally stdio was used to make the code as portable as possible, however since it now relies on POSIX functionality anyway there's no need for the inconsistency. --- tbdiff-create/main.c | 16 +++++--- tbdiff/tbdiff-common.h | 2 +- tbdiff/tbdiff-create.c | 104 +++++++++++++++++++++++++------------------------ tbdiff/tbdiff-io.c | 30 +++++++------- tbdiff/tbdiff-io.h | 15 +++---- 5 files changed, 88 insertions(+), 79 deletions(-) diff --git a/tbdiff-create/main.c b/tbdiff-create/main.c index 79b35e2..c8df2bf 100644 --- a/tbdiff-create/main.c +++ b/tbdiff-create/main.c @@ -18,7 +18,9 @@ #include #include #include +#include +#include #include #include @@ -62,15 +64,17 @@ main(int argc, return EXIT_FAILURE; } - FILE *fp = fopen(argv[1], "wb"); - if(fp == NULL) { - fprintf(stderr, "ERROR: Unable to open patch for writing.\n"); + int fd = open(argv[1], + O_WRONLY | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if(fd < 0) { + fprintf(stderr, "Error(%d): Unable to open patch for writing.\n", errno); return EXIT_FAILURE; } int err; - if((err = tbd_create(fp, tstat[0], tstat[1])) != 0) { - fclose(fp); + if((err = tbd_create(fd, tstat[0], tstat[1])) != 0) { + close(fd); tbd_stat_free(tstat[0]); tbd_stat_free(tstat[1]); @@ -89,7 +93,7 @@ main(int argc, return EXIT_FAILURE; } - fclose(fp); + close(fd); tbd_stat_free(tstat[0]); tbd_stat_free(tstat[1]); diff --git a/tbdiff/tbdiff-common.h b/tbdiff/tbdiff-common.h index 193b462..9b5b5f3 100644 --- a/tbdiff/tbdiff-common.h +++ b/tbdiff/tbdiff-common.h @@ -127,6 +127,6 @@ tbd_error(enum tbd_error e, char const *s, char const *func, int line, #endif int tbd_apply (FILE *stream); -int tbd_create(FILE *stream, struct tbd_stat *a, struct tbd_stat *b); +int tbd_create(int stream, struct tbd_stat *a, struct tbd_stat *b); #endif /* !__TBDIFF_COMMON_H__ */ diff --git a/tbdiff/tbdiff-create.c b/tbdiff/tbdiff-create.c index 57ab4fe..1f0312a 100644 --- a/tbdiff/tbdiff-create.c +++ b/tbdiff/tbdiff-create.c @@ -33,96 +33,96 @@ #define PATH_BUFFER_LENGTH 4096 static int -tbd_create_write_cmd(FILE *stream, +tbd_create_write_cmd(int stream, tbd_cmd_type cmd) { - if(fwrite(&cmd, sizeof(tbd_cmd_type), 1, stream) != 1) + if(write(stream, &cmd, sizeof(tbd_cmd_type)) != sizeof(tbd_cmd_type)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } static int -tbd_create_write_string(FILE *stream, +tbd_create_write_string(int stream, const char *string) { uint16_t slen = strlen(string); - if((tbd_write_uint16(slen, stream) != 1) - || (fwrite(string, 1, slen, stream) != slen)) + if((!tbd_write_uint16(slen, stream)) + || (write(stream, string, slen) != slen)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } static int -tbd_create_write_block(FILE *stream, +tbd_create_write_block(int stream, void const *data, size_t size) { - if (fwrite(&size, 1, sizeof(size), stream) != sizeof(size)) { + if (write(stream, &size, sizeof(size)) != sizeof(size)) { return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); } - if (fwrite(data, 1, size, stream) != size) { + if (write(stream, data, size) != size) { return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); } return TBD_ERROR_SUCCESS; } static int -tbd_create_write_mdata_mask(FILE *stream, +tbd_create_write_mdata_mask(int stream, uint16_t mask) { - if(tbd_write_uint16(mask, stream) != 1) + if(!tbd_write_uint16(mask, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } static int -tbd_create_write_mtime(FILE *stream, +tbd_create_write_mtime(int stream, time_t mtime) { - if(tbd_write_time(mtime, stream) != 1) + if(!tbd_write_time(mtime, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } static int -tbd_create_write_mode(FILE *stream, +tbd_create_write_mode(int stream, mode_t mode) { - if(tbd_write_mode(mode, stream) != 1) + if(!tbd_write_mode(mode, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } static int -tbd_create_write_gid(FILE *stream, +tbd_create_write_gid(int stream, gid_t gid) { - if(tbd_write_gid(gid, stream) != 1) + if(!tbd_write_gid(gid, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } static int -tbd_create_write_uid(FILE *stream, +tbd_create_write_uid(int stream, uid_t uid) { - if(tbd_write_uid(uid, stream) != 1) + if(!tbd_write_uid(uid, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } static int -tbd_create_write_dev(FILE *stream, +tbd_create_write_dev(int stream, uint32_t dev) { - if(tbd_write_uint32(dev, stream) != 1) + if(!tbd_write_uint32(dev, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); return 0; } static int -tbd_create_cmd_ident(FILE *stream) +tbd_create_cmd_ident(int stream) { int err; @@ -134,7 +134,7 @@ tbd_create_cmd_ident(FILE *stream) } static int -tbd_create_cmd_update(FILE *stream) +tbd_create_cmd_update(int stream) { return tbd_create_write_cmd(stream, TBD_CMD_UPDATE); } @@ -146,9 +146,10 @@ static int tbd_create_cmd_write_xattr_pair(char const *name, void const *data, size_t size, - void *stream) + void *ud) { int err; + int stream = *((int *)ud); if ((err = tbd_create_write_string(stream, name)) != TBD_ERROR_SUCCESS) @@ -162,7 +163,7 @@ tbd_create_cmd_write_xattr_pair(char const *name, } static int -tbd_create_cmd_write_xattrs(FILE *stream, struct tbd_stat *f) +tbd_create_cmd_write_xattrs(int stream, struct tbd_stat *f) { int err = TBD_ERROR_SUCCESS; struct tbd_xattrs_names names; @@ -199,7 +200,7 @@ tbd_create_cmd_write_xattrs(FILE *stream, struct tbd_stat *f) goto cleanup_names; } - if (tbd_write_uint32(count, stream) != 1) { + if (!tbd_write_uint32(count, stream)) { err = TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); goto cleanup_names; } @@ -209,7 +210,7 @@ tbd_create_cmd_write_xattrs(FILE *stream, struct tbd_stat *f) err = tbd_xattrs_pairs(&names, path, tbd_create_cmd_write_xattr_pair, - stream); + &stream); cleanup_names: tbd_xattrs_names_free(&names); @@ -219,7 +220,7 @@ cleanup_path: } static int -tbd_create_cmd_file_create(FILE *stream, +tbd_create_cmd_file_create(int stream, struct tbd_stat *f) { int err; @@ -232,7 +233,7 @@ tbd_create_cmd_file_create(FILE *stream, return err; uint32_t size = f->size; - if(tbd_write_uint32(size, stream) != 1) + if(!tbd_write_uint32(size, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); FILE *fp = tbd_stat_fopen(f, "rb"); @@ -243,7 +244,7 @@ tbd_create_cmd_file_create(FILE *stream, uintptr_t b = 256; for(b = 256; b == 256; ) { b = fread(buff, 1, b, fp); - if(fwrite(buff, 1, b, stream) != b) { + if(write(stream, buff, b) != b) { fclose(fp); return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); } @@ -273,7 +274,7 @@ tbd_metadata_mask(struct tbd_stat *a, } static int -tbd_create_cmd_file_metadata_update(FILE *stream, +tbd_create_cmd_file_metadata_update(int stream, struct tbd_stat *a, struct tbd_stat *b) { @@ -295,7 +296,7 @@ tbd_create_cmd_file_metadata_update(FILE *stream, } static int -tbd_create_cmd_file_delta(FILE *stream, +tbd_create_cmd_file_delta(int stream, struct tbd_stat *a, struct tbd_stat *b) { @@ -413,10 +414,11 @@ tbd_create_cmd_file_delta(FILE *stream, fclose(fpb); return err; } - if((tbd_write_uint32(start, stream) != 1) || - (tbd_write_uint32(end, stream) != 1) || - (tbd_write_uint32(size, stream) != 1)) { - fclose(fpb); + + if((!tbd_write_uint32(start, stream)) || + (!tbd_write_uint32(end , stream)) || + (!tbd_write_uint32(size , stream))) { + close(fdb); return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); } if(fseek(fpb, start, SEEK_SET) != 0) { @@ -430,7 +432,7 @@ tbd_create_cmd_file_delta(FILE *stream, fclose(fpb); return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } - if(fwrite(buff[0], 1, csize, stream) != csize) { + if(write(stream, buff[0], csize) != csize) { fclose(fpb); return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); } @@ -441,7 +443,7 @@ tbd_create_cmd_file_delta(FILE *stream, } static int -tbd_create_cmd_dir_create(FILE *stream, +tbd_create_cmd_dir_create(int stream, struct tbd_stat *d) { int err; @@ -457,7 +459,7 @@ tbd_create_cmd_dir_create(FILE *stream, } static int -tbd_create_cmd_dir_enter(FILE *stream, +tbd_create_cmd_dir_enter(int stream, const char *name) { int err; @@ -467,7 +469,7 @@ tbd_create_cmd_dir_enter(FILE *stream, } static int -tbd_create_cmd_dir_leave(FILE *stream, +tbd_create_cmd_dir_leave(int stream, struct tbd_stat *dir) { int err; @@ -480,7 +482,7 @@ tbd_create_cmd_dir_leave(FILE *stream, } static int -tbd_create_cmd_entity_delete(FILE *stream, +tbd_create_cmd_entity_delete(int stream, const char *name) { int err; @@ -490,7 +492,7 @@ tbd_create_cmd_entity_delete(FILE *stream, } static int -tbd_create_cmd_dir_delta(FILE *stream, +tbd_create_cmd_dir_delta(int stream, struct tbd_stat *a, struct tbd_stat *b) { @@ -512,7 +514,7 @@ tbd_create_cmd_dir_delta(FILE *stream, } static int -tbd_create_cmd_symlink_create(FILE *stream, +tbd_create_cmd_symlink_create(int stream, struct tbd_stat *symlink) { int err; @@ -536,7 +538,7 @@ tbd_create_cmd_symlink_create(FILE *stream, } static int -tbd_create_cmd_symlink_delta(FILE *stream, +tbd_create_cmd_symlink_delta(int stream, struct tbd_stat *a, struct tbd_stat *b) { @@ -574,7 +576,7 @@ tbd_create_cmd_symlink_delta(FILE *stream, } static int -tbd_create_cmd_special_create(FILE *stream, +tbd_create_cmd_special_create(int stream, struct tbd_stat *nod) { int err; @@ -590,7 +592,7 @@ tbd_create_cmd_special_create(FILE *stream, } static int -tbd_create_cmd_special_delta(FILE *stream, +tbd_create_cmd_special_delta(int stream, struct tbd_stat *a, struct tbd_stat *b) { @@ -610,7 +612,7 @@ tbd_create_cmd_special_delta(FILE *stream, } static int -tbd_create_cmd_socket_create(FILE *stream, +tbd_create_cmd_socket_create(int stream, struct tbd_stat *nod) { (void)stream; @@ -619,7 +621,7 @@ tbd_create_cmd_socket_create(FILE *stream, } static int -tbd_create_cmd_socket_delta(FILE *stream, +tbd_create_cmd_socket_delta(int stream, struct tbd_stat *a, struct tbd_stat *b) { @@ -630,7 +632,7 @@ tbd_create_cmd_socket_delta(FILE *stream, } static int -tbd_create_dir(FILE *stream, +tbd_create_dir(int stream, struct tbd_stat *d) { int err; @@ -675,7 +677,7 @@ tbd_create_dir(FILE *stream, } static int -tbd_create_impl(FILE *stream, +tbd_create_impl(int stream, struct tbd_stat *a, struct tbd_stat *b, bool top) @@ -786,12 +788,12 @@ tbd_create_impl(FILE *stream, } int -tbd_create(FILE *stream, +tbd_create(int stream, struct tbd_stat *a, struct tbd_stat *b) { int err; - if((stream == NULL) || (a == NULL) || (b == NULL)) + if((stream < 0) || (a == NULL) || (b == NULL)) return TBD_ERROR(TBD_ERROR_NULL_POINTER); if((err = tbd_create_cmd_ident(stream)) != 0 || diff --git a/tbdiff/tbdiff-io.c b/tbdiff/tbdiff-io.c index f9324aa..54bcfa7 100644 --- a/tbdiff/tbdiff-io.c +++ b/tbdiff/tbdiff-io.c @@ -15,6 +15,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include #include #include @@ -52,42 +53,43 @@ static inline void endianswap(void* value, size_t size) #define ENDIANSWAP(v) #endif -size_t tbd_write_uint16(uint16_t value, FILE *stream) { +bool tbd_write_uint16(uint16_t value, int stream) { ENDIANSWAP(&value); - return fwrite(&value, sizeof(value), 1, stream); + return (write(stream, &value, sizeof(value)) == sizeof(value)); } -size_t tbd_write_uint32(uint32_t value, FILE *stream) { +bool tbd_write_uint32(uint32_t value, int stream) { ENDIANSWAP(&value); - return fwrite(&value, sizeof(value), 1, stream); + return (write(stream, &value, sizeof(value)) == sizeof(value)); } -size_t tbd_write_uint64(uint64_t value, FILE *stream) { +bool tbd_write_uint64(uint64_t value, int stream) { ENDIANSWAP(&value); - return fwrite(&value, sizeof(value), 1, stream); + return (write(stream, &value, sizeof(value)) == sizeof(value)); } -size_t tbd_write_time(time_t value, FILE *stream) { +bool tbd_write_time(time_t value, int stream) { uint64_t realv = value; ENDIANSWAP(&realv); - return fwrite(&realv, sizeof(realv), 1, stream); + return (write(stream, &realv, sizeof(realv)) == sizeof(value)); } -size_t tbd_write_mode(mode_t value, FILE *stream) { +bool tbd_write_mode(mode_t value, int stream) { ENDIANSWAP(&value); - return fwrite(&value, sizeof(value), 1, stream); + return (write(stream, &value, sizeof(value)) == sizeof(value)); } -size_t tbd_write_uid(uid_t value, FILE *stream) { +bool tbd_write_uid(uid_t value, int stream) { ENDIANSWAP(&value); - return fwrite(&value, sizeof(value), 1, stream); + return (write(stream, &value, sizeof(value)) == sizeof(value)); } -size_t tbd_write_gid(gid_t value, FILE *stream) { +bool tbd_write_gid(gid_t value, int stream) { ENDIANSWAP(&value); - return fwrite(&value, sizeof(value), 1, stream); + return (write(stream, &value, sizeof(value)) == sizeof(value)); } + size_t tbd_read_uint16(uint16_t *value, FILE *stream) { assert(value != NULL); size_t rval = fread(value, sizeof(*value), 1, stream); diff --git a/tbdiff/tbdiff-io.h b/tbdiff/tbdiff-io.h index dc18475..3bb93c6 100644 --- a/tbdiff/tbdiff-io.h +++ b/tbdiff/tbdiff-io.h @@ -22,19 +22,20 @@ #ifndef __TBDIFF_IO_H__ #define __TBDIFF_IO_H__ +#include #include #include #include #include -size_t tbd_write_uint16(uint16_t value, FILE* stream); -size_t tbd_write_uint32(uint32_t value, FILE* stream); -size_t tbd_write_uint64(uint64_t value, FILE* stream); -size_t tbd_write_time(time_t value, FILE* stream); -size_t tbd_write_mode(mode_t value, FILE* stream); -size_t tbd_write_uid(uid_t value, FILE* stream); -size_t tbd_write_gid(gid_t value, FILE* stream); +bool tbd_write_uint16(uint16_t value, int stream); +bool tbd_write_uint32(uint32_t value, int stream); +bool tbd_write_uint64(uint64_t value, int stream); +bool tbd_write_time (time_t value, int stream); +bool tbd_write_mode (mode_t value, int stream); +bool tbd_write_uid (uid_t value, int stream); +bool tbd_write_gid (gid_t value, int stream); size_t tbd_read_uint16(uint16_t *value, FILE* stream); size_t tbd_read_uint32(uint32_t *value, FILE* stream); -- cgit v1.2.1 From 4f69a8fadbd90eb6ff979b6dad57f6de631e3734 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Fri, 30 May 2014 16:57:55 +0100 Subject: Use POSIX file operations internally in tbdiff-create This keeps the code consistent by using the same file functions internally as are used when reading from or writing to the stream. The code is also simplified somewhat since POSIX file operations are cleaner and more consistent than stdio. --- tbdiff/tbdiff-create.c | 76 +++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/tbdiff/tbdiff-create.c b/tbdiff/tbdiff-create.c index 1f0312a..0c5823d 100644 --- a/tbdiff/tbdiff-create.c +++ b/tbdiff/tbdiff-create.c @@ -16,13 +16,13 @@ */ #include -#include #include #include #include #include #include +#include #include #include "tbdiff-common.h" @@ -236,20 +236,20 @@ tbd_create_cmd_file_create(int stream, if(!tbd_write_uint32(size, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); - FILE *fp = tbd_stat_fopen(f, "rb"); - if(fp == NULL) + int fd = tbd_stat_open(f, O_RDONLY); + if(fd < 0) return TBD_ERROR(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING); uint8_t buff[256]; uintptr_t b = 256; for(b = 256; b == 256; ) { - b = fread(buff, 1, b, fp); + b = read(fd, buff, b); if(write(stream, buff, b) != b) { - fclose(fp); + close(fd); return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); } } - fclose(fp); + close(fd); return tbd_create_cmd_write_xattrs(stream, f); } @@ -300,12 +300,12 @@ tbd_create_cmd_file_delta(int stream, struct tbd_stat *a, struct tbd_stat *b) { - FILE *fpa = tbd_stat_fopen(a, "rb"); - if(fpa == NULL) + int fda = tbd_stat_open(a, O_RDONLY); + if(fda < 0) return TBD_ERROR(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING); - FILE *fpb = tbd_stat_fopen(b, "rb"); - if(fpb == NULL) { - fclose(fpa); + int fdb = tbd_stat_open(b, O_RDONLY); + if(fdb < 0) { + close(fda); return TBD_ERROR(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING); } @@ -315,8 +315,8 @@ tbd_create_cmd_file_delta(int stream, uintptr_t o; for(o = 0; (blks[1] == blks[0]) && (blks[0] != 0); o += blks[1]) { - blks[0] = fread(buff[0], 1, blks[0], fpa); - blks[1] = fread(buff[1], 1, blks[0], fpb); + blks[0] = read(fda, buff[0], blks[0]); + blks[1] = read(fdb, buff[1], blks[0]); if((blks[0] == 0) || (blks[1] == 0)) break; @@ -332,20 +332,14 @@ tbd_create_cmd_file_delta(int stream, } uint32_t start = o; - if((fseek(fpa, 0, SEEK_END) != 0) || (fseek(fpb, 0, SEEK_END) != 0)) { - fclose(fpa); - fclose(fpb); - return TBD_ERROR(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM); - } - /* Find length. */ - long flena = ftell(fpa); - long flenb = ftell(fpb); + off_t flena = lseek(fda, 0, SEEK_END); + off_t flenb = lseek(fdb, 0, SEEK_END); if((flena < 0) || (flenb < 0)) { - fclose(fpa); - fclose(fpb); - return TBD_ERROR(TBD_ERROR_UNABLE_TO_DETECT_STREAM_POSITION); + close(fda); + close(fdb); + return TBD_ERROR(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM); } /* Find end. */ @@ -357,17 +351,17 @@ tbd_create_cmd_file_delta(int stream, if((blks[0] == 0) || (blks[1] == 0)) break; - if((fseek(fpa, flena - (o + blks[0]), SEEK_SET) != 0) - || (fseek(fpb, flenb - (o + blks[1]), SEEK_SET) != 0)) { - fclose(fpa); - fclose(fpb); + if((lseek(fda, flena - (o + blks[0]), SEEK_SET) < 0) + || (lseek(fdb, flenb - (o + blks[1]), SEEK_SET) < 0)) { + close(fda); + close(fdb); return TBD_ERROR(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM); } - if((fread(buff[0], 1, blks[0], fpa) != blks[0]) - || (fread(buff[1], 1, blks[1], fpb) != blks[1])) { - fclose(fpa); - fclose(fpb); + if((read(fda, buff[0], blks[0]) != blks[0]) + || (read(fdb, buff[1], blks[1]) != blks[1])) { + close(fda); + close(fdb); return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } @@ -381,7 +375,7 @@ tbd_create_cmd_file_delta(int stream, if(i < blks[1]) break; } - fclose(fpa); + close(fda); /* Ensure that the start and end don't overlap for the new file. */ if((flenb - o) < start) @@ -396,7 +390,7 @@ tbd_create_cmd_file_delta(int stream, /* Data is identical, only alter metadata */ if((end == start) && (size == 0)) { tbd_create_cmd_file_metadata_update(stream, a, b); - fclose(fpb); + close(fdb); return tbd_create_cmd_write_xattrs(stream, b); } @@ -411,7 +405,7 @@ tbd_create_cmd_file_delta(int stream, ((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); + close(fdb); return err; } @@ -421,24 +415,24 @@ tbd_create_cmd_file_delta(int stream, close(fdb); return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); } - if(fseek(fpb, start, SEEK_SET) != 0) { - fclose(fpb); + if(lseek(fdb, start, SEEK_SET) < 0) { + close(fdb); return TBD_ERROR(TBD_ERROR_UNABLE_TO_SEEK_THROUGH_STREAM); } for(o = 0; o < size; o += 256) { uintptr_t csize = ((size - o) > 256 ? 256 : (size - o)); - if(fread(buff[0], 1, csize, fpb) != csize) { - fclose(fpb); + if(read(fdb, buff[0], csize) != csize) { + close(fdb); return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } if(write(stream, buff[0], csize) != csize) { - fclose(fpb); + close(fdb); return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); } } - fclose(fpb); + close(fdb); return tbd_create_cmd_write_xattrs(stream, b); } -- cgit v1.2.1 From cbe6a4f51bc27c4e8a81f89876c3ae469c8bf67e Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Fri, 30 May 2014 16:59:48 +0100 Subject: Remove tbd_stat_fopen since it's no longer used Since we now use POSIX file functions only in tbdiff-create, we no longer need tbd_stat_fopen, so it's been removed. --- tbdiff/tbdiff-stat.c | 12 ------------ tbdiff/tbdiff-stat.h | 1 - 2 files changed, 13 deletions(-) diff --git a/tbdiff/tbdiff-stat.c b/tbdiff/tbdiff-stat.c index b0876ec..aabf237 100644 --- a/tbdiff/tbdiff-stat.c +++ b/tbdiff/tbdiff-stat.c @@ -258,15 +258,3 @@ tbd_stat_open(struct tbd_stat *file, int flags) free(path); return fd; } - -FILE* -tbd_stat_fopen(struct tbd_stat *file, - const char *mode) -{ - char *path = tbd_stat_path(file); - if(path == NULL) - return NULL; - FILE *fp = fopen(path, mode); - free(path); - return fp; -} diff --git a/tbdiff/tbdiff-stat.h b/tbdiff/tbdiff-stat.h index 6f4c93e..b8dd9b6 100644 --- a/tbdiff/tbdiff-stat.h +++ b/tbdiff/tbdiff-stat.h @@ -57,6 +57,5 @@ struct tbd_stat* tbd_stat_entry_find(struct tbd_stat *file, const char *name); char* tbd_statubpath(struct tbd_stat *file, const char *entry); char* tbd_stat_path(struct tbd_stat *file); int tbd_stat_open(struct tbd_stat *file, int flags); -FILE* tbd_stat_fopen(struct tbd_stat *file, const char *mode); #endif /* !__TBDIFF_STAT_H__ */ -- cgit v1.2.1 From 2d580135f11a1e705949b7fcf69486bacbca5587 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Fri, 30 May 2014 17:22:53 +0100 Subject: Use POSIX file operations for tbdiff-apply For the consistency reasons listed in earlier commits. --- tbdiff-deploy/main.c | 9 +-- tbdiff/tbdiff-apply.c | 155 +++++++++++++++++++++++++------------------------ tbdiff/tbdiff-common.h | 2 +- tbdiff/tbdiff-io.c | 56 +++++++++++------- tbdiff/tbdiff-io.h | 14 ++--- 5 files changed, 126 insertions(+), 110 deletions(-) diff --git a/tbdiff-deploy/main.c b/tbdiff-deploy/main.c index b5b7ce9..3f7691c 100644 --- a/tbdiff-deploy/main.c +++ b/tbdiff-deploy/main.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -33,19 +34,19 @@ main(int argc, return EXIT_FAILURE; } - FILE* patch = fopen(argv[1], "rb"); - if(patch == NULL) { + int patch = open(argv[1], O_RDONLY); + if(patch < 0) { fprintf(stderr, "Error: Can't open patch stream for reading.\n"); return EXIT_FAILURE; } int err; if((err = tbd_apply(patch)) != 0) { - fclose(patch); + close(patch); fprintf(stderr, "Error: Error applying patch stream (err=%d).\n", err); return EXIT_FAILURE; } - fclose(patch); + close(patch); return EXIT_SUCCESS; } diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index 5281c37..461ac3f 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -43,13 +43,13 @@ #include "tbdiff-xattrs.h" char* -tbd_apply_read_string(FILE *stream) +tbd_apply_read_string(int stream) { uint16_t dlen; - if(tbd_read_uint16(&dlen, stream) != 1) + if(!tbd_read_uint16(&dlen, stream)) return NULL; char dname[dlen + 1]; - if(fread(dname, 1, dlen, stream) != dlen) + if(read(stream, dname, dlen) != dlen) return NULL; dname[dlen] = '\0'; @@ -67,11 +67,11 @@ tbd_apply_read_string(FILE *stream) * - or your allocator does nothing when asked to free non-allocated memory */ int -tbd_apply_read_block(FILE *stream, void **data, size_t *size) +tbd_apply_read_block(int stream, void **data, size_t *size) { { size_t _size; - if (fread(&_size, 1, sizeof(_size), stream) != sizeof(_size) ) { + if (read(stream, &_size, sizeof(_size)) != sizeof(_size) ) { return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } if (_size > *size) { @@ -84,27 +84,27 @@ tbd_apply_read_block(FILE *stream, void **data, size_t *size) } } - if (fread(*data, 1, *size, stream) != *size) { + if (read(stream, *data, *size) != *size) { return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } return TBD_ERROR_SUCCESS; } static int -tbd_apply_identify(FILE *stream) +tbd_apply_identify(int stream) { tbd_cmd_type cmd; - if(fread(&cmd, sizeof(tbd_cmd_type), 1, stream) != 1) + if(read(stream, &cmd, sizeof(tbd_cmd_type)) != sizeof(tbd_cmd_type)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); if(cmd != TBD_CMD_IDENTIFY) return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); uint16_t nlen; - if(tbd_read_uint16(&nlen, stream) != 1) + if(!tbd_read_uint16(&nlen, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); if(strlen(TB_DIFF_PROTOCOL_ID) != nlen) return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); char nstr[nlen]; - if(fread(nstr, 1, nlen, stream) != nlen) + if(read(stream, nstr, nlen) != nlen) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); if(strncmp(nstr, TB_DIFF_PROTOCOL_ID, nlen) != 0) return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); @@ -112,13 +112,13 @@ tbd_apply_identify(FILE *stream) } static int -tbd_apply_cmd_dir_create(FILE *stream) +tbd_apply_cmd_dir_create(int stream) { uint16_t dlen; - if(tbd_read_uint16(&dlen, stream) != 1) + if(!tbd_read_uint16(&dlen, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char dname[dlen + 1]; - if(fread(dname, 1, dlen, stream) != dlen) + if(read(stream, dname, dlen) != dlen) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); dname[dlen] = '\0'; TBD_DEBUGF("cmd_dir_create %s\n", dname); @@ -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(&mtime, stream) != 1) + if(!tbd_read_time(&mtime, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); uid_t uid; - if(tbd_read_uid(&uid, stream) != 1) + if(!tbd_read_uid(&uid, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); gid_t gid; - if(tbd_read_gid(&gid, stream) != 1) + if(!tbd_read_gid(&gid, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); mode_t mode; - if(tbd_read_mode(&mode, stream) != 1) + if(!tbd_read_mode(&mode, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); if(mkdir(dname, (mode_t)mode) != 0) @@ -156,14 +156,14 @@ tbd_apply_cmd_dir_create(FILE *stream) } static int -tbd_apply_cmd_dir_enter(FILE *stream, +tbd_apply_cmd_dir_enter(int stream, uintptr_t *depth) { uint16_t dlen; - if(tbd_read_uint16(&dlen, stream) != 1) + if(!tbd_read_uint16(&dlen, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char dname[dlen + 1]; - if(fread(dname, 1, dlen, stream) != dlen) + if(read(stream, dname, dlen) != dlen) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); dname[dlen] = '\0'; TBD_DEBUGF("cmd_dir_enter %s\n", dname); @@ -178,13 +178,13 @@ tbd_apply_cmd_dir_enter(FILE *stream, } static int -tbd_apply_cmd_dir_leave(FILE *stream, +tbd_apply_cmd_dir_leave(int stream, uintptr_t *depth) { int err = TBD_ERROR_SUCCESS; struct utimbuf time; - if (tbd_read_time(&(time.modtime), stream) != 1) { + if (!tbd_read_time(&(time.modtime), stream)) { return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } time.actime = time.modtime;/* not sure what the best atime to use is */ @@ -212,13 +212,13 @@ tbd_apply_cmd_dir_leave(FILE *stream, } static int -tbd_apply_cmd_file_create(FILE *stream) +tbd_apply_cmd_file_create(int stream) { uint16_t flen; - if(tbd_read_uint16(&flen, stream) != 1) + if(!tbd_read_uint16(&flen, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char fname[flen + 1]; - if(fread(fname, 1, flen, stream) != flen) + if(read(stream, fname, flen) != flen) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); fname[flen] = '\0'; if((strchr(fname, '/') != NULL) || (strcmp(fname, "..") == 0)) @@ -230,11 +230,11 @@ tbd_apply_cmd_file_create(FILE *stream) gid_t gid; uint32_t fsize; - 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) + if(!tbd_read_time (&mtime, stream) || + !tbd_read_uint32(&mode , stream) || + !tbd_read_uid (&uid , stream) || + !tbd_read_gid (&gid , stream) || + !tbd_read_uint32(&fsize, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); TBD_DEBUGF("cmd_file_create %s:%"PRId32"\n", fname, fsize); @@ -254,7 +254,7 @@ 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(read(stream, fbuff, block) != block) { fclose(fp); return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } @@ -279,7 +279,7 @@ tbd_apply_cmd_file_create(FILE *stream) } static int -tbd_apply_cmd_file_delta(FILE *stream) +tbd_apply_cmd_file_delta(int stream) { uint16_t mdata_mask; time_t mtime; @@ -289,10 +289,10 @@ tbd_apply_cmd_file_delta(FILE *stream) uint16_t flen; int error; - if(tbd_read_uint16(&flen, stream) != 1) + if(!tbd_read_uint16(&flen, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char fname[flen + 1]; - if(fread(fname, 1, flen, stream) != flen) + if(read(stream, fname, flen) != flen) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); fname[flen] = '\0'; @@ -303,11 +303,11 @@ tbd_apply_cmd_file_delta(FILE *stream) return TBD_ERROR(TBD_ERROR_INVALID_PARAMETER); /* Reading metadata */ - 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) + if(!tbd_read_uint16(&mdata_mask, stream) || + !tbd_read_time (&mtime , stream) || + !tbd_read_uid (&uid , stream) || + !tbd_read_gid (&gid , stream) || + !tbd_read_uint32(&mode , stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); FILE *op = fopen(fname, "rb"); @@ -324,11 +324,11 @@ tbd_apply_cmd_file_delta(FILE *stream) } uint32_t dstart, dend; - if(tbd_read_uint32(&dstart, stream) != 1) { + if(!tbd_read_uint32(&dstart, stream)) { error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); goto tbd_apply_cmd_file_delta_error; } - if(tbd_read_uint32(&dend, stream) != 1) { + if(!tbd_read_uint32(&dend, stream)) { error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); goto tbd_apply_cmd_file_delta_error; } @@ -349,7 +349,7 @@ tbd_apply_cmd_file_delta(FILE *stream) } uint32_t fsize; - if(tbd_read_uint32(&fsize, stream) != 1) { + if(!tbd_read_uint32(&fsize, stream)) { error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); goto tbd_apply_cmd_file_delta_error; } @@ -357,7 +357,7 @@ tbd_apply_cmd_file_delta(FILE *stream) for(block = 256; fsize != 0; fsize -= block) { if(fsize < block) block = fsize; - if(fread(fbuff, 1, block, stream) != block) { + if(read(stream, fbuff, block) != block) { error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); goto tbd_apply_cmd_file_delta_error; } @@ -477,13 +477,13 @@ tbd_apply_cmd_entity_delete_for_name(const char *name) } static int -tbd_apply_cmd_entity_delete(FILE *stream) +tbd_apply_cmd_entity_delete(int stream) { uint16_t elen; - if(tbd_read_uint16(&elen, stream) != 1) + if(!tbd_read_uint16(&elen, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char ename[elen + 1]; - if(fread(ename, 1, elen, stream) != elen) + if(read(stream, ename, elen) != elen) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); ename[elen] = '\0'; @@ -495,34 +495,34 @@ tbd_apply_cmd_entity_delete(FILE *stream) } static int -tbd_apply_cmd_symlink_create(FILE *stream) +tbd_apply_cmd_symlink_create(int stream) { uint16_t len; time_t mtime; uid_t uid; gid_t gid; - if(tbd_read_time(&mtime, stream) != 1 || - tbd_read_uid(&uid , stream) != 1 || - tbd_read_gid(&gid , stream) != 1) + if(!tbd_read_time(&mtime, stream) || + !tbd_read_uid (&uid , stream) || + !tbd_read_gid (&gid , stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); /* Reading link file name */ - if(tbd_read_uint16(&len, stream) != 1) + if(!tbd_read_uint16(&len, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char linkname[len + 1]; linkname[len] = '\0'; - if(fread(linkname, sizeof(char), len, stream) != len) + if(read(stream, linkname, len) != len) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); /* Reading target path */ - if(tbd_read_uint16(&len, stream) != 1) + if(!tbd_read_uint16(&len, stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char linkpath[len+1]; linkpath[len] = '\0'; - if(fread(linkpath, sizeof(char), len, stream) != len) + if(read(stream, linkpath, len) != len) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); TBD_DEBUGF("cmd_symlink_create %s -> %s\n", linkname, linkpath); @@ -543,7 +543,7 @@ tbd_apply_cmd_symlink_create(FILE *stream) } static int -tbd_apply_cmd_special_create(FILE *stream) +tbd_apply_cmd_special_create(int stream) { char *name = tbd_apply_read_string(stream); time_t mtime; @@ -553,11 +553,11 @@ tbd_apply_cmd_special_create(FILE *stream) uint32_t dev; if(name == NULL || - 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) { + !tbd_read_time (&mtime, stream) || + !tbd_read_mode (&mode , stream) || + !tbd_read_uid (&uid , stream) || + !tbd_read_gid (&gid , stream) || + !tbd_read_uint32(&dev , stream)) { free(name); return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } @@ -581,7 +581,7 @@ tbd_apply_cmd_special_create(FILE *stream) } static int -tbd_apply_cmd_dir_delta(FILE *stream) +tbd_apply_cmd_dir_delta(int stream) { uint16_t metadata_mask; time_t mtime; @@ -589,11 +589,11 @@ tbd_apply_cmd_dir_delta(FILE *stream) gid_t gid; mode_t mode; - 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) + if(!tbd_read_uint16(&metadata_mask, stream) || + !tbd_read_time (&mtime , stream) || + !tbd_read_uid (&uid , stream) || + !tbd_read_gid (&gid , stream) || + !tbd_read_uint32(&mode , stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char *dname = tbd_apply_read_string(stream); @@ -618,7 +618,7 @@ tbd_apply_cmd_dir_delta(FILE *stream) } static int -tbd_apply_cmd_file_mdata_update(FILE *stream) +tbd_apply_cmd_file_mdata_update(int stream) { uint16_t metadata_mask; time_t mtime; @@ -626,11 +626,11 @@ tbd_apply_cmd_file_mdata_update(FILE *stream) gid_t gid; mode_t mode; - 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) + if(!tbd_read_uint16(&metadata_mask, stream) || + !tbd_read_time (&mtime , stream) || + !tbd_read_uid (&uid , stream) || + !tbd_read_gid (&gid , stream) || + !tbd_read_uint32(&mode , stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); char *dname = tbd_apply_read_string(stream); @@ -656,7 +656,7 @@ tbd_apply_cmd_file_mdata_update(FILE *stream) } static int -tbd_apply_cmd_xattrs_update(FILE *stream) +tbd_apply_cmd_xattrs_update(int stream) { int err = TBD_ERROR_SUCCESS; char *fname; @@ -674,7 +674,7 @@ tbd_apply_cmd_xattrs_update(FILE *stream) } /* read how many attributes to process */ - if (tbd_read_uint32(&count, stream) != 1) { + if (!tbd_read_uint32(&count, stream)) { err = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); goto cleanup; } @@ -709,9 +709,9 @@ cleanup: } int -tbd_apply(FILE *stream) +tbd_apply(int stream) { - if(stream == NULL) + if(stream < 0) return TBD_ERROR(TBD_ERROR_NULL_POINTER); int err; @@ -722,7 +722,8 @@ tbd_apply(FILE *stream) bool flush = false; while(!flush) { tbd_cmd_type cmd; - if(fread(&cmd, sizeof(tbd_cmd_type), 1, stream) != 1) + if(read(stream, &cmd, sizeof(tbd_cmd_type)) != + sizeof(tbd_cmd_type)) 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 9b5b5f3..8a5c889 100644 --- a/tbdiff/tbdiff-common.h +++ b/tbdiff/tbdiff-common.h @@ -126,7 +126,7 @@ tbd_error(enum tbd_error e, char const *s, char const *func, int line, } #endif -int tbd_apply (FILE *stream); +int tbd_apply (int stream); int tbd_create(int stream, struct tbd_stat *a, struct tbd_stat *b); #endif /* !__TBDIFF_COMMON_H__ */ diff --git a/tbdiff/tbdiff-io.c b/tbdiff/tbdiff-io.c index 54bcfa7..8ad0235 100644 --- a/tbdiff/tbdiff-io.c +++ b/tbdiff/tbdiff-io.c @@ -90,53 +90,67 @@ bool tbd_write_gid(gid_t value, int stream) { } -size_t tbd_read_uint16(uint16_t *value, FILE *stream) { +bool tbd_read_uint16(uint16_t *value, int stream) { assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); + size_t rval = read(stream, value, sizeof(*value)); + if (rval != sizeof(*value)) + return false; ENDIANSWAP(value); - return rval; + return true; } -size_t tbd_read_uint32(uint32_t *value, FILE *stream) { +bool tbd_read_uint32(uint32_t *value, int stream) { assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); + size_t rval = read(stream, value, sizeof(*value)); + if (rval != sizeof(*value)) + return false; ENDIANSWAP(value); - return rval; + return true; } -size_t tbd_read_uint64(uint64_t *value, FILE *stream) { +bool tbd_read_uint64(uint64_t *value, int stream) { assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); + size_t rval = read(stream, value, sizeof(*value)); + if (rval != sizeof(*value)) + return false; ENDIANSWAP(value); - return rval; + return true; } -size_t tbd_read_time(time_t *value, FILE *stream) { +bool tbd_read_time(time_t *value, int stream) { assert(value != NULL); uint64_t realv; - size_t rval = fread(&realv, sizeof(realv), 1, stream); + size_t rval = read(stream, &realv, sizeof(realv)); + if (rval != sizeof(*value)) + return false; ENDIANSWAP(&realv); *value = realv; - return rval; + return true; } -size_t tbd_read_mode(mode_t *value, FILE *stream) { +bool tbd_read_mode(mode_t *value, int stream) { assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); + ssize_t rval = read(stream, value, sizeof(*value)); + if (rval != sizeof(*value)) + return false; ENDIANSWAP(value); - return rval; + return true; } -size_t tbd_read_uid(uid_t *value, FILE *stream) { +bool tbd_read_uid(uid_t *value, int stream) { assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); + size_t rval = read(stream, value, sizeof(*value)); + if (rval != sizeof(*value)) + return false; ENDIANSWAP(value); - return rval; + return true; } -size_t tbd_read_gid(gid_t *value, FILE *stream) { +bool tbd_read_gid(gid_t *value, int stream) { assert(value != NULL); - size_t rval = fread(value, sizeof(*value), 1, stream); + size_t rval = read(stream, value, sizeof(*value)); + if (rval != sizeof(*value)) + return false; ENDIANSWAP(value); - return rval; + return true; } diff --git a/tbdiff/tbdiff-io.h b/tbdiff/tbdiff-io.h index 3bb93c6..f5bb5e5 100644 --- a/tbdiff/tbdiff-io.h +++ b/tbdiff/tbdiff-io.h @@ -37,12 +37,12 @@ bool tbd_write_mode (mode_t value, int stream); bool tbd_write_uid (uid_t value, int stream); bool tbd_write_gid (gid_t value, int stream); -size_t tbd_read_uint16(uint16_t *value, FILE* stream); -size_t tbd_read_uint32(uint32_t *value, FILE* stream); -size_t tbd_read_uint64(uint64_t *value, FILE* stream); -size_t tbd_read_time(time_t *value, FILE* stream); -size_t tbd_read_mode(mode_t *value, FILE* stream); -size_t tbd_read_uid(uid_t *value, FILE* stream); -size_t tbd_read_gid(gid_t *value, FILE* stream); +bool tbd_read_uint16(uint16_t *value, int stream); +bool tbd_read_uint32(uint32_t *value, int stream); +bool tbd_read_uint64(uint64_t *value, int stream); +bool tbd_read_time (time_t *value, int stream); +bool tbd_read_mode (mode_t *value, int stream); +bool tbd_read_uid (uid_t *value, int stream); +bool tbd_read_gid (gid_t *value, int stream); #endif /* !__TBDIFF_IO_H__ */ -- cgit v1.2.1 From 49fad34754c669cfbc95d0fe4a3f562138cc7460 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Fri, 30 May 2014 17:57:07 +0100 Subject: Use POSIX file operations internally in tbdiff-apply For consistency reasons and because the POSIX functions are more consistent and simple, this also allows us to set the mode on file creation and detect if a file already exists. --- tbdiff/tbdiff-apply.c | 57 +++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c index 461ac3f..615032f 100644 --- a/tbdiff/tbdiff-apply.c +++ b/tbdiff/tbdiff-apply.c @@ -16,7 +16,6 @@ */ #include -#include #include #include #include @@ -26,9 +25,12 @@ #include #include #include +#include #include #include +#include + #include "config.h" #if HAVE_ATTR_XATTR_H @@ -239,15 +241,12 @@ tbd_apply_cmd_file_create(int stream) TBD_DEBUGF("cmd_file_create %s:%"PRId32"\n", fname, fsize); - FILE *fp = fopen(fname, "rb"); - if(fp != NULL) { - fclose(fp); - return TBD_ERROR(TBD_ERROR_FILE_ALREADY_EXISTS); - } - - fp = fopen(fname, "wb"); - if(fp == NULL) + int fd = open(fname, O_WRONLY | O_CREAT | O_EXCL, mode); + if(fd < 0) { + if (errno == EEXIST) + return TBD_ERROR(TBD_ERROR_FILE_ALREADY_EXISTS); return TBD_ERROR(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_WRITING); + } uintptr_t block = 256; uint8_t fbuff[block]; @@ -255,15 +254,15 @@ tbd_apply_cmd_file_create(int stream) if(fsize < block) block = fsize; if(read(stream, fbuff, block) != block) { - fclose(fp); + close(fd); return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); } - if(fwrite(fbuff, 1, block, fp) != block) { - fclose(fp); + if(write(fd, fbuff, block) != block) { + close(fd); return TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); } } - fclose(fp); + close(fd); /* Apply metadata. */ struct utimbuf timebuff = { time(NULL), mtime }; @@ -310,16 +309,16 @@ tbd_apply_cmd_file_delta(int stream) !tbd_read_uint32(&mode , stream)) return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); - FILE *op = fopen(fname, "rb"); - if(op == NULL) + int od = open(fname, O_RDONLY); + if(od < 0) return TBD_ERROR(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_READING); if(remove(fname) != 0) { - fclose(op); + close(od); return TBD_ERROR(TBD_ERROR_UNABLE_TO_REMOVE_FILE); } - FILE *np = fopen(fname, "wb"); - if(np == NULL) { - fclose(op); + int nd = open(fname, O_WRONLY | O_CREAT, mode); + if(nd < 0) { + close(od); return TBD_ERROR(TBD_ERROR_UNABLE_TO_OPEN_FILE_FOR_WRITING); } @@ -338,11 +337,11 @@ tbd_apply_cmd_file_delta(int stream) for(block = 256; dstart != 0; dstart -= block) { if(dstart < block) block = dstart; - if(fread(fbuff, 1, block, op) != block) { + if(read(od, fbuff, block) != block) { error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); goto tbd_apply_cmd_file_delta_error; } - if(fwrite(fbuff, 1, block, np) != block) { + if(write(nd, fbuff, block) != block) { error = TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); goto tbd_apply_cmd_file_delta_error; } @@ -361,27 +360,27 @@ tbd_apply_cmd_file_delta(int stream) error = TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_STREAM); goto tbd_apply_cmd_file_delta_error; } - if(fwrite(fbuff, 1, block, np) != block) { + if(write(nd, fbuff, block) != block) { error = TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); goto tbd_apply_cmd_file_delta_error; } } - if(fseek(op, dend, SEEK_SET) != 0) { + if(lseek(od, dend, SEEK_SET) < 0) { 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) { + block = read(od, fbuff, block); + if(write(nd, fbuff, block) != block) { error = TBD_ERROR(TBD_ERROR_UNABLE_TO_WRITE_STREAM); goto tbd_apply_cmd_file_delta_error; } } - fclose(np); - fclose(op); + close(nd); + close(od); /* Apply metadata. */ /* file was removed so old permissions were lost @@ -410,8 +409,8 @@ tbd_apply_cmd_file_delta(int stream) return 0; tbd_apply_cmd_file_delta_error: - fclose(np); - fclose(op); + close(nd); + close(od); return error; } -- cgit v1.2.1 From 73162c1f05f82a493f38dee2c8296c5a70efa1b8 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Mon, 2 Jun 2014 10:32:00 +0100 Subject: Remove tbd_stat_print since it's unused and unimplemented --- tbdiff/tbdiff-stat.c | 6 ------ tbdiff/tbdiff-stat.h | 1 - 2 files changed, 7 deletions(-) diff --git a/tbdiff/tbdiff-stat.c b/tbdiff/tbdiff-stat.c index aabf237..4d20481 100644 --- a/tbdiff/tbdiff-stat.c +++ b/tbdiff/tbdiff-stat.c @@ -108,12 +108,6 @@ tbd_stat_free(struct tbd_stat *file) free(file); } -void -tbd_stat_print(struct tbd_stat *file) -{ - (void)file; -} - struct tbd_stat* tbd_stat_entry(struct tbd_stat *file, uint32_t entry) { diff --git a/tbdiff/tbdiff-stat.h b/tbdiff/tbdiff-stat.h index b8dd9b6..5f9af83 100644 --- a/tbdiff/tbdiff-stat.h +++ b/tbdiff/tbdiff-stat.h @@ -51,7 +51,6 @@ struct tbd_stat { struct tbd_stat* tbd_stat(const char *path); void tbd_stat_free(struct tbd_stat *file); -void tbd_stat_print(struct tbd_stat *file); struct tbd_stat* tbd_stat_entry(struct tbd_stat *file, uint32_t entry); struct tbd_stat* tbd_stat_entry_find(struct tbd_stat *file, const char *name); char* tbd_statubpath(struct tbd_stat *file, const char *entry); -- cgit v1.2.1 From c78b85020bc7337493b259694239ea64ace8b44e Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Mon, 2 Jun 2014 10:54:47 +0100 Subject: Print usage in tbdiff-deploy when it's used incorrectly --- tbdiff-deploy/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tbdiff-deploy/main.c b/tbdiff-deploy/main.c index 3f7691c..283c5b4 100644 --- a/tbdiff-deploy/main.c +++ b/tbdiff-deploy/main.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 @@ -25,12 +25,19 @@ #include +static void +print_usage(const char *name) +{ + printf("Usage: %s \n", name); +} + int main(int argc, char **argv) { if(argc < 2) { fprintf(stderr, "Error: No patch stream specified.\n"); + print_usage(argv[0]); return EXIT_FAILURE; } -- cgit v1.2.1 From 1de58f93e1b19442d40badde4b68fc34bb08f386 Mon Sep 17 00:00:00 2001 From: Ben Brewer Date: Mon, 2 Jun 2014 10:56:01 +0100 Subject: Print errno when tbdiff-deploy fails to open stream --- tbdiff-deploy/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tbdiff-deploy/main.c b/tbdiff-deploy/main.c index 283c5b4..228a753 100644 --- a/tbdiff-deploy/main.c +++ b/tbdiff-deploy/main.c @@ -43,7 +43,9 @@ main(int argc, int patch = open(argv[1], O_RDONLY); if(patch < 0) { - fprintf(stderr, "Error: Can't open patch stream for reading.\n"); + fprintf(stderr, + "Error: Can't open patch stream for reading (err=%d).\n", + errno); return EXIT_FAILURE; } -- cgit v1.2.1