shared utils: add a string suffix checker 53/203753/2
authorMichal Bloch <m.bloch@samsung.com>
Wed, 17 Apr 2019 10:26:23 +0000 (12:26 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 17 Apr 2019 12:18:13 +0000 (14:18 +0200)
Change-Id: I8c7a5e78c7d407a983c967a6b105c31e3beff3a7
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/shared/util.c
src/shared/util.h

index 1161bed..61ed8ea 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * crash-manager
- * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2012-2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
@@ -557,6 +557,14 @@ char* concatenate(char *const vec[])
        return str;
 }
 
+bool string_ends_with(const char *string, const char *suffix)
+{
+       const size_t string_len = strlen(string);
+       const size_t suffix_len = strlen(suffix);
+
+       return (string_len >= suffix_len) && !strcmp(string + string_len - suffix_len, suffix);
+}
+
 /**
  * @}
  */
index 4f6c6ab..a1d8f5f 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef __DEF_UTIL_H__
 #define __DEF_UTIL_H__
 
+#include <stdbool.h>
+
 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
 
 #ifndef __CONSTRUCTOR__
@@ -61,6 +63,8 @@ char* get_cmd_line(pid_t pid);
 
 char* concatenate(char *const vec[]);
 
+bool string_ends_with(const char *string, const char *suffix);
+
 #ifdef __cplusplus
 }
 #endif