This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: readlink null termination problem


On Mon, 5 Jan 2004, Christopher Faylor wrote:

> On Tue, Jan 06, 2004 at 08:17:14AM +0800, peter garrone wrote:
> >I was having a problem with mkcramfs on cygwin creating symbolic links
> >for the compressed linux filesystem.
> >
> >mkcramfs uses malloc to allocate a buffer that it sends to the readlink function in cygwin path.cc
> >That function uses memcpy to do a copy of the link into a buffer.
> >Neither mkcramfs or readlink is null-terminating the string representing the link.
> >
> >Probably both are at fault. I have fixed my problem by zeroing the buffer in mkcramfs
> > before calling readlink, but it would probably be beneficial if readlink terminates
> > the returned string, if there is room.
>
> NAME
>        readlink - read value of a symbolic link
>
> SYNOPSIS
>        #include <unistd.h>
>
>        int readlink(const char *path, char *buf, size_t bufsiz);
>
> DESCRIPTION
>        readlink  places  the  contents of the symbolic link path in the buffer
>        buf, which has size bufsiz.  readlink does not append a  NUL  character
>        to  buf.   It will truncate the contents (to a length of bufsiz charac-
>        ters), in case the buffer is too small to hold all of the contents.

And, to ward off the obvious next question:

RETURN VALUES
       The  call  returns  the  count of characters placed in the
       buffer if it succeeds, or a -1 if an error occurs, placing
       the error code in errno.

HTH,
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"I have since come to realize that being between your mentor and his route
to the bathroom is a major career booster."  -- Patrick Naughton

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]