Re: [PATCH v9] man/man7/pathname.7: Add file documenting format of pathnames

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Jason,

On Mon, Jan 20, 2025 at 02:06:26PM -0500, Jason Yundt wrote:
> The goal of this new manual page is to help people create programs that
> do the right thing even in the face of unusual paths.  The information
> that I used to create this new manual page came from these sources:
> 
> • <https://unix.stackexchange.com/a/39179/316181>
> • <https://sourceware.org/pipermail/libc-help/2024-August/006737.html>
> • <https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/fs/ext4/ext4.h?h=v6.12.9#n2288>
> • <man:unix(7)>
> • <https://unix.stackexchange.com/q/92426/316181>
> 
> Signed-off-by: Jason Yundt <jason@jasonyundt.email>
> ---
> Here’s what I changed from the previous version:
> 
> • I removed the second iconv() call.
> • I made utf32_pathname const.  I think that that was the only one that could
>   be made const, but correct me if I’m wrong.
> • I changed the order of the variable declarations.  I think that they’re in
>   the correct order now, but correct me if I’m wrong.
> • I removed the curly brackets from all of the if statements.
> • I renamed inbytesleft to inbytes and outbytesleft to outbytes.
> • I replaced the \\ with \[rs].

Thanks!

> +.SS Program source
> +.\" SRC BEGIN (pathname_encoding_example.c)
> +.EX
> +#include <err.h>
> +#include <iconv.h>
> +#include <langinfo.h>
> +#include <locale.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <uchar.h>
> +\&
> +#define NELEMS(a)  (sizeof(a) / sizeof(a[0]))
> +\&
> +int
> +main(void)
> +{
> +    char *inbuf;

I'd rename inbuf,outbut to in,out.

> +    char *locale_pathname;
> +    char *outbuf;
> +    FILE *fp;
> +    size_t iconv_result;

I've removed this variable (see below).

> +    size_t inbytes;
> +    size_t outbytes;
> +    size_t size;
> +    iconv_t cd;

Please align (and merge some) with spaces the above as:

    char     *locale_pathname;
    char     *in, *out;
    FILE     *fp;
    size_t   size;
    size_t   inbytes, outbytes;
    iconv_t  cd;

I've also reordered a few so that they appear in order of use (more or
less).

> +    const char32_t utf32_pathname[] = U"example";
> +\&
> +    if (setlocale(LC_ALL, "") == NULL)
> +        err(EXIT_FAILURE, "setlocale");
> +\&
> +    size = NELEMS(utf32_pathname) * MB_CUR_MAX;
> +    locale_pathname = malloc(size);
> +    if (locale_pathname == NULL)
> +      err(EXIT_FAILURE, "malloc");
> +\&
> +    cd = iconv_open(nl_langinfo(CODESET), "UTF\-32");
> +    if (cd == (iconv_t) \- 1)
> +        err(EXIT_FAILURE, "iconv_open");
> +\&
> +    inbuf = (char *) utf32_pathname;
> +    inbytes = sizeof utf32_pathname;

Please use sizeof(utf32_pathname), with parentheses.

> +    outbuf = locale_pathname;
> +    outbytes = size;
> +    iconv_result =
> +        iconv(cd, &inbuf, &inbytes, &outbuf, &outbytes);
> +    if (iconv_result == \-1)

This variable seems useless:

    if (iconv(cd, &in, &inbytes, &out, &outbytes) == \-1)

> +        err(EXIT_FAILURE, "iconv");
> +\&
> +    if (iconv_result == \-1)
> +        err(EXIT_FAILURE, "iconv");

This is a leftover from the previous version.


Have a lovely night!
Alex

> +\&
> +    if (iconv_close(cd) == \-1)
> +        err(EXIT_FAILURE, "iconv_close");
> +\&
> +    fp = fopen(locale_pathname, "w");
> +    fputs("Hello, world!\[rs]n", fp);
> +    if (fclose(fp) == EOF)
> +        err(EXIT_FAILURE, "fclose");
> +\&
> +    free(locale_pathname);
> +    exit(EXIT_SUCCESS);
> +}
> +.EE
> +.\" SRC END
> +.SH SEE ALSO
> +.BR limits.h (0p),
> +.BR open (2),
> +.BR fpathconf (3),
> +.BR iconv (3),
> +.BR nl_langinfo (3),
> +.BR path_resolution (7),
> +.BR mount (8)
> -- 
> 2.47.1
> 
> 

-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux