tst_kvcmp: Strip double quotes when parsing /etc/os-release
PATCH v2 1/1 tst_kvcmp: Strip double quotes when parsing /etc/os-release
ID is normally without double quotes, e.g.: ID=debian
But at least SLES and openSUSE contain double quotes, e.g.:
ID="opensuse-tumbleweed"
thus optionally strip the double quotes after scanning them.
--- lib/tst_kvercmp.c | 6 ++++++ 1 file changed, 6 insertions(+)
lib/tst_kvercmp.c +6 -0
@@ -148,6 +148,12 @@ const char *tst_kvcmp_distname(const char *kver)if (access (OSRELEASE_PATH ,F_OK ) !=-1 ) {SAFE_FILE_LINES_SCANF (NULL ,OSRELEASE_PATH ,"ID=%s" , distname); +if (p[0 ] =='"' ) +memmove (p, p +1 ,strlen (p)); + +if (p[strlen (p) -1 ] =='"' ) + p[strlen (p) -1 ] ='\0' ; +while (*p) { *p =toupper ((unsigned char )*p); p++;
Signature · 1 line
2.28.0
PATCH v2 1/1 tst_kvcmp: Strip double quotes when parsing /etc/os-release
Hi!
lib/tst_kvercmp.c const char *tst_kvcmp_distname(const char *kver) · line 152
Quoted 10 lines
lib/tst_kvercmp.c +2
-0@@ -148,6 +148,12 @@ const char *tst_kvcmp_distname(const char *kver)if (access (OSRELEASE_PATH ,F_OK ) !=-1 ) {SAFE_FILE_LINES_SCANF (NULL ,OSRELEASE_PATH ,"ID=%s" , distname); +if (p[0 ] =='"' ) +memmove (p, p +1 ,strlen (p));
Why can't we just do distname++ and move the p = distname after this condition?
lib/tst_kvercmp.c const char *tst_kvcmp_distname(const char *kver) · line 155
Quoted 2 lines
lib/tst_kvercmp.c +2
-0+if (p[strlen (p) -1 ] =='"' ) + p[strlen (p) -1 ] ='\0' ;
I guess that we can move this to the while loop with:
while (*p) {
if (*p == '"') {
*p = 0;
break;
}
*p = ....
p++;
}Quoted 6 lines
lib/tst_kvercmp.c +0
-0while (*p) { *p =toupper ((unsigned char )*p); p++;Signature · 1 line
2.28.0
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/1 tst_kvcmp: Strip double quotes when parsing /etc/os-release
Hi Cyril,
Quoted 8 lines
Quoted 7 lines
lib/tst_kvercmp.c +0
-0@@ -148,6 +148,12 @@ const char *tst_kvcmp_distname(const char *kver)if (access (OSRELEASE_PATH ,F_OK ) !=-1 ) {SAFE_FILE_LINES_SCANF (NULL ,OSRELEASE_PATH ,"ID=%s" , distname);
Quoted 5 lines
lib/tst_kvercmp.c const char *tst_kvcmp_distname(const char *kver) · line 152
Quoted 2 lines
lib/tst_kvercmp.c +2
-0+if (p[0 ] =='"' ) +memmove (p, p +1 ,strlen (p));Why can't we just do distname++ and move the p = distname after this condition?
Sure.
Quoted 5 lines
lib/tst_kvercmp.c const char *tst_kvcmp_distname(const char *kver) · line 155
Quoted 2 lines
lib/tst_kvercmp.c +2
-0+if (p[strlen (p) -1 ] =='"' ) + p[strlen (p) -1 ] ='\0' ;I guess that we can move this to the while loop with:
Quoted 9 lines
while (*p) {
if (*p == '"') {
*p = 0;
break;
}
*p = ....
p++;
}OK, " shouldn't be in the middle of the character, thus safe
Thanks for the suggestions.
Kind regards,
Petr
PATCH v2 1/1 tst_kvcmp: Strip double quotes when parsing /etc/os-release
In reply to Cyril HrubisHi Cyril,
Quoted 8 lines
Quoted 7 lines
lib/tst_kvercmp.c +0
-0@@ -148,6 +148,12 @@ const char *tst_kvcmp_distname(const char *kver)if (access (OSRELEASE_PATH ,F_OK ) !=-1 ) {SAFE_FILE_LINES_SCANF (NULL ,OSRELEASE_PATH ,"ID=%s" , distname);
Quoted 5 lines
lib/tst_kvercmp.c const char *tst_kvcmp_distname(const char *kver) · line 152
Quoted 2 lines
lib/tst_kvercmp.c +2
-0+if (p[0 ] =='"' ) +memmove (p, p +1 ,strlen (p));Why can't we just do distname++ and move the p = distname after this condition?
OK, distname is char[], not a pointer, I guess I have to use memmove().
Kind regards,
Petr
PATCH v2 1/1 tst_kvcmp: Strip double quotes when parsing /etc/os-release
Hi!
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
lib/tst_kvercmp.c +0
-0@@ -148,6 +148,12 @@ const char *tst_kvcmp_distname(const char *kver)if (access (OSRELEASE_PATH ,F_OK ) !=-1 ) {SAFE_FILE_LINES_SCANF (NULL ,OSRELEASE_PATH ,"ID=%s" , distname);
Quoted 6 lines
Quoted 5 lines
lib/tst_kvercmp.c const char *tst_kvcmp_distname(const char *kver) · line 152
Quoted 2 lines
lib/tst_kvercmp.c +2
-0+if (p[0 ] =='"' ) +memmove (p, p +1 ,strlen (p));Why can't we just do distname++ and move the p = distname after this condition?
OK, distname is char[], not a pointer, I guess I have to use
memmove().
In that case you just need to do char *ret = distname + 1; p = ret; .... return ret;
Signature · 2 lines
Cyril Hrubis [email protected]