Back to index

avfs  1.0.1
Defines | Functions | Variables
utils.c File Reference
#include "utils.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

Go to the source code of this file.

Defines

#define VDEV_SEP_CHAR   '#'

Functions

static int path_valid_virtual (const char *path)
int __av_path_local (const char *path)
static int make_abs_path (const char *path, char *pathbuf)
static int try_convert_path (const char *path, char *pathbuf)
int __av_get_abs_path (const char *path, char *pathbuf, const char **resp)

Variables

char __av_cwd [PATHBUF_LEN]
pthread_mutex_t __av_cwdlock
int __av_virtcwd

Define Documentation

#define VDEV_SEP_CHAR   '#'

Definition at line 14 of file utils.c.


Function Documentation

int __av_get_abs_path ( const char *  path,
char *  pathbuf,
const char **  resp 
)

Definition at line 103 of file utils.c.

{
    int res;

    if(path[0] == '/') {
        if(strchr(path, ':') != NULL) {
            const char *s;

            for(s = path; *s == '/'; s++);
            if(try_convert_path(s, pathbuf)) {
                *resp = pathbuf;
                return 0;
            }
        }
        *resp = path;
        return 0;
    }

    if(strchr(path, ':') != NULL) {
        if(try_convert_path(path, pathbuf)) {
            *resp = pathbuf;
            return 0;
        }
    }

    pthread_mutex_lock(&__av_cwdlock);
    res = make_abs_path(path, pathbuf);
    pthread_mutex_unlock(&__av_cwdlock);
    if(res == 0)
        *resp = pathbuf;

    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int __av_path_local ( const char *  path)

Definition at line 38 of file utils.c.

{
    if(strchr(path, VDEV_SEP_CHAR) == NULL) {
        if(strchr(path, ':') == NULL)
            return 1;
        else if(path_valid_virtual(path))
            return 0;
        else
            return 1;
    }
    else
        return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int make_abs_path ( const char *  path,
char *  pathbuf 
) [static]

Definition at line 53 of file utils.c.

{
    unsigned int len;

    if(__av_cwd[0] == '\0') {
        if(getcwd(__av_cwd, PATHBUF_LEN) == NULL)
            return -errno;
    }

    len = strlen(__av_cwd) + 1 + strlen(path);
    if(len >= PATHBUF_LEN)
        return -ENAMETOOLONG;

    sprintf(pathbuf, "%s/%s", __av_cwd, path);

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int path_valid_virtual ( const char *  path) [static]

Definition at line 21 of file utils.c.

{
    const char *s = path;

    while(*s == '/')
        s++;
    
    for(; *s != '\0'; s++) {
        if(*s == '/')
            return 0;
        if(*s == ':')
            return 1;
    }
    
    return 0;
}

Here is the caller graph for this function:

static int try_convert_path ( const char *  path,
char *  pathbuf 
) [static]

Definition at line 71 of file utils.c.

{
    const char *s;
    const char *prefixenv;

    if(strlen(path) + 32 > PATHBUF_LEN)
        return 0;
    
    for(s = path; *s != '\0'; s++) {
        if(*s == ':')
            break;

        if(!isalpha((int) *s) && !isdigit((int) *s) && *s != '-' && *s != '.')
            return 0;
    }

    if(s == path || *s == '\0' || (s[1] != '/' && s[1] != '\0'))
        return 0;
    
    prefixenv = getenv("AVFS_HOST_PREFIX");
    if(prefixenv == NULL)
        prefixenv = "rsh:";

    if(strlen(path) + strlen(prefixenv) + 32 > PATHBUF_LEN)
        return 0;

    sprintf(pathbuf, "/%c%s%.*s%s", VDEV_SEP_CHAR, prefixenv,
            s - path, path, s + 1);
    
    return 1;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 17 of file utils.c.

pthread_mutex_t __av_cwdlock

Definition at line 18 of file utils.c.

Definition at line 19 of file utils.c.