Back to index

avfs  1.0.1
utils.h
Go to the documentation of this file.
00001 /*
00002     AVFS: A Virtual File System Library
00003     Copyright (C) 1998-2001  Miklos Szeredi <miklos@szeredi.hu>
00004 
00005     This program can be distributed under the terms of the GNU LGPL.
00006     See the file COPYING.LIB.
00007 */
00008 
00009 #define _GNU_SOURCE /* necessary to get definition of RTLD_NEXT */
00010 
00011 #include "cmd.h"
00012 #include "client.h"
00013 #include <dlfcn.h>
00014 #include <pthread.h>
00015 
00016 #define AVFS_DTABLE_SIZE 1024
00017 
00018 struct fileinfo {
00019     int isvirtual;
00020     int serverfh;
00021     int holderfd;
00022 };
00023 
00024 extern struct fileinfo __av_dtable[AVFS_DTABLE_SIZE];
00025 extern char __av_cwd[PATHBUF_LEN];
00026 extern pthread_mutex_t __av_cwdlock;
00027 extern int __av_virtcwd;
00028 
00029 #define ISVIRTUAL(fd)    (__av_dtable[fd].isvirtual)
00030 #define FD_OK(fd)        ((fd) >= 0 && (fd) < AVFS_DTABLE_SIZE)
00031 #define SERVERFH(fd)     (__av_dtable[fd].serverfh)
00032 
00033 int __av_get_abs_path(const char *path, char *pathbuf, const char **resp);
00034 int __av_path_local(const char *path);
00035 
00036 static inline void *__av_get_real(const char *name)
00037 {
00038     void *res;
00039     int errnosave = errno;
00040     
00041     res = dlsym(RTLD_NEXT, name);
00042     errno = errnosave;
00043 
00044     return res;
00045 }
00046 
00047 static inline int __av_maybe_local(const char *path)
00048 {
00049     int isvirtual;
00050     
00051     pthread_mutex_lock(&__av_cwdlock);
00052     isvirtual = __av_virtcwd;
00053     pthread_mutex_unlock(&__av_cwdlock);
00054 
00055     if(!isvirtual || path == NULL || path[0] == '/')
00056         return 1;
00057     else
00058         return 0;
00059 }
00060 
00061 static inline int __av_is_local(int res, const char *path)
00062 {
00063     if(res != -1 || errno != ENOENT || __av_path_local(path))
00064         return 1;
00065     else
00066         return 0;
00067 }