[2796] in BarnOwl Developers
Re: [PATCH 1/2] Fixed :unsub to make it work if ~/.zephyr.subs is a
daemon@ATHENA.MIT.EDU (Jason Gross)
Mon Nov 15 23:11:45 2010
In-Reply-To: <uushbfix9b6.fsf@1ts.org>
From: Jason Gross <jasongross9@gmail.com>
Date: Mon, 15 Nov 2010 23:11:12 -0500
To: Karl Ramm <kcr@1ts.org>
Cc: David A Benjamin <davidben@mit.edu>, Kevin Chen <kchen@mit.edu>,
barnowl-dev@mit.edu
--000e0cd4d4bc195f62049523c174
Content-Type: text/plain; charset=ISO-8859-1
I don't think I'm competent enough in C to do this, especially with such
a small code block.
At least, I can't keep both functionality and call it my own code. Like, I
think the best I can do, without sacrificing efficiency (I'm assuming
xrealloc/reallov is faster than free(buffer); buffer = malloc(buffer,
size);(?)) is something like:
/* mallocs successively bigger buffers for readlink, until it succeeds or
readlink fails.
* If readlink or realloc fails, this function returns NULL */
char *readlink_malloc(const char *filename) {
size_t size = 128; /* initial guess for a long enough path length */
int nchars = (int)size;
char *buffer = NULL;
while (TRUE) {
buffer = (char *)realloc(buffer, size);
if (buffer == NULL) { /* we cannot allocate a big enough buffer for the
file name */
free(buffer);
return NULL;
}
nchars = readlink(filename, buffer, size);
if (nchars < 0) { /* readlink failed */
free(buffer);
return NULL;
}
if (size < nchars)
return buffer;
size *= 2;
}
}
On Mon, Nov 15, 2010 at 9:59 PM, Karl Ramm <kcr@1ts.org> wrote:
> Jason Gross <jasongross9@gmail.com> writes:
>
> > So should I rewrite the code to use readlink instead? If so, is there a
> > problem with naming the code readlink_malloc, or should I give it a name
> > with an owl_ prefix to avoid conflicts? Is an inline citation of
> > http://www.gnu.org/s/libc/manual/html_node/Symbolic-Links.htmlsufficient?
>
> I would rewrite the code entirely, because we probably don't want the gnu
> "free"
> documentation license infecting our code.
>
> kcr
>
> > -Jason
> >
> > On Mon, Nov 15, 2010 at 5:55 PM, Karl Ramm <kcr@1ts.org> wrote:
> >
> >> Readlink is a syscall available on any UNIX with symlinks, which is any
> >> you're going to be running barnowl on.
> >>
> >> kcr
> >> Jason Gross <jasongross9@gmail.com> writes:
> >>
> >> > Where do I find information about where a function is supported?
> >> >
> >> > I found canonicalize_file_name at
> >> > http://www.gnu.org/s/libc/manual/html_node/Symbolic-Links.html, which
> I
> >> > found by searching google (
> >> >
> >>
> http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=resolve+symbolic+link+c
> >> ).
> >> > It also gave the function readlink and the code
> >> >
> >> > char *
> >> > readlink_malloc (const char *filename)
> >> > {
> >> > int size = 100;
> >> > char *buffer = NULL;
> >> >
> >> > while (1)
> >> > {
> >> > buffer = (char *) xrealloc (buffer, size);
> >> > int nchars = readlink (filename, buffer, size);
> >> > if (nchars < 0)
> >> > {
> >> > free (buffer);
> >> > return NULL;
> >> > }
> >> > if (nchars < size)
> >> > return buffer;
> >> > size *= 2;
> >> > }
> >> > }
> >> >
> >> > Is this a GNUism, or is readlink generally available? Should we use
> this
> >> > instead? (I think Python uses readlink for its realpath.)
> >> >
> >> > -Jason
> >> >
> >> > On Mon, Nov 15, 2010 at 5:14 PM, David A Benjamin <davidben@mit.edu>
> >> wrote:
> >> >
> >> >> On Mon, 15 Nov 2010, David A Benjamin wrote:
> >> >>
> >> >> On Mon, 15 Nov 2010, Kevin Chen wrote:
> >> >>>
> >> >>> On Mon, 15 Nov 2010, Karl Ramm wrote:
> >> >>>>
> >> >>>> David A Benjamin <davidben@MIT.EDU> writes:
> >> >>>>>
> >> >>>>> The man pages says it's equivalent to realpath(path, NULL)
> >> >>>>>> which... doesn't appear to be a GNUism?
> >> >>>>>>
> >> >>>>>> We can also add another AC_REPLACE_FUNCS, but they're annoying.
> >> >>>>>>
> >> >>>>>> David
> >> >>>>>>
> >> >>>>>
> >> >>>>> It's in POSIX 2001 so we.. probably get to point and laugh if
> someone
> >> >>>>> doesn't have it?
> >> >>>>>
> >> >>>>
> >> >>>> My manpage (for realpath) says that passing NULL as the second
> >> argument
> >> >>>> is a non-standard glibc extension.
> >> >>>>
> >> >>>>
> >> >>> Lovely. Meh, we can allocate a PATH_MAX-sized buffer. Not terribly
> >> >>> exciting.
> >> >>>
> >> >>>
> >> >> Err, on second thought, reading all the NOTES in my version of the
> man
> >> >> page, can I run away screaming now?
> >> >>
> >> >> Maybe glib has an implementation that isn't awful.
> >> >>
> >> >> David
> >> >>
> >>
>
--000e0cd4d4bc195f62049523c174
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div>I don't think I'm competent enough in C to do this, especially=
with such a=A0small code block.</div><div>At least, I can't keep both =
functionality and call it my own code. =A0Like, I think the best I can do, =
without sacrificing efficiency (I'm assuming xrealloc/reallov is faster=
than free(buffer); buffer =3D malloc(buffer, size);(?)) is something like:=
</div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">/* mallocs successively bigger buffers for readlink, until it succeeds=
or readlink fails.</font></div><div><font class=3D"Apple-style-span" face=
=3D"'courier new', monospace">=A0* If readlink or realloc fails, th=
is function returns NULL */</font></div>
<div><div><font class=3D"Apple-style-span" face=3D"'courier new', m=
onospace">char *readlink_malloc(const char *filename) {</font></div><div><f=
ont class=3D"Apple-style-span" face=3D"'courier new', monospace">=
=A0=A0size_t size =3D 128; /* initial guess for a long enough path length *=
/</font></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">=A0=A0int nchars =3D (int)size;</font></div><div><font class=3D"Apple-=
style-span" face=3D"'courier new', monospace">=A0=A0char *buffer =
=3D NULL;</font></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">=A0=A0while (TRUE) {</font></div><div><font class=3D"Apple-style-span"=
face=3D"'courier new', monospace">=A0=A0 =A0buffer =3D (char *)rea=
lloc(buffer, size);</font></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">=A0=A0 =A0if (buffer =3D=3D NULL) { /* we cannot allocate a big enough=
buffer for the file name */</font></div><div><font class=3D"Apple-style-sp=
an" face=3D"'courier new', monospace">=A0=A0 =A0 =A0free(buffer);</=
font></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">=A0=A0 =A0 =A0return NULL;</font></div><div><font class=3D"Apple-style=
-span" face=3D"'courier new', monospace">=A0=A0 =A0}</font></div><d=
iv><font class=3D"Apple-style-span" face=3D"'courier new', monospac=
e">=A0=A0 =A0nchars =3D readlink(filename, buffer, size);</font></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">=A0=A0 =A0if (nchars < 0) { /* readlink failed */</font></div><div>=
<font class=3D"Apple-style-span" face=3D"'courier new', monospace">=
=A0=A0 =A0 =A0free(buffer);</font></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">=A0=A0 =A0 =A0return NULL;</font></div><div><font class=3D"Apple-style=
-span" face=3D"'courier new', monospace">=A0=A0 =A0}</font></div><d=
iv><font class=3D"Apple-style-span" face=3D"'courier new', monospac=
e">=A0=A0 =A0if (size < nchars)</font></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">=A0=A0 =A0 =A0return buffer;</font></div><div><font class=3D"Apple-sty=
le-span" face=3D"'courier new', monospace">=A0=A0 =A0size *=3D 2;</=
font></div><div><font class=3D"Apple-style-span" face=3D"'courier new&#=
39;, monospace">=A0=A0}</font></div>
<div><font class=3D"Apple-style-span" face=3D"'courier new', monosp=
ace">}</font></div></div><div class=3D"gmail_quote">On Mon, Nov 15, 2010 at=
9:59 PM, Karl Ramm <span dir=3D"ltr"><<a href=3D"mailto:kcr@1ts.org">kc=
r@1ts.org</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex;"><div class=3D"im">Jason Gross <<a href=
=3D"mailto:jasongross9@gmail.com">jasongross9@gmail.com</a>> writes:<br>
<br>
</div><div class=3D"im">> So should I rewrite the code to use readlink i=
nstead? =A0If so, is there a<br>
> problem with naming the code readlink_malloc, or should I give it a na=
me<br>
> with an owl_ prefix to avoid conflicts? =A0Is an inline citation of<br=
>
> <a href=3D"http://www.gnu.org/s/libc/manual/html_node/Symbolic-Links.h=
tml" target=3D"_blank">http://www.gnu.org/s/libc/manual/html_node/Symbolic-=
Links.html</a> sufficient?<br>
<br>
</div>I would rewrite the code entirely, because we probably don't want=
the gnu "free"<br>
documentation license infecting our code.<br>
<br>
kcr<br>
<div><div></div><div class=3D"h5"><br>
> -Jason<br>
><br>
> On Mon, Nov 15, 2010 at 5:55 PM, Karl Ramm <<a href=3D"mailto:kcr@1=
ts.org">kcr@1ts.org</a>> wrote:<br>
><br>
>> Readlink is a syscall available on any UNIX with symlinks, which i=
s any<br>
>> you're going to be running barnowl on.<br>
>><br>
>> kcr<br>
>> Jason Gross <<a href=3D"mailto:jasongross9@gmail.com">jasongros=
s9@gmail.com</a>> writes:<br>
>><br>
>> > Where do I find information about where a function is support=
ed?<br>
>> ><br>
>> > I found canonicalize_file_name at<br>
>> > <a href=3D"http://www.gnu.org/s/libc/manual/html_node/Symboli=
c-Links.html" target=3D"_blank">http://www.gnu.org/s/libc/manual/html_node/=
Symbolic-Links.html</a>, which I<br>
>> > found by searching google (<br>
>> ><br>
>> <a href=3D"http://www.google.com/search?sourceid=3Dchrome&ie=
=3DUTF-8&q=3Dresolve+symbolic+link+c" target=3D"_blank">http://www.goog=
le.com/search?sourceid=3Dchrome&ie=3DUTF-8&q=3Dresolve+symbolic+lin=
k+c</a><br>
>> ).<br>
>> > =A0It also gave the function readlink and the code<br>
>> ><br>
>> > char *<br>
>> > readlink_malloc (const char *filename)<br>
>> > {<br>
>> > =A0 int size =3D 100;<br>
>> > =A0 char *buffer =3D NULL;<br>
>> ><br>
>> > =A0 while (1)<br>
>> > =A0 =A0 {<br>
>> > =A0 =A0 =A0 buffer =3D (char *) xrealloc (buffer, size);<br>
>> > =A0 =A0 =A0 int nchars =3D readlink (filename, buffer, size);=
<br>
>> > =A0 =A0 =A0 if (nchars < 0)<br>
>> > =A0 =A0 =A0 =A0 {<br>
>> > =A0 =A0 =A0 =A0 =A0 free (buffer);<br>
>> > =A0 =A0 =A0 =A0 =A0 return NULL;<br>
>> > =A0 =A0 =A0 =A0 }<br>
>> > =A0 =A0 =A0 if (nchars < size)<br>
>> > =A0 =A0 =A0 =A0 return buffer;<br>
>> > =A0 =A0 =A0 size *=3D 2;<br>
>> > =A0 =A0 }<br>
>> > }<br>
>> ><br>
>> > Is this a GNUism, or is readlink generally available? =A0Shou=
ld we use this<br>
>> > instead? =A0(I think Python uses readlink for its realpath.)<=
br>
>> ><br>
>> > -Jason<br>
>> ><br>
>> > On Mon, Nov 15, 2010 at 5:14 PM, David A Benjamin <<a href=
=3D"mailto:davidben@mit.edu">davidben@mit.edu</a>><br>
>> wrote:<br>
>> ><br>
>> >> On Mon, 15 Nov 2010, David A Benjamin wrote:<br>
>> >><br>
>> >> =A0On Mon, 15 Nov 2010, Kevin Chen wrote:<br>
>> >>><br>
>> >>> =A0On Mon, 15 Nov 2010, Karl Ramm wrote:<br>
>> >>>><br>
>> >>>> =A0David A Benjamin <<a href=3D"mailto:davidbe=
n@MIT.EDU">davidben@MIT.EDU</a>> writes:<br>
>> >>>>><br>
>> >>>>> =A0The man pages says it's equivalent to =
realpath(path, NULL)<br>
>> >>>>>> which... doesn't appear to be a GNUis=
m?<br>
>> >>>>>><br>
>> >>>>>> We can also add another AC_REPLACE_FUNCS,=
but they're annoying.<br>
>> >>>>>><br>
>> >>>>>> David<br>
>> >>>>>><br>
>> >>>>><br>
>> >>>>> It's in POSIX 2001 so we.. probably get t=
o point and laugh if someone<br>
>> >>>>> doesn't have it?<br>
>> >>>>><br>
>> >>>><br>
>> >>>> My manpage (for realpath) says that passing NULL =
as the second<br>
>> argument<br>
>> >>>> is a non-standard glibc extension.<br>
>> >>>><br>
>> >>>><br>
>> >>> Lovely. Meh, we can allocate a PATH_MAX-sized buffer.=
Not terribly<br>
>> >>> exciting.<br>
>> >>><br>
>> >>><br>
>> >> Err, on second thought, reading all the NOTES in my versi=
on of the man<br>
>> >> page, can I run away screaming now?<br>
>> >><br>
>> >> Maybe glib has an implementation that isn't awful.<br=
>
>> >><br>
>> >> David<br>
>> >><br>
>><br>
</div></div></blockquote></div><br>
--000e0cd4d4bc195f62049523c174--