Re: g_path_get_basename returns last directory name if there is a "/" at the end?



on 9/17/01 6:39 AM, Mikael Hermansson at tyan linux se wrote:

> Is this really the way it should work?
> 
> g_path_get_basename("/home/ftp/pub/files/")
> 
> returns: g_strdup("files")
> 
> imho. if there is a slash(/) at the end it should return g_strdup("")
> 
> and only g_path_get_basename("/home/ftp/pub/files/filename") should return
> g_strdup("filename")

Changing this behavior is the main reason that g_path_get_basename was
introduced to replace the old g_basename. The old g_basename could not
return "files" because it returned a pointer to the end of the original
string (and the best you can do in that case is "files/").

I'm not going to rehash the entire discussion, but in a nutshell it's useful
to get the name of the actual directory itself, even if there are one or
more trailing '/' characters. This is also how the basename shell command
from POSIX behaves, and probably how the one on the computer you are using
right now behaves too. Try it.

    -- Darin





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