diff options
author | Neal Gompa <ngompa13@gmail.com> | 2017-12-30 12:19:16 -0500 |
---|---|---|
committer | Neal Gompa <ngompa13@gmail.com> | 2017-12-30 12:22:39 -0500 |
commit | d54da94b818a0cf51352ba1f4cdeb857ebc92218 (patch) | |
tree | e5469d8c1a2cee28c5773349ea9544da179f934c /src/rename_device.c | |
parent | d465fd1adf0105bf43261e9340bd8f8997f01839 (diff) | |
parent | 7fa374712f6da22f97bce84fff2e4cd535e9ef8d (diff) | |
download | initscripts-d54da94b818a0cf51352ba1f4cdeb857ebc92218.tar initscripts-d54da94b818a0cf51352ba1f4cdeb857ebc92218.tar.gz initscripts-d54da94b818a0cf51352ba1f4cdeb857ebc92218.tar.bz2 initscripts-d54da94b818a0cf51352ba1f4cdeb857ebc92218.tar.xz initscripts-d54da94b818a0cf51352ba1f4cdeb857ebc92218.zip |
Merge tag '9.78' into distro/mga
Tag as 9.78
Diffstat (limited to 'src/rename_device.c')
-rw-r--r-- | src/rename_device.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/src/rename_device.c b/src/rename_device.c index d49205ed..6d6030eb 100644 --- a/src/rename_device.c +++ b/src/rename_device.c @@ -104,20 +104,40 @@ char *read_subchannels(char *path) { #endif +/* + * Taken from systemd: + * https://github.com/systemd/systemd/blob/master/src/basic/string-util.c#L49 + */ +char* endswith(const char *s, const char *postfix) { + size_t sl, pl; + + sl = strlen(s); + pl = strlen(postfix); + + if (pl == 0) + return (char*) s + sl; + + if (sl < pl) + return NULL; + + if (memcmp(s + sl - pl, postfix, pl) != 0) + return NULL; + + return (char*) s + sl - pl; +} + int isCfg(const struct dirent *dent) { - int len = strlen(dent->d_name); - - if (strncmp(dent->d_name,"ifcfg-",6)) - return 0; - if (strstr(dent->d_name,"rpmnew") || - strstr(dent->d_name,"rpmsave") || - strstr(dent->d_name,"rpmorig")) - return 0; - if (dent->d_name[len-1] == '~') - return 0; - if (!strncmp(dent->d_name+len-4,".bak",4)) + if (strncmp(dent->d_name, "ifcfg-",6) || + endswith(dent->d_name, ".rpmnew") != NULL || + endswith(dent->d_name, ".rpmsave") != NULL || + endswith(dent->d_name, ".rpmorig") != NULL || + endswith(dent->d_name, ".orig") != NULL || + endswith(dent->d_name, ".old") != NULL || + endswith(dent->d_name, ".bak") != NULL || + endswith(dent->d_name, "~") != NULL) return 0; - return 1; + else + return 1; } static inline char *dequote(char *start, char *end) { |