Re:Not knowing the /proc file system
by a1369209993 on Wednesday October 25, 2023 @06:34PM
(#38019217)
As written, it should be `s_hasdigit`, but it's actually wrong - it should be:
int s_isnum(const char* s) {
int result = (*s != '\0');
while (*s != '\0') {
if ((*s < '0') || ('9' < *s)) {
result = 0;
}
s++;
}
return result;
}
otherwise, it will choke on directories like `/proc/etc64/` or `/proc/net6/` if any such directory is added. (Plus other bits like early return, but that's not a correctness bug.)Thanks for this! Had not been aware of files such as `/proc/net6/` or `/proc/etc64/`. Will include this as an edit to the original post.
Re:Not knowing the /proc file system
by a1369209993 on Thursday October 26, 2023 @05:31PM
(#38031947)
AFAIK, no such directories exist in the linux proc code at this time. (Which means you won't get bug reports even in principle until, possibly years later, some such directories are added. At which point the code will start to to malfunction, possibly in bizzare and inconsistent ways, despite having worked fine for years by that point. This is a design principle I learned by experience.)
Also I would say almost any "issomething" method involving a loop has an opportunity for an early return.