summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tbdiff-create/main.c4
-rw-r--r--tbdiff/tbdiff-apply.c8
-rw-r--r--tbdiff/tbdiff-common.h20
-rw-r--r--tbdiff/tbdiff-create.c100
-rw-r--r--tbdiff/tbdiff-stat.c59
-rw-r--r--tbdiff/tbdiff-stat.h44
-rw-r--r--tbdiff/tbdiff-xattrs.c26
-rw-r--r--tbdiff/tbdiff-xattrs.h19
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 <tbdiff/tbdiff-stat.h>
-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 <tbdiff/tbdiff-stat.h>
-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 <stdbool.h>
#include <sys/types.h>
-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 <tbdiff/tbdiff-common.h>
#include <tbdiff/tbdiff-xattrs.h>
-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, &params);
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 <stdint.h>
/* 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__ */