#include <andrewos.h>
#include <class.h>
#include <fileent.eh>

boolean fileentry__InitializeObject(classid, self)
struct classheader *classid;
struct fileentry *self;
{
    self->path = NULL;
    return TRUE;
}

void fileentry__FinalizeObject(classid, self)
struct classheader *classid;
struct fileentry *self;
{
    if (self->path != NULL) {
	free(self->path);
    }
}

char *fileentry__Shorten(classid, name)
struct classheader *classid;
char *name;
{
    char *lastSlash;

    lastSlash = rindex(name, '/');
    if (lastSlash != NULL)  {
	return lastSlash + 1;
    }
    else {
	return name;
    }
}

char *fileentry__TildeResolve(classid, name)
struct classheader *classid;
char *name;
{
}

void fileentry__SetPath(self, path)
struct fileentry *self;
char *path;
{
    if (self->path != NULL) {
	free(self->path);
    }
    self->path = (char *) malloc(strlen(path) + 1);
    strcpy(self->path, path);
}

char *fileentry__GetPath(self)
struct fileentry *self;
{
    return self->path;
}

boolean fileentry__CanRead(self)
struct fileentry *self;
{
    return self->path != NULL && access(self->path, R_OK) == 0;
}

boolean fileentry__CanWrite(self)
struct fileentry *self;
{
    return self->path != NULL && access(self->path, W_OK) == 0;
}

