monit-dev
[Top][All Lists]
Advanced

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

Re: POSIX.1 getcwd


From: Igor Homyakov
Subject: Re: POSIX.1 getcwd
Date: Mon, 1 Sep 2003 12:05:45 +0400
User-agent: Mutt/1.4.1i

Ok, but STRLEN is to short
$ grep PATH_MAX  /usr/include/linux/limits.h
#define PATH_MAX        4096    /* # chars in a path name including nul */

from my man 3 getcwd (linux)
<cite>
       Note that PATH_MAX need not be a compile-time  constant;  it
       may depend on the filesystem and may even be unlimited.
</cite>

my code was inspired by OpenGroup spec
http://www.opengroup.org/onlinepubs/007904975/functions/getcwd.html

* Martin Pala <address@hidden> [030901 10:56]:
> 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);
> >>
> >>   
> >>
> >
> > 
> >
> 
> 
> 
> 
> _______________________________________________
> monit-dev mailing list
> address@hidden
> http://mail.nongnu.org/mailman/listinfo/monit-dev
> 
-- 
Igor Homyakov
<igor.homyakov AT ramax.ru>




reply via email to

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