From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12051 invoked by alias); 18 Sep 2005 19:13:17 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 11996 invoked by uid 22791); 18 Sep 2005 19:13:08 -0000 Received: from nitzan.inter.net.il (HELO nitzan.inter.net.il) (192.114.186.20) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Sun, 18 Sep 2005 19:13:08 +0000 Received: from HOME-C4E4A596F7 (IGLD-80-230-33-247.inter.net.il [80.230.33.247]) by nitzan.inter.net.il (MOS 3.6.5-GR) with ESMTP id BLK51094 (AUTH halo1); Sun, 18 Sep 2005 22:12:51 +0300 (IDT) Date: Sun, 18 Sep 2005 19:13:00 -0000 Message-Id: From: Eli Zaretskii To: Mark Kettenis CC: sjackman@gmail.com, rearnsha@gcc.gnu.org, gdb-patches@sources.redhat.com In-reply-to: <200509180903.j8I93fTo025933@elgar.sibelius.xs4all.nl> (message from Mark Kettenis on Sun, 18 Sep 2005 11:03:41 +0200 (CEST)) Subject: Re: sim/arm/armos.c: IsTTY [PATCH] Reply-to: Eli Zaretskii References: <7f45d9390508151204ca0b146@mail.gmail.com> <20050830023718.GB16189@nevyn.them.org> <7f45d93905090709516f912861@mail.gmail.com> <1126170388.18092.16.camel@pc960.cambridge.arm.com> <7f45d93905090910237c63acf0@mail.gmail.com> <20050917223728.GL8777@nevyn.them.org> <20050918034432.GA6990@nevyn.them.org> <200509180903.j8I93fTo025933@elgar.sibelius.xs4all.nl> X-SW-Source: 2005-09/txt/msg00163.txt.bz2 > Date: Sun, 18 Sep 2005 11:03:41 +0200 (CEST) > From: Mark Kettenis > 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!