sysfs_streq

Linux/Linux Kernel : 2018. 3. 19. 09:57
반응형

Name

sysfs_streq — return true if strings are equal, modulo trailing newline


문자열을 비교한다. 뒤에 개행이 오던 NULL이 오던 차이는 관계없다.

Synopsis

bool sysfs_streq (const char * s1,
 const char * s2);
 

Arguments

const char * s1

one string

const char * s2

another string


  1. /** 
  2.  * sysfs_streq - return true if strings are equal, modulo trailing newline 
  3.  * @s1: one string 
  4.  * @s2: another string 
  5.  * 
  6.  * This routine returns true iff two strings are equal, treating both 
  7.  * NUL and newline-then-NUL as equivalent string terminations.  It's 
  8.  * geared for use with sysfs input strings, which generally terminate 
  9.  * with newlines but are compared against values without newlines. 
  10.  */  
  11. bool sysfs_streq(const char *s1, const char *s2)  
  12. {  
  13.     while (*s1 && *s1 == *s2) {  
  14.         s1++;  
  15.         s2++;  
  16.     }  
  17.   
  18.     if (*s1 == *s2)  
  19.         return true;  
  20.     if (!*s1 && *s2 == '\n' && !s2[1])  
  21.         return true;  
  22.     if (*s1 == '\n' && !s1[1] && !*s2)  
  23.         return true;  
  24.     return false;  
  25. }  
  26. EXPORT_SYMBOL(sysfs_streq);  


반응형

'Linux > Linux Kernel' 카테고리의 다른 글

likely, unlikely 함수란?  (0) 2018.03.19
container_of  (0) 2018.03.19
sysfs 사용하기  (0) 2018.03.18
Posted by Real_G