[2797] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

Re: [PATCH 1/2] Fixed :unsub to make it work if ~/.zephyr.subs is

daemon@ATHENA.MIT.EDU (David A Benjamin)
Mon Nov 15 23:39:12 2010

Date: Mon, 15 Nov 2010 23:39:09 -0500 (EST)
From: David A Benjamin <davidben@MIT.EDU>
To: Jason Gross <jasongross9@gmail.com>
cc: Karl Ramm <kcr@1ts.org>, Kevin Chen <kchen@mit.edu>, barnowl-dev@mit.edu
In-Reply-To: <AANLkTikLfBWGGwCV7C8aTrwxVaRZo7ixk5+ggkv1rWY8@mail.gmail.com>

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

---1257051904-14195983-1289882074=:15631
Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-15; FORMAT=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE
Content-ID: <alpine.DEB.1.10.1011152335211.15631@dr-wily.mit.edu>

If we're going to implement this with readlink, we may as well use Glib's=
=20
version.

http://library.gnome.org/devel/glib/stable/glib-File-Utilities.html#g-file-=
read-link

It also provides a wrapper over stat that'll probably be shorter for=20
testing if a file is a symlink:

http://library.gnome.org/devel/glib/stable/glib-File-Utilities.html#g-file-=
test

David

On Mon, 15 Nov 2010, Jason Gross wrote:

> I don't think I'm competent enough in C to do this, especially with such =
a=A0small code block.
> At least, I can't keep both functionality and call it my own code. =A0Lik=
e, I think the best I can do, without sacrificing efficiency (I'm assuming
> xrealloc/reallov is faster than free(buffer); buffer =3D malloc(buffer, s=
ize);(?)) is something like:
> /* mallocs successively bigger buffers for readlink, until it succeeds or=
 readlink fails.
> =A0* If readlink or realloc fails, this function returns NULL */
> char *readlink_malloc(const char *filename) {
> =A0=A0size_t size =3D 128; /* initial guess for a long enough path length=
 */
> =A0=A0int nchars =3D (int)size;
> =A0=A0char *buffer =3D NULL;
> =A0=A0while (TRUE) {
> =A0=A0 =A0buffer =3D (char *)realloc(buffer, size);
> =A0=A0 =A0if (buffer =3D=3D NULL) { /* we cannot allocate a big enough bu=
ffer for the file name */
> =A0=A0 =A0 =A0free(buffer);
> =A0=A0 =A0 =A0return NULL;
> =A0=A0 =A0}
> =A0=A0 =A0nchars =3D readlink(filename, buffer, size);
> =A0=A0 =A0if (nchars < 0) { /* readlink failed */
> =A0=A0 =A0 =A0free(buffer);
> =A0=A0 =A0 =A0return NULL;
> =A0=A0 =A0}
> =A0=A0 =A0if (size < nchars)
> =A0=A0 =A0 =A0return buffer;
> =A0=A0 =A0size *=3D 2;
> =A0=A0}
> }
> On Mon, Nov 15, 2010 at 9:59 PM, Karl Ramm <kcr@1ts.org> wrote:
>       Jason Gross <jasongross9@gmail.com> writes:
>=20
> > So should I rewrite the code to use readlink instead? =A0If so, is ther=
e a
> > problem with naming the code readlink_malloc, or should I give it a nam=
e
> > with an owl_ prefix to avoid conflicts? =A0Is an inline citation of
> > http://www.gnu.org/s/libc/manual/html_node/Symbolic-Links.html sufficie=
nt?
>=20
> I would rewrite the code entirely, because we probably don't want the gnu=
 "free"
> documentation license infecting our code.
>=20
> kcr
>=20
> > -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 an=
y
> >> 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, whic=
h I
> >> > found by searching google (
> >> >
> >> http://www.google.com/search?sourceid=3Dchrome&ie=3DUTF-8&q=3Dresolve+=
symbolic+link+c
> >> ).
> >> > =A0It also gave the function readlink and the code
> >> >
> >> > char *
> >> > readlink_malloc (const char *filename)
> >> > {
> >> > =A0 int size =3D 100;
> >> > =A0 char *buffer =3D NULL;
> >> >
> >> > =A0 while (1)
> >> > =A0 =A0 {
> >> > =A0 =A0 =A0 buffer =3D (char *) xrealloc (buffer, size);
> >> > =A0 =A0 =A0 int nchars =3D readlink (filename, buffer, size);
> >> > =A0 =A0 =A0 if (nchars < 0)
> >> > =A0 =A0 =A0 =A0 {
> >> > =A0 =A0 =A0 =A0 =A0 free (buffer);
> >> > =A0 =A0 =A0 =A0 =A0 return NULL;
> >> > =A0 =A0 =A0 =A0 }
> >> > =A0 =A0 =A0 if (nchars < size)
> >> > =A0 =A0 =A0 =A0 return buffer;
> >> > =A0 =A0 =A0 size *=3D 2;
> >> > =A0 =A0 }
> >> > }
> >> >
> >> > Is this a GNUism, or is readlink generally available? =A0Should we u=
se this
> >> > instead? =A0(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:
> >> >>
> >> >> =A0On Mon, 15 Nov 2010, Kevin Chen wrote:
> >> >>>
> >> >>> =A0On Mon, 15 Nov 2010, Karl Ramm wrote:
> >> >>>>
> >> >>>> =A0David A Benjamin <davidben@MIT.EDU> writes:
> >> >>>>>
> >> >>>>> =A0The 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 so=
meone
> >> >>>>> 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
> >> >>
> >>
>=20
>=20
>=20
>
---1257051904-14195983-1289882074=:15631--

home help back first fref pref prev next nref lref last post