-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: strncmp implementation for old kernels
- Loading branch information
1 parent
1e92ea1
commit 02c0213
Showing
2 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
#pragma once | ||
|
||
#include "vmlinux.h" | ||
#include "common.bpf.h" | ||
|
||
#define STRNCMP(s1, s1_sz, s2) \ | ||
({ \ | ||
int result; \ | ||
if (LINUX_KERNEL_VERSION >= KERNEL_VERSION(5, 17, 0)) \ | ||
{ \ | ||
result = bpf_strncmp(s1, s1_sz, s2); \ | ||
} \ | ||
else \ | ||
{ \ | ||
\ | ||
char *__cs = (s1); \ | ||
char *__ct = (s2); \ | ||
unsigned char __c1, __c2; \ | ||
_Pragma("unroll") for (__u32 i = (s1_sz); i > 0; i--) \ | ||
{ \ | ||
__c1 = *__cs++; \ | ||
__c2 = *__ct++; \ | ||
if (__c1 != __c2) \ | ||
{ \ | ||
result = __c1 < __c2 ? -1 : 1; \ | ||
break; \ | ||
} \ | ||
if (!__c1) \ | ||
{ \ | ||
result = 0; \ | ||
break; \ | ||
} \ | ||
} \ | ||
} \ | ||
result; \ | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters