nfqws,tpws: r/o open instead of stat() for list file check

This commit is contained in:
bol-van
2025-02-04 23:28:18 +03:00
parent bd67b41f32
commit 5f9fa28251
6 changed files with 34 additions and 8 deletions

View File

@@ -9,6 +9,7 @@
#include <ctype.h>
#include <sys/stat.h>
#include <libgen.h>
#include <fcntl.h>
int unique_size_t(size_t *pu, int ct)
{
@@ -313,6 +314,17 @@ bool file_mod_signature(const char *filename, file_mod_sig *ms)
return true;
}
bool file_open_test(const char *filename, int flags)
{
int fd = open(filename,flags);
if (fd>=0)
{
close(fd);
return true;
}
return false;
}
bool pf_in_range(uint16_t port, const port_filter *pf)
{
return port && (((!pf->from && !pf->to) || (port>=pf->from && port<=pf->to)) ^ pf->neg);