From c58c1dc44601db434a9fdfa923d1b123dc9a0f25 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Sat, 16 Dec 2006 07:18:41 +0000 Subject: [PATCH] Added a basename var to file_struct at the end, making it clearer where the basename exists without actually changing how the data is organized. --- flist.c | 18 +++++++++--------- generator.c | 8 ++++---- rsync.h | 13 ++++++------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/flist.c b/flist.c index 3dadeab4..11bd2598 100644 --- a/flist.c +++ b/flist.c @@ -740,7 +740,7 @@ static struct file_struct *recv_file_entry(struct file_list *flist, #ifdef SUPPORT_LINKS if (linkname_len) { - bp = (char*)F_BASENAME(file) + basename_len; + bp = (char*)file->basename + basename_len; if (first_hlink_ndx >= 0) { struct file_struct *first = flist->files[first_hlink_ndx]; memcpy(bp, F_SYMLINK(first), linkname_len); @@ -997,7 +997,7 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, #ifdef SUPPORT_LINKS if (linkname_len) { - bp = (char*)F_BASENAME(file) + basename_len; + bp = (char*)file->basename + basename_len; memcpy(bp, linkname, linkname_len); } #endif @@ -1795,7 +1795,7 @@ static void output_flist(struct file_list *flist) dir = slash = ""; else slash = "/"; - name = F_BASENAME(file); + name = file->basename; trail = S_ISDIR(file->mode) ? "/" : ""; } else dir = slash = name = trail = ""; @@ -1846,7 +1846,7 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2) c1 = c2 = NULL; if (!c1) { type1 = S_ISDIR(f1->mode) ? t_path : t_ITEM; - c1 = (uchar*)F_BASENAME(f1); + c1 = (const uchar*)f1->basename; if (type1 == t_PATH && *c1 == '.' && !c1[1]) { type1 = t_ITEM; state1 = s_TRAILING; @@ -1859,7 +1859,7 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2) } if (!c2) { type2 = S_ISDIR(f2->mode) ? t_path : t_ITEM; - c2 = (uchar*)F_BASENAME(f2); + c2 = (const uchar*)f2->basename; if (type2 == t_PATH && *c2 == '.' && !c2[1]) { type2 = t_ITEM; state2 = s_TRAILING; @@ -1883,7 +1883,7 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2) break; case s_SLASH: type1 = S_ISDIR(f1->mode) ? t_path : t_ITEM; - c1 = (uchar*)F_BASENAME(f1); + c1 = (const uchar*)f1->basename; if (type1 == t_PATH && *c1 == '.' && !c1[1]) { type1 = t_ITEM; state1 = s_TRAILING; @@ -1913,7 +1913,7 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2) break; case s_SLASH: type2 = S_ISDIR(f2->mode) ? t_path : t_ITEM; - c2 = (uchar*)F_BASENAME(f2); + c2 = (const uchar*)f2->basename; if (type2 == t_PATH && *c2 == '.' && !c2[1]) { type2 = t_ITEM; state2 = s_TRAILING; @@ -1968,9 +1968,9 @@ char *f_name(struct file_struct *f, char *fbuf) int len = strlen(f->dirname); memcpy(fbuf, f->dirname, len); fbuf[len] = '/'; - strlcpy(fbuf + len + 1, F_BASENAME(f), MAXPATHLEN - (len + 1)); + strlcpy(fbuf + len + 1, f->basename, MAXPATHLEN - (len + 1)); } else - strlcpy(fbuf, F_BASENAME(f), MAXPATHLEN); + strlcpy(fbuf, f->basename, MAXPATHLEN); return fbuf; } diff --git a/generator.c b/generator.c index 55f0e4a5..43bc4113 100644 --- a/generator.c +++ b/generator.c @@ -248,7 +248,7 @@ static enum delret delete_dir_contents(char *fname, int flags) continue; } - strlcpy(p, F_BASENAME(fp), remainder); + strlcpy(p, fp->basename, remainder); /* Save stack by recursing to ourself directly. */ if (S_ISDIR(fp->mode) && delete_dir_contents(fname, flags | DEL_RECURSE) != DR_SUCCESS) @@ -736,7 +736,7 @@ static void generate_and_send_sums(int fd, OFF_T len, int f_out, int f_copy) static int find_fuzzy(struct file_struct *file, struct file_list *dirlist) { int fname_len, fname_suf_len; - const char *fname_suf, *fname = F_BASENAME(file); + const char *fname_suf, *fname = file->basename; uint32 lowest_dist = 25 << 16; /* ignore a distance greater than 25 */ int j, lowest_j = -1; @@ -752,7 +752,7 @@ static int find_fuzzy(struct file_struct *file, struct file_list *dirlist) if (!S_ISREG(fp->mode) || !F_LENGTH(fp) || fp->flags & FLAG_SENT) continue; - name = F_BASENAME(fp); + name = fp->basename; if (F_LENGTH(fp) == F_LENGTH(file) && cmp_time(fp->modtime, file->modtime) == 0) { @@ -1616,7 +1616,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, if (fnamecmp_type == FNAMECMP_FUZZY) iflags |= ITEM_XNAME_FOLLOWS; itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type, - fuzzy_file ? F_BASENAME(fuzzy_file) : NULL); + fuzzy_file ? fuzzy_file->basename : NULL); } if (!do_xfers) { diff --git a/rsync.h b/rsync.h index c2a4e674..0e0ad82f 100644 --- a/rsync.h +++ b/rsync.h @@ -526,15 +526,15 @@ struct file_struct { } dir; uint32 len32; /* Lowest 32 bits of the file's length */ unsigned short mode; /* The item's type and permissions */ - unsigned short flags; /* This item MUST remain last! */ + unsigned short flags; /* The FLAG_* bits for this item */ + const char basename[1]; /* The basename (AKA filename) follows */ }; extern int flist_extra_cnt; extern int preserve_uid; extern int preserve_gid; -#define FILE_STRUCT_LEN (offsetof(struct file_struct, flags) \ - + sizeof (unsigned short)) +#define FILE_STRUCT_LEN (offsetof(struct file_struct, basename)) #define EXTRA_LEN (sizeof (union flist_extras)) #define SUM_EXTRA_CNT ((MD4_SUM_LENGTH + EXTRA_LEN - 1) / EXTRA_LEN) @@ -544,8 +544,7 @@ extern int preserve_gid; #define LEN64_BUMP(f) ((f)->flags & FLAG_LENGTH64 ? 1 : 0) #define HLINK_BUMP(f) (F_IS_HLINKED(f) ? 1 : 0) -/* Basename (AKA filename) and length applies to all items */ -#define F_BASENAME(f) ((const char*)(f) + FILE_STRUCT_LEN) +/* The length applies to all items. */ #if SIZEOF_INT64 < 8 #define F_LENGTH(f) ((int64)(f)->len32) #else @@ -554,7 +553,7 @@ extern int preserve_gid; #endif /* If there is a symlink string, it is always right after the basename */ -#define F_SYMLINK(f) (F_BASENAME(f) + strlen(F_BASENAME(f)) + 1) +#define F_SYMLINK(f) ((f)->basename + strlen((f)->basename) + 1) /* When the associated option is on, all entries will have these present: */ #define F_UID(f) REQ_EXTRA(f, preserve_uid)->uid @@ -574,7 +573,7 @@ extern int preserve_gid; + SUM_EXTRA_CNT - 1)) /* Some utility defines: */ -#define F_IS_ACTIVE(f) F_BASENAME(f)[0] +#define F_IS_ACTIVE(f) (f)->basename[0] #define F_IS_HLINKED(f) ((f)->flags & FLAG_HLINKED) #define F_HLINK_NOT_FIRST(f) BITS_SETnUNSET((f)->flags, FLAG_HLINKED, FLAG_HLINK_FIRST) #define F_HLINK_NOT_LAST(f) BITS_SETnUNSET((f)->flags, FLAG_HLINKED, FLAG_HLINK_LAST) -- 2.34.1