diff options
author | Eric Sandeen <sandeen@redhat.com> | 2013-01-25 13:27:47 -0600 |
---|---|---|
committer | Zach Brown <zab@redhat.com> | 2013-02-05 16:09:41 -0800 |
commit | bcb2b73358f1c05e6b5c48cfd19e3762cc69c677 (patch) | |
tree | 0527a68a1c20f3777f1c5f3559e29c424fb4dde4 /utils.h | |
parent | 7ced17b07f9524c999395240458a46e403036d6b (diff) | |
download | btrfs-progs-bcb2b73358f1c05e6b5c48cfd19e3762cc69c677.tar.gz |
btrfs-progs: simplify ioctl name copy and null termination
In the places where we copy a string into the name
member of btrfs_ioctl_vol_args or btrfs_ioctl_vol_args_v2,
we use strncopy (to not overflow the name array) and then
set the last position to the null character.
Howver, in both cases the arrays are defined with:
char name[MAX+1];
hence the last array position is name[MAX].
In most cases, we now insert the null at name[MAX-1]
which deprives us of one useful character.
Even the above isn't consistent through the code, so
make some helper code to make it simple, i.e.
strncpy_null(dest, src) which automatically does the
right thing based on the size of dest.
Thanks to Zach Brown for the macro suggestion.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Diffstat (limited to 'utils.h')
-rw-r--r-- | utils.h | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -53,4 +53,9 @@ int get_device_info(int fd, u64 devid, struct btrfs_ioctl_dev_info_args *di_args); int get_fs_info(int fd, char *path, struct btrfs_ioctl_fs_info_args *fi_args, struct btrfs_ioctl_dev_info_args **di_ret); + +char *__strncpy__null(char *dest, const char *src, size_t n); +/* Helper to always get proper size of the destination string */ +#define strncpy_null(dest, src) __strncpy__null(dest, src, sizeof(dest)) + #endif |