[TUHS] 30 days of awktober

Steffen Nurpmeso steffen at sdaoden.eu
Sun Oct 6 08:23:25 AEST 2024


Rich Salz wrote in
 <CAFH29tptJ87d9LbR3DUj1meCaRKn8J6eY0GtBF51xGMnRbkp9w at mail.gmail.com>:
 |Someone is trying to write something interesting about awk every day of
 |this month.  The thread starts here:
 |https://mastodon.mit.edu/@eichin/113240121988228925

The good thing is that find(1) now has + standardized.  Ie his

  find /tmp --print0 | xargs -0 stat --format "%s %n"

can now be

  find /tmp -exec stat --format "%s %n" {} +

And the POSIX core developers mention (APPLICATION USAGE)

  It should be noted that using find with −print0 to pipe input to
  xargs −r0 is less safe than using find with −exec because if
  find −print0 is terminated after it has written a partial
  pathname, the partial pathname may be processed as if it was
  a complete pathname.

Heh!

Other than that, off-topic to this thread i am afraid, but should
be posted to another, .. but now that i am here, you know, we all
owe thanks to Geoff Clare and Andrey Josey (and Eric Blake of
RedHat, but really, the Linux approach to this problem makes me
sick, it really should have to work as shown in RFC 2553->3493),
as only thanks to these people the BSD socket API is still
compatible with ISO C .. at least on POSIX systems!

And here is how:

  In stating these field mapping requirements when a cast operator
  is applied to the various socket address structures, the
  standard defines the behavior in circumstances where the
  behavior is undefined in the ISO C standard. The onus is on
  implementations to ensure that these mappings are as described
  in the standard, making use of implementation-specific
  extensions if necessary, even though this is not stated
  explicitly.

and the solution is

  On page 386 line 13115 section <sys/socket.h> DESCRIPTION, change:

      When a pointer to a sockaddr_storage structure is cast as
      a pointer to a sockaddr structure, the ss_family field of
      the sockaddr_storage structure shall map onto the sa_family
      field of the sockaddr structure. When a pointer to
      a sockaddr_storage structure is cast as a pointer to
      a protocol-specific address structure, the ss_family field
      shall map onto a field of that structure that is of type
      sa_family_t and that identifies the protocol’s address
      family.

  to:

      When a pointer to a sockaddr_storage structure is cast as
      a pointer to a sockaddr structure, or vice versa, the
      ss_family field of the sockaddr_storage structure shall map
      onto the sa_family field of the sockaddr structure. When
      a pointer to a sockaddr_storage structure is cast as
      a pointer to a protocol-specific address structure, or vice
      versa, the ss_family field shall map onto a field of that
      structure that is of type sa_family_t and that identifies
      the protocol’s address family. When a pointer to a sockaddr
      structure is cast as a pointer to a protocol-specific
      address structure, or vice versa, the sa_family field shall
      map onto a field of that structure that is of type
      sa_family_t and that identifies the protocol’s address
      family. Additionally, the structures shall be defined in
      such a way that the compiler treats an access to the stored
      value of the sa_family_t member of any of these structures,
      via an lvalue expression whose type involves any other one
      of these structures, as permissible, despite the more
      restrictive expression rules on stored value access as
      stated in the ISO C standard.

as well as this RATIONALE addition:

  Note that defining the sockaddr_storage and sockaddr structures
  using only mechanisms defined in early editions of the ISO
  C standard may produce aliasing diagnostics when applications
  use casting between pointers to the various socket address
  structures. Because of the large body of existing code utilizing
  sockets in a way that could trigger undefined behavior due to
  strict aliasing rules, this standard mandates that these
  structures can alias each other for accessing the sa_family_t
  member of the structures, so as to preserve well-defined
  semantics. An implementation's header files may need to use
  anonymous unions, or even an implementation-specific extension,
  to comply with the requirements of this standard.

I love this standard.

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)


More information about the TUHS mailing list