MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / strncmp

Function strncmp

rEFIt_UEFI/Platform/Posix/string.cpp:73–114  ·  view source on GitHub ↗

faster implementation than AsciiStrnCmp. AsciiStrnCmp calls AsciiStrSize 4 times. int strncmp( const char * s1, const char * s2, size_t n ) { while ( n && *s1 && ( *s1 == *s2 ) ) { ++s1; ++s2; --n; } if ( n == 0 ) { return 0; } else { return ( *(unsigned char *)s1 - *(unsigned char *)s2 ); } } Compare no more than N characters of S1 and S2, returning less than, equal to or greater than zero

Source from the content-addressed store, hash-verified

71 if S1 is lexicographically less than, equal to or
72 greater than S2. */
73int
74strncmp(const char *s1, const char *s2, size_t n)
75{
76 unsigned char c1 = '\0';
77 unsigned char c2 = '\0';
78
79 if (n >= 4)
80 {
81 size_t n4 = n >> 2;
82 do
83 {
84 c1 = (unsigned char) *s1++;
85 c2 = (unsigned char) *s2++;
86 if (c1 == '\0' || c1 != c2)
87 return c1 - c2;
88 c1 = (unsigned char) *s1++;
89 c2 = (unsigned char) *s2++;
90 if (c1 == '\0' || c1 != c2)
91 return c1 - c2;
92 c1 = (unsigned char) *s1++;
93 c2 = (unsigned char) *s2++;
94 if (c1 == '\0' || c1 != c2)
95 return c1 - c2;
96 c1 = (unsigned char) *s1++;
97 c2 = (unsigned char) *s2++;
98 if (c1 == '\0' || c1 != c2)
99 return c1 - c2;
100 } while (--n4 > 0);
101 n &= 3;
102 }
103
104 while (n > 0)
105 {
106 c1 = (unsigned char) *s1++;
107 c2 = (unsigned char) *s2++;
108 if (c1 == '\0' || c1 != c2)
109 return c1 - c2;
110 n--;
111 }
112
113 return c1 - c2;
114}
115
116
117

Callers 15

toBSDNameFunction · 0.85
checkDevicePathFunction · 0.85
toBSDNameFunction · 0.85
getFSTypeFromPBRFunction · 0.85
compareFunction · 0.85
strncmp_testsFunction · 0.85
StartLoaderMethod · 0.85
GetCPUPropertiesFunction · 0.85
setup_nvidia_devpropFunction · 0.85
InjectKextsMethod · 0.85
PatchTableType17Function · 0.85

Calls

no outgoing calls

Tested by 2

compareFunction · 0.68
strncmp_testsFunction · 0.68