summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2015-06-16 16:58:23 +0200
committerJakub Hrozek <jhrozek@redhat.com>2015-06-19 18:48:13 +0200
commita99845006f96f9d1e7af871ec67c71cee8408a62 (patch)
tree25a873d57d0f695652263dfc05de141859ff5a69 /src/util
parent8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98 (diff)
downloadsssd-a99845006f96f9d1e7af871ec67c71cee8408a62.tar.gz
sssd-a99845006f96f9d1e7af871ec67c71cee8408a62.tar.xz
sssd-a99845006f96f9d1e7af871ec67c71cee8408a62.zip
utils: add get_last_x_chars()
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/string_utils.c17
-rw-r--r--src/util/util.h2
2 files changed, 19 insertions, 0 deletions
diff --git a/src/util/string_utils.c b/src/util/string_utils.c
index 71b2a0920..b6037621e 100644
--- a/src/util/string_utils.c
+++ b/src/util/string_utils.c
@@ -108,3 +108,20 @@ errno_t guid_blob_to_string_buf(const uint8_t *blob, char *str_buf,
return EOK;
}
+
+const char *get_last_x_chars(const char *str, size_t x)
+{
+ size_t len;
+
+ if (str == NULL) {
+ return NULL;
+ }
+
+ len = strlen(str);
+
+ if (len < x) {
+ return str;
+ }
+
+ return (str + len - x);
+}
diff --git a/src/util/util.h b/src/util/util.h
index 786ed303e..3d90cf0d1 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -628,6 +628,8 @@ char * sss_reverse_replace_space(TALLOC_CTX *mem_ctx,
errno_t guid_blob_to_string_buf(const uint8_t *blob, char *str_buf,
size_t buf_size);
+const char *get_last_x_chars(const char *str, size_t x);
+
/* from become_user.c */
errno_t become_user(uid_t uid, gid_t gid);
struct sss_creds;