diff options
author | Karel Zak | 2010-07-15 16:00:42 +0200 |
---|---|---|
committer | Karel Zak | 2011-01-03 12:28:40 +0100 |
commit | b49103ed47580ecc94969d00ff4ebd5101fa53fd (patch) | |
tree | 634ea3787359ccefb4230755195784341f7a560c /shlibs/mount/src/utils.c | |
parent | libmount: add mnt_get_writable_mtab_path() (diff) | |
download | kernel-qcow2-util-linux-b49103ed47580ecc94969d00ff4ebd5101fa53fd.tar.gz kernel-qcow2-util-linux-b49103ed47580ecc94969d00ff4ebd5101fa53fd.tar.xz kernel-qcow2-util-linux-b49103ed47580ecc94969d00ff4ebd5101fa53fd.zip |
libmount: add {start,end}swith() functions
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount/src/utils.c')
-rw-r--r-- | shlibs/mount/src/utils.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/shlibs/mount/src/utils.c b/shlibs/mount/src/utils.c index 67b00c316..eb183ee0f 100644 --- a/shlibs/mount/src/utils.c +++ b/shlibs/mount/src/utils.c @@ -28,6 +28,7 @@ #include <fcntl.h> #include <pwd.h> +#include "strutils.h" #include "pathnames.h" #include "mountP.h" @@ -52,6 +53,37 @@ char *mnt_getenv_safe(const char *arg) #endif } +int endswith(const char *s, const char *sx) +{ + ssize_t off; + + assert(s); + assert(sx); + + off = strlen(s); + if (!off) + return 0; + off -= strlen(sx); + if (off < 0) + return 0; + + return !strcmp(s + off, sx); +} + +int startswith(const char *s, const char *sx) +{ + size_t off; + + assert(s); + assert(sx); + + off = strlen(sx); + if (!off) + return 0; + + return !strncmp(s, sx, off); +} + /** * mnt_fstype_is_pseudofs: * @type: filesystem name @@ -318,12 +350,32 @@ int test_match_options(struct mtest *ts, int argc, char *argv[]) return 0; } +int test_startswith(struct mtest *ts, int argc, char *argv[]) +{ + char *optstr = argv[1]; + char *pattern = argv[2]; + + printf("%s\n", startswith(optstr, pattern) ? "YES" : "NOT"); + return 0; +} + +int test_endswith(struct mtest *ts, int argc, char *argv[]) +{ + char *optstr = argv[1]; + char *pattern = argv[2]; + + printf("%s\n", endswith(optstr, pattern) ? "YES" : "NOT"); + return 0; +} + int main(int argc, char *argv[]) { struct mtest tss[] = { { "--match-fstype", test_match_fstype, "<type> <pattern> FS types matching" }, { "--match-options", test_match_options, "<options> <pattern> options matching" }, + { "--starts-with", test_startswith, "<string> <prefix>" }, + { "--ends-with", test_endswith, "<string> <prefix>" }, { NULL } }; |