problem with realpath()

problem with realpath()

Post by John Gord » Fri, 09 Nov 2001 23:47:10



i'm having trouble with this code:

  int main(int argc, char **argv)
  {
    int index;
    char resolvedpath[1000];

    for(index = 1; index < argc; index++)
    {
      if(realpath(argv[index], resolvedpath))
        printf("%-20s -> %s\n", argv[index], resolvedpath);
      else
        printf("%s: none\n", argv[index]);
    }

    return EXIT_SUCCESS;

  }

when i call this program with a filename that doesn't exist, index
gets overwritten with zeroes and the for loops forever!

if i declare resolvedpath to be at least PATH_MAX characters, though,
all is well.  the manpage didn't mention this, however.  am i doing
something wrong?

---
"... What with you being his parents and all, I think that you could
be trusted not to shaft him."  -- Robert Chang, rec.games.board


 
 
 

problem with realpath()

Post by Carl McGuir » Fri, 09 Nov 2001 23:58:42



Quote:> i'm having trouble with this code:

>   int main(int argc, char **argv)
>   {
>     int index;
>     char resolvedpath[1000];

>     for(index = 1; index < argc; index++)
>     {
>       if(realpath(argv[index], resolvedpath))
>         printf("%-20s -> %s\n", argv[index], resolvedpath);
>       else
>         printf("%s: none\n", argv[index]);
>     }

>     return EXIT_SUCCESS;

>   }

> when i call this program with a filename that doesn't exist, index
> gets overwritten with zeroes and the for loops forever!

> if i declare resolvedpath to be at least PATH_MAX characters, though,
> all is well.  the manpage didn't mention this, however.

It does on my man page (AIX 4.3.3), PATH_MAX may be used as an appropriate
array size for resolved_name/resolvedpath.

- Show quoted text -

>  am i doing
> something wrong?

> ---
> "... What with you being his parents and all, I think that you could
> be trusted not to shaft him."  -- Robert Chang, rec.games.board




 
 
 

problem with realpath()

Post by Casper H.S. Dik - Network Security Engine » Sat, 10 Nov 2001 00:27:32


[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


>It does on my man page (AIX 4.3.3), PATH_MAX may be used as an appropriate
>array size for resolved_name/resolvedpath.

On Solaris, the manual page lists it as:

     #include <sys/param.h>

     char *realpath(file_name, resolved_name)
     char *file_name;
     char resolved_name[MAXPATHLEN];

which I would take as a clear indication that I cannot pass just
any sized buffer as "resolved_name".

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

1. equivalent of stdlib.h's realpath() in a shell script?

There are times when I need to convert a file path into an absolute
path.  For this, I've written a C program which I named 'realpath'
which invokes stdlib.h's realpath() method.  I call this program from
a shell script.

Is there another way to convert file paths into absolute/canonical
paths using some shell functions or one of the more commonly available
tools?  It would be nice to avoid having to take my C program around
and build it on all the systems I use.
--
Benjamin

2. HELP ME

3. kernel space realpath()

4. Windows Owns Desktop, Extends Lead in Server Market

5. relocation error: symbol not found: realpath

6. any way to automatically prune duplicates from bash history ?

7. Needed: BSD source to realpath()

8. VFAT

9. problems, problems, 37.5 GB, problems, 1024, problems...

10. Installation problems, problems, problems!

11. PPP stands for Problem Problem Problem

12. Problems... problems ... more problems

13. Problems, Problems, Problems