MinGW でlibUnihanコードをコンパイルしようとしていますが、移植が必要な関数に遭遇しました。この関数の目的は、正規のパス表現を取得することです。これはpwd.h(POSIX であり、MinGW はそうではありません) を使用するため、「~」を使用してホーム ディレクトリを意味することができpasswdますpw_dir。hereとrealpath hereのポートを少し見つけましたが、これに対処する方法についてはまだ完全に途方に暮れています。MinGW では、 で表され~、 にあるホーム ディレクトリがまだあります/home/nateが、これは POSIX ではないpwd.hため、このホーム ディレクトリがどこにあるかを見つけるのを手伝う必要はありません。
Q: MinGW で適切に動作するように以下の関数を移植するにはどうすればよいですか?
/**
 * Return the canonicalized absolute pathname.
 *
 * It works exactly the same with realpath(3), except this function can handle the path with ~,
 * where realpath cannot.
 *
 * @param path The path to be resolved.
 * @param resolved_path Buffer for holding the resolved_path.
 * @return resolved path, NULL is the resolution is not sucessful.
 */
gchar*
truepath(const gchar *path, gchar *resolved_path){
    gchar workingPath[PATH_MAX];
    gchar fullPath[PATH_MAX];
    gchar *result=NULL;
    g_strlcpy(workingPath,path,PATH_MAX);
//     printf("*** path=%s \n",path);
    if ( workingPath[0] != '~' ){
        result = realpath(workingPath, resolved_path);
    }else{
        gchar *firstSlash, *suffix, *homeDirStr;
        struct passwd *pw;
        // initialize variables
        firstSlash = suffix = homeDirStr = NULL;
    firstSlash = strchr(workingPath, DIRECTORY_SEPARATOR);
        if (firstSlash == NULL)
            suffix = "";
        else
        {
            *firstSlash = 0;    // so userName is null terminated
            suffix = firstSlash + 1;
        }
        if (workingPath[1] == '\0')
            pw = getpwuid( getuid() );
        else
            pw = getpwnam( &workingPath[1] );
        if (pw != NULL)
            homeDirStr = pw->pw_dir;
        if (homeDirStr != NULL){
        gint ret=g_sprintf(fullPath, "%s%c%s", homeDirStr, DIRECTORY_SEPARATOR, suffix);
        if (ret>0){
        result = realpath(fullPath, resolved_path);
        }
    }
    }
    return result;
}