diff options
author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2013-11-14 17:31:56 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-14 19:32:20 -0500 |
commit | 839cc2a94cc3665bafe32203c2f095f4dd470a80 (patch) | |
tree | c48aa0e5bcd3f09ad5b7354396a50928c9211155 /include/linux/seq_file.h | |
parent | 57f4257eae33e036125973858934730250d464e3 (diff) |
seq_file: introduce seq_setwidth() and seq_pad()
There are several users who want to know bytes written by seq_*() for
alignment purpose. Currently they are using %n format for knowing it
because seq_*() returns 0 on success.
This patch introduces seq_setwidth() and seq_pad() for allowing them to
align without using %n format.
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Joe Perches <joe@perches.com>
Cc: David Miller <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/seq_file.h')
-rw-r--r-- | include/linux/seq_file.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index 4e32edc8f506..52e0097f61f0 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h | |||
@@ -20,6 +20,7 @@ struct seq_file { | |||
20 | size_t size; | 20 | size_t size; |
21 | size_t from; | 21 | size_t from; |
22 | size_t count; | 22 | size_t count; |
23 | size_t pad_until; | ||
23 | loff_t index; | 24 | loff_t index; |
24 | loff_t read_pos; | 25 | loff_t read_pos; |
25 | u64 version; | 26 | u64 version; |
@@ -79,6 +80,20 @@ static inline void seq_commit(struct seq_file *m, int num) | |||
79 | } | 80 | } |
80 | } | 81 | } |
81 | 82 | ||
83 | /** | ||
84 | * seq_setwidth - set padding width | ||
85 | * @m: the seq_file handle | ||
86 | * @size: the max number of bytes to pad. | ||
87 | * | ||
88 | * Call seq_setwidth() for setting max width, then call seq_printf() etc. and | ||
89 | * finally call seq_pad() to pad the remaining bytes. | ||
90 | */ | ||
91 | static inline void seq_setwidth(struct seq_file *m, size_t size) | ||
92 | { | ||
93 | m->pad_until = m->count + size; | ||
94 | } | ||
95 | void seq_pad(struct seq_file *m, char c); | ||
96 | |||
82 | char *mangle_path(char *s, const char *p, const char *esc); | 97 | char *mangle_path(char *s, const char *p, const char *esc); |
83 | int seq_open(struct file *, const struct seq_operations *); | 98 | int seq_open(struct file *, const struct seq_operations *); |
84 | ssize_t seq_read(struct file *, char __user *, size_t, loff_t *); | 99 | ssize_t seq_read(struct file *, char __user *, size_t, loff_t *); |