VLC_API int vlc_unlink( const char *filename );
VLC_API int vlc_rename( const char *oldpath, const char *newpath );
+VLC_API char *vlc_getcwd( void ) VLC_USED;
#if defined( WIN32 )
# ifndef UNDER_CE
return ret;
}
+/**
+ * Determines the current working directory.
+ *
+ * @return the current working directory (must be free()'d)
+ * or NULL on error
+ */
+char *vlc_getcwd (void)
+{
+ /* Try $PWD */
+ const char *pwd = getenv ("PWD");
+ if (pwd != NULL)
+ {
+ struct stat s1, s2;
+ /* Make sure $PWD is correct */
+ if (stat (pwd, &s1) == 0 && stat (".", &s2) == 0
+ && s1.st_dev == s2.st_dev && s1.st_ino == s2.st_ino)
+ return ToLocaleDup (pwd);
+ }
+
+ /* Otherwise iterate getcwd() until the buffer is big enough */
+ long path_max = pathconf (".", _PC_PATH_MAX);
+ size_t size = (path_max == -1 || path_max > 4096) ? 4096 : path_max;
+
+ for (;; size *= 2)
+ {
+ char *buf = malloc (size);
+ if (unlikely(buf == NULL))
+ break;
+
+ if (getcwd (buf, size) != NULL)
+#ifdef ASSUME_UTF8
+ return buf;
+#else
+ {
+ char *ret = ToLocaleDup (buf);
+ free (buf);
+ return ret; /* success */
+ }
+#endif
+ free (buf);
+
+ if (errno != ERANGE)
+ break;
+ }
+ return NULL;
+}
+
/**
* Duplicates a file descriptor. The new file descriptor has the close-on-exec
* descriptor flag set.
#endif
}
+char *vlc_getcwd (void)
+{
+ wchar_t *wdir = _wgetcwd (NULL, 0);
+ if (wdir == NULL)
+ return NULL;
+
+ char *dir = FromWide (wdir);
+ free (wdir);
+ return dir;
+}
+
/* Under Windows, these wrappers return the list of drive letters
* when called with an empty argument or just '\'. */
typedef struct vlc_DIR