diff options
author | Gary Benson <gbenson@redhat.com> | 2015-03-06 09:42:06 +0000 |
---|---|---|
committer | Gary Benson <gbenson@redhat.com> | 2015-03-06 09:42:06 +0000 |
commit | 61012eef8463764ccd9117dc1c9bc43cc452b7cc (patch) | |
tree | f576a77bcb77e71cc60e6592b56d2aa915b50c36 /gdb/common | |
parent | e80417caef36c7d5e3d1da6a3b396a872d9d7201 (diff) | |
download | gdb-61012eef8463764ccd9117dc1c9bc43cc452b7cc.zip gdb-61012eef8463764ccd9117dc1c9bc43cc452b7cc.tar.gz gdb-61012eef8463764ccd9117dc1c9bc43cc452b7cc.tar.bz2 |
New common function "startswith"
This commit introduces a new inline common function "startswith"
which takes two string arguments and returns nonzero if the first
string starts with the second. It also updates the 295 places
where this logic was written out longhand to use the new function.
gdb/ChangeLog:
* common/common-utils.h (startswith): New inline function.
All places where this logic was used updated to use the above.
Diffstat (limited to 'gdb/common')
-rw-r--r-- | gdb/common/common-utils.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h index 60aa030..cd2665a 100644 --- a/gdb/common/common-utils.h +++ b/gdb/common/common-utils.h @@ -68,4 +68,13 @@ char *savestring (const char *ptr, size_t len); extern char *safe_strerror (int); +/* Return non-zero if the start of STRING matches PATTERN, zero + otherwise. */ + +static inline int +startswith (const char *string, const char *pattern) +{ + return strncmp (string, pattern, strlen (pattern)) == 0; +} + #endif |