From: <ta...@us...> - 2012-09-27 11:30:23
|
Revision: 6680 http://gfarm.svn.sourceforge.net/gfarm/?rev=6680&view=rev Author: tatebe Date: 2012-09-27 11:30:12 +0000 (Thu, 27 Sep 2012) Log Message: ----------- gfarm_realpath_by_gfarm2fs: support a new file or directory Modified Paths: -------------- gfarm_v2/branches/2.5/lib/libgfarm/gfarm/gfarm_path.c Modified: gfarm_v2/branches/2.5/lib/libgfarm/gfarm/gfarm_path.c =================================================================== --- gfarm_v2/branches/2.5/lib/libgfarm/gfarm/gfarm_path.c 2012-09-27 10:03:49 UTC (rev 6679) +++ gfarm_v2/branches/2.5/lib/libgfarm/gfarm/gfarm_path.c 2012-09-27 11:30:12 UTC (rev 6680) @@ -7,6 +7,7 @@ #include <sys/xattr.h> #endif #include <stdlib.h> +#include <string.h> #include <errno.h> #include <gfarm/gfarm.h> @@ -14,17 +15,32 @@ gfarm_error_t gfarm_realpath_by_gfarm2fs(const char *path, char **pathp) { - char *p; + char *p, *parent = NULL; + const char *base; size_t s = 0; - int saved_errno; + int saved_errno, base_len = 0; +#ifdef __GNUC__ /* workaround gcc warning: may be used uninitialized */ + base = NULL; +#endif #ifdef HAVE_SYS_XATTR_H s = lgetxattr(path, "gfarm2fs.path", NULL, 0); - if (s == -1) - return (GFARM_ERR_NO_SUCH_OBJECT); - if (pathp == NULL) + if (s == -1) { + parent = gfarm_path_dir(path); + s = lgetxattr(parent, "gfarm2fs.path", NULL, 0); + if (s == -1) { + free(parent); + return (GFARM_ERR_NO_SUCH_OBJECT); + } + base = gfarm_path_dir_skip(path); + base_len = strlen(base) + 1; /* 1 for '/' */ + path = parent; + } + if (pathp == NULL) { + free(parent); return (GFARM_ERR_NO_ERROR); - GFARM_MALLOC_ARRAY(p, s + 1); + } + GFARM_MALLOC_ARRAY(p, s + base_len + 1); /* 1 for '\0' */ if (p == NULL) return (GFARM_ERR_NO_MEMORY); if (lgetxattr(path, "gfarm2fs.path", p, s) == -1) { @@ -32,7 +48,12 @@ free(p); return (gfarm_errno_to_error(saved_errno)); } + free(parent); p[s] = '\0'; + if (base_len > 0) { + strcat(p, "/"); + strcat(p, base); + } *pathp = p; return (GFARM_ERR_NO_ERROR); #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |