• Re: Everything without Posix-APIs !

    From [email protected]@21:1/5 to All on Sat Jan 18 10:02:47 2025
    On Fri, 17 Jan 2025 07:46:25 +0100
    Bonita Montero <[email protected]> gabbled:
    I'm developing a little tool to grep from a process address space
    with a regex-delimiter for the start and end (both included in the
    result). Therefore I needed to enumerate the process-IDs whose exe-
    cutable paths matches a certain regex. This is the code:


    Everything is done without Posix-APIs but with pure C++ !

    Given its simply iterating a directory I'm not sure whats so amazing about it. However, thank you for reminding me about from_chars(), I'd forgotten all
    about that function. Could have used it recently instead of strtol().

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paavo Helde@21:1/5 to Bonita Montero on Sat Jan 18 17:28:44 2025
    On 18.01.2025 14:28, Bonita Montero wrote:
    Am 18.01.2025 um 11:02 schrieb [email protected]:
    On Fri, 17 Jan 2025 07:46:25 +0100
    Bonita Montero <[email protected]> gabbled:
    I'm developing a little tool to grep from a process address space
    with a regex-delimiter for the start and end (both included in the
    result). Therefore I needed to enumerate the process-IDs whose exe-
    cutable paths matches a certain regex. This is the code:


    Everything is done without Posix-APIs but with pure C++ !

    Given its simply iterating a directory I'm not sure whats so amazing
    about it.
    However, thank you for reminding me about from_chars(), I'd forgotten
    all about that function. Could have used it recently instead of strtol().


    from_chars is more flexible because it returns where it has ended
    parsing. That's necessary to detect syntax-errors because there
    might be superfluous chars beyond the end.

    strtol() also returns where it has ended parsing, so there is no
    difference here.

    Alas, strtol() uses the current locale which might potentially cause
    surprises, at least in theory. std::from_chars() is definitely better in
    this regard.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to [email protected] on Sat Jan 18 16:38:39 2025
    [email protected] writes:
    On Fri, 17 Jan 2025 07:46:25 +0100
    Bonita Montero <[email protected]> gabbled:
    I'm developing a little tool to grep from a process address space
    with a regex-delimiter for the start and end (both included in the
    result). Therefore I needed to enumerate the process-IDs whose exe-
    cutable paths matches a certain regex. This is the code:


    Everything is done without Posix-APIs but with pure C++ !

    Given its simply iterating a directory I'm not sure whats so amazing about it. >However, thank you for reminding me about from_chars(), I'd forgotten all >about that function. Could have used it recently instead of strtol().


    It doesn't seem to handle unsigned conversions. It is far more common
    (9 of 10 occurances) for me to use strtoul.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Bonita Montero on Sat Jan 18 16:41:44 2025
    Bonita Montero <[email protected]> writes:
    Am 18.01.2025 um 11:02 schrieb [email protected]:
    On Fri, 17 Jan 2025 07:46:25 +0100
    Bonita Montero <[email protected]> gabbled:
    I'm developing a little tool to grep from a process address space
    with a regex-delimiter for the start and end (both included in the
    result). Therefore I needed to enumerate the process-IDs whose exe-
    cutable paths matches a certain regex. This is the code:


    Everything is done without Posix-APIs but with pure C++ !

    Given its simply iterating a directory I'm not sure whats so amazing
    about it.
    However, thank you for reminding me about from_chars(), I'd forgotten
    all about that function. Could have used it recently instead of strtol().


    from_chars is more flexible because it returns where it has ended
    parsing. That's necessary to detect syntax-errors because there
    might be superfluous chars beyond the end.

    All the strto* C library functions return a pointer to the
    byte where it has ended parsing.


    ahci_irq = strtoul(argv[2], &cp, 0);
    if ((cp == argv[2])
    || (*cp != '\0')
    || ((ahci_irq != 0) && !d_interrupts->valid_interrupt_id(ahci_irq))) {
    lp->log("Illegal interrupt value '%s'\n", argv[2]);
    return false;
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paavo Helde@21:1/5 to Scott Lurndal on Sat Jan 18 19:11:06 2025
    On 18.01.2025 18:38, Scott Lurndal wrote:
    [email protected] writes:
    On Fri, 17 Jan 2025 07:46:25 +0100
    Bonita Montero <[email protected]> gabbled:
    I'm developing a little tool to grep from a process address space
    with a regex-delimiter for the start and end (both included in the
    result). Therefore I needed to enumerate the process-IDs whose exe-
    cutable paths matches a certain regex. This is the code:


    Everything is done without Posix-APIs but with pure C++ !

    Given its simply iterating a directory I'm not sure whats so amazing about it.
    However, thank you for reminding me about from_chars(), I'd forgotten all
    about that function. Could have used it recently instead of strtol().


    It doesn't seem to handle unsigned conversions. It is far more common
    (9 of 10 occurances) for me to use strtoul.

    What do you mean? This compiles and runs fine for me (VS2022):

    #include <iostream>
    #include <cstdint>
    #include <charconv>

    int main() {

    const char buff[] = "4294967295";

    std::uint32_t k;
    std::from_chars(std::begin(buff), std::end(buff), k);

    std::cout << k << std::endl;
    }

    Output:
    4294967295

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Paavo Helde on Sat Jan 18 17:21:36 2025
    Paavo Helde <[email protected]> writes:
    On 18.01.2025 18:38, Scott Lurndal wrote:
    [email protected] writes:
    On Fri, 17 Jan 2025 07:46:25 +0100
    Bonita Montero <[email protected]> gabbled:
    I'm developing a little tool to grep from a process address space
    with a regex-delimiter for the start and end (both included in the
    result). Therefore I needed to enumerate the process-IDs whose exe-
    cutable paths matches a certain regex. This is the code:


    Everything is done without Posix-APIs but with pure C++ !

    Given its simply iterating a directory I'm not sure whats so amazing about it.
    However, thank you for reminding me about from_chars(), I'd forgotten all >>> about that function. Could have used it recently instead of strtol().


    It doesn't seem to handle unsigned conversions. It is far more common
    (9 of 10 occurances) for me to use strtoul.

    What do you mean? This compiles and runs fine for me (VS2022):

    #include <iostream>
    #include <cstdint>
    #include <charconv>

    int main() {

    const char buff[] = "4294967295";

    std::uint32_t k;
    std::from_chars(std::begin(buff), std::end(buff), k);

    std::cout << k << std::endl;
    }

    Output:
    4294967295


    I sit corrected.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)