Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH] Fix for cwd in os.pmc on HP-UX

2 views
Skip to first unread message

Nick Glencross

unread,
Jan 3, 2006, 11:11:04 AM1/3/06
to p6i
This tidy patch makes cwd work on HP-UX. As it stands at the moment it
gives an 'invalid argument' exception (although it gave a more
meaningful message earlier this morning).

The manual page for getcwd says:

If buf is a NULL pointer, getcwd() obtains size bytes of space using
malloc() (see malloc(3C)). In this case, the pointer returned by
getcwd() can be used as the argument in a subsequent call to free()
(see malloc(3C)). Invoking getcwd() with buf as a null pointer is not
recommended because this functionality may be removed from the HP-UX
operating system in a future release.

It therefore looks like 'getcwd (NULL, 0)' might work from this, but
in fact returns [EINTVAL] The size of the argument is zero.

I've therefore changed it to use an automatic variable (which assumes
that PATH_MAX is constant to conform to c89) and removed the free.
Failing that, the code can be preserved as it is, but replace size
with PATH_MAX+1 (although as the manual page says, this may not
continue to work).

With this and r10855, os.t will pass on HP-UX.

Regards,

Nick

parrot_r10861_os_getwd_patch.txt

Alberto Simões

unread,
Jan 3, 2006, 11:23:59 AM1/3/06
to Nick Glencross, p6i
Applied in r10864.
Maintained the old version as well, because some folks were complaining
not to have PATH_MAX defined. I hope those can work the way it was before.

Cheers.
Alberto

> ------------------------------------------------------------------------
>
> Index: src/classes/os.pmc
> ===================================================================
> --- src/classes/os.pmc (revision 10861)
> +++ src/classes/os.pmc (working copy)
> @@ -61,11 +61,12 @@
>
> METHOD STRING* cwd() {
> #ifndef _MSC_VER
> - STRING *scwd;
> - char * cwd = getcwd(NULL, 0);
> + char buf[PATH_MAX+1];
> +
> + char * cwd = getcwd(buf, PATH_MAX+1);
> +
> if (cwd) {
> - scwd = string_from_cstring(interpreter, cwd, strlen(cwd));
> - mem_sys_free(cwd);
> + STRING *scwd = string_from_cstring(interpreter, cwd, strlen(cwd));
> return scwd;
> } else {
> char *errmsg = strerror(errno);
>
>

--
Alberto Simões - Departamento de Informática - Universidade do Minho
Campus de Gualtar - 4710-057 Braga - Portugal

0 new messages