bug-hurd
[Top][All Lists]
Advanced

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

Re: scsh on GNU/Hurd


From: Marcus Brinkmann
Subject: Re: scsh on GNU/Hurd
Date: Thu, 23 May 2002 23:58:44 +0200
User-agent: Mutt/1.3.28i

On Thu, May 23, 2002 at 11:38:58PM +0200, Niels Möller wrote:
> 3. In syscalls1.c, I added the lines
> 
>     /* MAXPATHLEN is not defined on the Hurd. */
>     /* FIXME: Do this properly, and get rid of the static memory as well */
>     #ifndef MAXPATHLEN
>     #define MAXPATHLEN 500
>     #endif
> 
>   just before the definiton of scm_readlink,
> 
>     /* Read the symlink into static memory. Return NULL on error. */
>     static char linkpath[MAXPATHLEN+1]; /*  Maybe unaligned. Not reentrant. */
>     char const *scm_readlink(const char *path)
>     {
>       int retval = readlink(path, linkpath, MAXPATHLEN);
>       return (char const *)
>           ((retval == -1) ? NULL : ( linkpath[retval] = '\0', linkpath ));
>     }
> 
>   This is an ugly hack, but I haven't figured out how to fix
>   scm_readlink properly.

The GLibC manual has an example code that does loop properly over readlink
while the returned name is as large as the buffer (and thus could be
truncated).

          char *
          readlink_malloc (const char *filename)
          {
            int size = 100;

            while (1)
              {
                char *buffer = (char *) xmalloc (size);
                int nchars = readlink (filename, buffer, size);
                if (nchars < 0)
                  return NULL;
                if (nchars < size)
                  return buffer;
                free (buffer);
                size *= 2;
              }
          }

Actually, this example leaks memory if readlink fails, so insert a
free (buffer) after the if (nchars < 0).  (I don't know the copyright glibc
manual examples are under).
 
> 3. sigset_t seems to be a plain unsigned int, so I had to redefine the
>    macros in scsh/gnu/sigset.h, as follows:

Actually, in the generic case, sigset_t could even be a structure type.
Can not the functions described in

File: libc.info,  Node: Signal Sets

be used to implement it portably?

Thanks,
Marcus

-- 
`Rhubarb is no Egyptian god.' Debian http://www.debian.org brinkmd@debian.org
Marcus Brinkmann              GNU    http://www.gnu.org    marcus@gnu.org
Marcus.Brinkmann@ruhr-uni-bochum.de
http://www.marcus-brinkmann.de



reply via email to

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