Explorar o código

gamemode: Add a helper to compare string tails

Signed-off-by: Kai Krakow <kai@kaishome.de>
Kai Krakow %!s(int64=6) %!d(string=hai) anos
pai
achega
373fe5a8af
Modificáronse 1 ficheiros con 11 adicións e 0 borrados
  1. 11 0
      daemon/gamemode.c

+ 11 - 0
daemon/gamemode.c

@@ -74,6 +74,17 @@ POSSIBILITY OF SUCH DAMAGE.
 #define safe_snprintf(b, s, ...)                                                                   \
 	(snprintf(b, sizeof(b), s, __VA_ARGS__) < (ssize_t)sizeof(b) ? strndup(b, sizeof(b)) : NULL)
 
+/**
+ * Helper function: Test, if haystack ends with needle.
+ */
+static inline const char *strtail(const char *haystack, const char *needle)
+{
+	char *pos = strstr(haystack, needle);
+	if (pos && (strlen(pos) == strlen(needle)))
+		return pos;
+	return NULL;
+}
+
 /**
  * The GameModeClient encapsulates the remote connection, providing a list
  * form to contain the pid and credentials.