Re: sim/arm/armos.c: IsTTY [PATCH]

Eli Zaretskii
2005-09-18T19:13:17Z

> Date: Sun, 18 Sep 2005 11:03:41 +0200 (CEST)
> From: Mark Kettenis <mark.kettenis@xs4all.nl>
> CC: eliz@gnu.org, sjackman@gmail.com, rearnsha@gcc.gnu.org,
> gdb-patches@sources.redhat.com
>
> FWIW, the correct way to deal with these issues is to dynamically
> allocate the buffer, making the buffer bigger if it fails because the
> buffer is too small:
>
> #ifndef _POSIX_PATH_MAX
> #define _POSIX_PATH_MAX 256
> #endif
>
> size_t len = _POSIX_PATH_MAX;
> char *buf = xmalloc(len);
> while (foo(..., buf, len) == -1 && errno == ENAMETOOLONG)
> {
> len *= 2;
> buf = xrealloc(buf, len);
> }
>
> I used _POSIX_PATH_MAX here, but you could probably just as well
> hardcode a sensible value. Don't forget to free the buffer once
> you're done with it ;-).

Forgive my bluntness, but if such a simple job requires such
complicated code, and with caveats on top of that, it's a clear sign
of a botched API, worthy of a certain company from Redmond!