linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH V2 1/2] mkfs.f2fs: add helper strtrim() to trim string's space
@ 2015-11-28 10:19 Sheng Yong
  2015-11-28  3:53 ` Chao Yu
  2015-11-28 10:19 ` [RFC PATCH V2 2/2] mkfs.f2fs: avoid dumplicate extensions Sheng Yong
  0 siblings, 2 replies; 7+ messages in thread
From: Sheng Yong @ 2015-11-28 10:19 UTC (permalink / raw)
  To: chao2.yu, jaegeuk; +Cc: linux-f2fs-devel

Add a helper function strtrim() to trim space both at the beginning and end
of a string.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
---
 include/f2fs_fs.h |  1 +
 lib/libf2fs.c     | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 359deec..e85b2d0 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -768,6 +768,7 @@ enum {
 
 extern void ASCIIToUNICODE(u_int16_t *, u_int8_t *);
 extern int log_base_2(u_int32_t);
+extern void strtrim(char **str);
 extern unsigned int addrs_per_inode(struct f2fs_inode *);
 
 extern int get_bits_in_byte(unsigned char n);
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 83d1296..e901289 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -48,6 +48,30 @@ int log_base_2(u_int32_t num)
 	return ret;
 }
 
+void strtrim(char **str)
+{
+	int len = strlen(*str);
+	char *head = *str;
+	char *tail = *str + len - 1;
+
+	while (head != tail) {
+		if (*head == ' ')
+			head++;
+		else {
+			*str = head;
+			break;
+		}
+	}
+
+	while (tail != head) {
+		if (*tail == ' ') {
+			*tail = '\0';
+			tail--;
+		} else
+			break;
+	}
+}
+
 /*
  * f2fs bit operations
  */
-- 
1.9.1


------------------------------------------------------------------------------

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-11-29  6:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-28 10:19 [RFC PATCH V2 1/2] mkfs.f2fs: add helper strtrim() to trim string's space Sheng Yong
2015-11-28  3:53 ` Chao Yu
2015-11-28 10:19 ` [RFC PATCH V2 2/2] mkfs.f2fs: avoid dumplicate extensions Sheng Yong
2015-11-28  3:07   ` [RFC PATCH V3 " Sheng Yong
2015-11-28  4:00     ` Chao Yu
2015-11-28  4:19       ` Sheng Yong
2015-11-29  6:00         ` Jaegeuk Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).