$(top_srcdir)/lib/at.c \
$(top_srcdir)/include/list.h \
$(top_srcdir)/lib/mangle.c \
- $(top_srcdir)/lib/canonicalize.c
+ $(top_srcdir)/lib/canonicalize.c \
+ $(top_srcdir)/lib/strutils.c
nodist_libmount_la_SOURCES = mountP.h
/* utils.c */
extern char *mnt_getenv_safe(const char *arg);
+extern int endswith(const char *s, const char *sx);
+extern int startswith(const char *s, const char *sx);
+
extern char *mnt_get_username(const uid_t uid);
extern int mnt_has_regular_mtab(void);
#include <fcntl.h>
#include <pwd.h>
+#include "strutils.h"
#include "pathnames.h"
#include "mountP.h"
#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
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 }
};