/*****************************************************************************
* filesystem.c: POSIX file system helpers
*****************************************************************************
- * Copyright (C) 2005-2006 the VideoLAN team
+ * Copyright (C) 2005-2006 VLC authors and VideoLAN
* Copyright © 2005-2008 Rémi Denis-Courmont
*
* Authors: Rémi Denis-Courmont <rem # videolan.org>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#include <vlc_common.h>
-#include <vlc_charset.h>
-#include <vlc_fs.h>
-#include "libvlc.h" /* vlc_mkdir */
-
#include <assert.h>
#include <stdio.h>
#include <limits.h> /* NAME_MAX */
#include <errno.h>
+
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
+#ifndef HAVE_LSTAT
+# define lstat(a, b) stat(a, b)
+#endif
#include <dirent.h>
#include <sys/socket.h>
-#ifndef HAVE_LSTAT
-# define lstat( a, b ) stat(a, b)
-#endif
+#include <vlc_common.h>
+#include <vlc_fs.h>
+#include "libvlc.h" /* vlc_mkdir */
/**
* Opens a system file handle.
flags |= O_CLOEXEC;
#endif
- const char *local_name = ToLocale (filename);
-
- if (local_name == NULL)
- {
- errno = ENOENT;
- return -1;
- }
-
- int fd = open (local_name, flags, mode);
+ int fd = open (filename, flags, mode);
if (fd != -1)
fcntl (fd, F_SETFD, FD_CLOEXEC);
-
- LocaleFree (local_name);
return fd;
}
flags |= O_CLOEXEC;
#endif
- const char *local_name = ToLocale (filename);
- if (local_name == NULL)
- {
- errno = ENOENT;
- return -1;
- }
-
#ifdef HAVE_OPENAT
- int fd = openat (dir, local_name, flags, mode);
+ int fd = openat (dir, filename, flags, mode);
if (fd != -1)
fcntl (fd, F_SETFD, FD_CLOEXEC);
#else
int fd = -1;
errno = ENOSYS;
+ (void) mode;
#endif
-
- LocaleFree (local_name);
return fd;
}
*/
int vlc_mkdir (const char *dirname, mode_t mode)
{
- char *locname = ToLocale (dirname);
- if (unlikely(locname == NULL))
- {
- errno = ENOENT;
- return -1;
- }
-
- int res = mkdir (locname, mode);
- LocaleFree (locname);
- return res;
+ return mkdir (dirname, mode);
}
/**
*/
DIR *vlc_opendir (const char *dirname)
{
- const char *local_name = ToLocale (dirname);
- if (unlikely(local_name == NULL))
- {
- errno = ENOENT;
- return NULL;
- }
-
- DIR *dir = opendir (local_name);
- LocaleFree (local_name);
- return dir;
+ return opendir (dirname);
}
/**
char *path = NULL;
long len = fpathconf (dirfd (dir), _PC_NAME_MAX);
-#ifdef NAME_MAX
/* POSIX says there shall we room for NAME_MAX bytes at all times */
if (/*len == -1 ||*/ len < NAME_MAX)
len = NAME_MAX;
-#else
- /* OS is broken. Lets assume there is no files left. */
- if (len == -1)
- return NULL;
-#endif
len += offsetof (struct dirent, d_name) + 1;
struct dirent *buf = malloc (len);
if (val != 0)
errno = val;
else if (ent != NULL)
-#ifndef __APPLE__
path = strdup (ent->d_name);
-#else
- path = FromCharset ("UTF-8-MAC", ent->d_name, strlen (ent->d_name));
-#endif
free (buf);
return path;
}
-static int vlc_statEx (const char *filename, struct stat *buf, bool deref)
-{
- const char *local_name = ToLocale (filename);
- if (unlikely(local_name == NULL))
- {
- errno = ENOENT;
- return -1;
- }
-
- int res = deref ? stat (local_name, buf)
- : lstat (local_name, buf);
- LocaleFree (local_name);
- return res;
-}
-
/**
* Finds file/inode information, as stat().
* Consider using fstat() instead, if possible.
*/
int vlc_stat (const char *filename, struct stat *buf)
{
- return vlc_statEx (filename, buf, true);
+ return stat (filename, buf);
}
/**
*/
int vlc_lstat (const char *filename, struct stat *buf)
{
- return vlc_statEx (filename, buf, false);
+ return lstat (filename, buf);
}
/**
*/
int vlc_unlink (const char *filename)
{
- const char *local_name = ToLocale (filename);
- if (unlikely(local_name == NULL))
- {
- errno = ENOENT;
- return -1;
- }
-
- int ret = unlink (local_name);
- LocaleFree (local_name);
- return ret;
+ return unlink (filename);
}
/**
*/
int vlc_rename (const char *oldpath, const char *newpath)
{
- const char *lo = ToLocale (oldpath);
- if (lo == NULL)
- goto error;
-
- const char *ln = ToLocale (newpath);
- if (ln == NULL)
- {
- LocaleFree (lo);
-error:
- errno = ENOENT;
- return -1;
- }
-
- int ret = rename (lo, ln);
- LocaleFree (lo);
- LocaleFree (ln);
- return ret;
+ return rename (oldpath, newpath);
}
/**
/* 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);
+ return strdup (pwd);
}
/* Otherwise iterate getcwd() until the buffer is big enough */
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)
return newfd;
}
-#ifdef __ANDROID__ /* && we support android < 2.3 */
-/* pipe2() is declared and available since android-9 NDK,
- * although it is available in libc.a since android-3
- * We redefine the function here in order to be able to run
- * on versions of Android older than 2.3
- */
-#include <sys/syscall.h>
-//#include <sys/linux-syscalls.h> // fucking brokeness
-int pipe2(int fds[2], int flags)
-{
- return syscall(/*__NR_pipe2 */ 359, fds, flags);
-}
-#endif /* __ANDROID__ */
-
/**
* Creates a pipe (see "man pipe" for further reference).
*/