[pulseaudio-commits] r1467 - /trunk/src/utils/padsp.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Mon Jun 11 04:22:31 PDT 2007
Author: ossman
Date: Mon Jun 11 13:22:30 2007
New Revision: 1467
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1467&root=3Dpulseaudio&vi=
ew=3Drev
Log:
Support stat() and friends as some programs (audacity) likes to check if
the device node is there first.
Modified:
trunk/src/utils/padsp.c
Modified: trunk/src/utils/padsp.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/utils/padsp.c?rev=3D1=
467&root=3Dpulseaudio&r1=3D1466&r2=3D1467&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/utils/padsp.c (original)
+++ trunk/src/utils/padsp.c Mon Jun 11 13:22:30 2007
@@ -116,9 +116,17 @@
static int (*_close)(int) =3D NULL;
static int (*_open)(const char *, int, mode_t) =3D NULL;
static FILE* (*_fopen)(const char *path, const char *mode) =3D NULL;
+static int (*_stat)(const char *, struct stat *) =3D NULL;
+#ifdef _STAT_VER
+static int (*___xstat)(int, const char *, struct stat *) =3D NULL;
+#endif
#ifdef HAVE_OPEN64
static int (*_open64)(const char *, int, mode_t) =3D NULL;
static FILE* (*_fopen64)(const char *path, const char *mode) =3D NULL;
+static int (*_stat64)(const char *, struct stat64 *) =3D NULL;
+#ifdef _STAT_VER
+static int (*___xstat64)(int, const char *, struct stat64 *) =3D NULL;
+#endif
#endif
static int (*_fclose)(FILE *f) =3D NULL;
static int (*_access)(const char *, int) =3D NULL;
@@ -167,6 +175,38 @@
pthread_mutex_lock(&func_mutex); \
if (!_access) \
_access =3D (int (*)(const char*, int)) dlsym_fn(RTLD_NEXT, "acces=
s"); \
+ pthread_mutex_unlock(&func_mutex); \
+} while(0)
+
+#define LOAD_STAT_FUNC() \
+do { \
+ pthread_mutex_lock(&func_mutex); \
+ if (!_stat) \
+ _stat =3D (int (*)(const char *, struct stat *)) dlsym_fn(RTLD_NEX=
T, "stat"); \
+ pthread_mutex_unlock(&func_mutex); \
+} while(0)
+
+#define LOAD_STAT64_FUNC() \
+do { \
+ pthread_mutex_lock(&func_mutex); \
+ if (!_stat64) \
+ _stat64 =3D (int (*)(const char *, struct stat64 *)) dlsym_fn(RTLD=
_NEXT, "stat64"); \
+ pthread_mutex_unlock(&func_mutex); \
+} while(0)
+
+#define LOAD_XSTAT_FUNC() \
+do { \
+ pthread_mutex_lock(&func_mutex); \
+ if (!___xstat) \
+ ___xstat =3D (int (*)(int, const char *, struct stat *)) dlsym_fn(=
RTLD_NEXT, "__xstat"); \
+ pthread_mutex_unlock(&func_mutex); \
+} while(0)
+
+#define LOAD_XSTAT64_FUNC() \
+do { \
+ pthread_mutex_lock(&func_mutex); \
+ if (!___xstat64) \
+ ___xstat64 =3D (int (*)(int, const char *, struct stat64 *)) dlsym=
_fn(RTLD_NEXT, "__xstat64"); \
pthread_mutex_unlock(&func_mutex); \
} while(0)
=
@@ -2348,7 +2388,107 @@
return 0;
}
=
+int stat(const char *pathname, struct stat *buf) {
#ifdef HAVE_OPEN64
+ struct stat64 parent;
+#else
+ struct stat parent;
+#endif
+ int ret;
+
+ if (!pathname || !buf) {
+ errno =3D EFAULT;
+ return -1;
+ }
+
+ if (strcmp(pathname, "/dev/dsp") !=3D 0 &&
+ strcmp(pathname, "/dev/adsp") !=3D 0 &&
+ strcmp(pathname, "/dev/sndstat") !=3D 0 &&
+ strcmp(pathname, "/dev/mixer") !=3D 0) {
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": stat(%s)\n", pathname);
+ LOAD_STAT_FUNC();
+ return _stat(pathname, buf);
+ }
+
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": stat(%s)\n", pathname);
+
+#ifdef _STAT_VER
+#ifdef HAVE_OPEN64
+ ret =3D __xstat64(_STAT_VER, "/dev", &parent);
+#else
+ ret =3D __xstat(_STAT_VER, "/dev", &parent);
+#endif
+#else
+#ifdef HAVE_OPEN64
+ ret =3D stat64("/dev", &parent);
+#else
+ ret =3D stat("/dev", &parent);
+#endif
+#endif
+
+ if (ret) {
+ debug(DEBUG_LEVEL_NORMAL, __FILE__": unable to stat \"/dev\"\n");
+ return -1;
+ }
+
+ buf->st_dev =3D parent.st_dev;
+ buf->st_ino =3D 0xDEADBEEF; /* FIXME: Can we do this in a safe way? =
*/
+ buf->st_mode =3D S_IFCHR | S_IRUSR | S_IWUSR;
+ buf->st_nlink =3D 1;
+ buf->st_uid =3D getuid();
+ buf->st_gid =3D getgid();
+ buf->st_rdev =3D 0x0E03; /* FIXME: Linux specific */
+ buf->st_size =3D 0;
+ buf->st_atime =3D 1181557705;
+ buf->st_mtime =3D 1181557705;
+ buf->st_ctime =3D 1181557705;
+ buf->st_blksize =3D 1;
+ buf->st_blocks =3D 0;
+
+ return 0;
+}
+
+#ifdef HAVE_OPEN64
+
+int stat64(const char *pathname, struct stat64 *buf) {
+ struct stat oldbuf;
+ int ret;
+
+ if (!pathname || !buf) {
+ errno =3D EFAULT;
+ return -1;
+ }
+
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": stat64(%s)\n", pathname);
+
+ if (strcmp(pathname, "/dev/dsp") !=3D 0 &&
+ strcmp(pathname, "/dev/adsp") !=3D 0 &&
+ strcmp(pathname, "/dev/sndstat") !=3D 0 &&
+ strcmp(pathname, "/dev/mixer") !=3D 0) {
+ LOAD_STAT64_FUNC();
+ return _stat64(pathname, buf);
+ }
+
+ ret =3D stat(pathname, &oldbuf);
+ if (ret)
+ return ret;
+
+ buf->st_dev =3D oldbuf.st_dev;
+ buf->st_ino =3D oldbuf.st_ino;
+ buf->st_mode =3D oldbuf.st_mode;
+ buf->st_nlink =3D oldbuf.st_nlink;
+ buf->st_uid =3D oldbuf.st_uid;
+ buf->st_gid =3D oldbuf.st_gid;
+ buf->st_rdev =3D oldbuf.st_rdev;
+ buf->st_size =3D oldbuf.st_size;
+ buf->st_atime =3D oldbuf.st_atime;
+ buf->st_mtime =3D oldbuf.st_mtime;
+ buf->st_ctime =3D oldbuf.st_ctime;
+ buf->st_blksize =3D oldbuf.st_blksize;
+ buf->st_blocks =3D oldbuf.st_blocks;
+
+ return 0;
+}
=
int open64(const char *filename, int flags, ...) {
va_list args;
@@ -2371,6 +2511,62 @@
=
return open(filename, flags, mode);
}
+
+#endif
+
+#ifdef _STAT_VER
+
+int __xstat(int ver, const char *pathname, struct stat *buf) {
+ if (!pathname || !buf) {
+ errno =3D EFAULT;
+ return -1;
+ }
+
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": __xstat(%s)\n", pathname);
+
+ if (strcmp(pathname, "/dev/dsp") !=3D 0 &&
+ strcmp(pathname, "/dev/adsp") !=3D 0 &&
+ strcmp(pathname, "/dev/sndstat") !=3D 0 &&
+ strcmp(pathname, "/dev/mixer") !=3D 0) {
+ LOAD_XSTAT_FUNC();
+ return ___xstat(ver, pathname, buf);
+ }
+
+ if (ver !=3D _STAT_VER) {
+ errno =3D EINVAL;
+ return -1;
+ }
+
+ return stat(pathname, buf);
+}
+
+#ifdef HAVE_OPEN64
+
+int __xstat64(int ver, const char *pathname, struct stat64 *buf) {
+ if (!pathname || !buf) {
+ errno =3D EFAULT;
+ return -1;
+ }
+
+ debug(DEBUG_LEVEL_VERBOSE, __FILE__": __xstat64(%s)\n", pathname);
+
+ if (strcmp(pathname, "/dev/dsp") !=3D 0 &&
+ strcmp(pathname, "/dev/adsp") !=3D 0 &&
+ strcmp(pathname, "/dev/sndstat") !=3D 0 &&
+ strcmp(pathname, "/dev/mixer") !=3D 0) {
+ LOAD_XSTAT64_FUNC();
+ return ___xstat64(ver, pathname, buf);
+ }
+
+ if (ver !=3D _STAT_VER) {
+ errno =3D EINVAL;
+ return -1;
+ }
+
+ return stat64(pathname, buf);
+}
+
+#endif
=
#endif
=
More information about the pulseaudio-commits
mailing list