monit-dev
[Top][All Lists]
Advanced

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

Re: POSIX.1 getcwd


From: Martin Pala
Subject: Re: POSIX.1 getcwd
Date: Mon, 01 Sep 2003 08:57:40 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030827 Debian/1.4-3

Hi,

it will be probably better to keep present static memory usage - appropriate getcwd manpage part:

--SNIP--
If buf is NULL, the behaviour of getcwd() is undefined.
...
As an extension to the POSIX.1 standard, Linux (libc4, libc5, glibc) getcwd() allocates the buffer dynamically using malloc() if buf is NULL on call. In this case, the allocated buffer has the length size unless size is zero, when buf is allocated as big as necessary. It is possible (and, indeed, advisable) to free() the buffers
if they have been obtained this way.
--SNIP--

=> this is not POSIX standard, but it is definition of undefined behaviour, which can cause problems with other libraries (like dietlibc and uClibc - thanks CHristian :) and other platforms. Btw. it is cheaper to use automatic memory then dynamic memory allocation.

We're appreciate very much that you are working on the code, this type of feedback is one of most valuable + the best way how to become commiter :)

Thanks,
Martin

Igor Homyakov wrote:

Index: env.c
===================================================================
RCS file: /cvsroot/monit/monit/env.c,v
retrieving revision 1.18
diff -r1.18 env.c
183c183
<   char cwd[STRLEN];
---
 char *cwd;

186c186,187
< ---
 long path_size;

195a197,200
path_size = pathconf(".", _PC_PATH_MAX);
 cwd = (char *)xmalloc((size_t)path_size);








reply via email to

[Prev in Thread] Current Thread [Next in Thread]