OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [peripheral/] [channels/] [file.c] - Diff between revs 1244 and 1748

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 1244 Rev 1748
Line 1... Line 1...
/* file.c -- Definition of functions and structures for
/* file.c -- Definition of functions and structures for
   peripheral to communicate with host through files
   peripheral to communicate with host through files
 
 
   Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
   Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
 
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
 
   Copyright (C) 2008 Embecosm Limited
 
 
This file is part of OpenRISC 1000 Architectural Simulator.
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
 
 
This program is free software; you can redistribute it and/or modify
   This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
it under the terms of the GNU General Public License as published by
 
the Free Software Foundation; either version 2 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.
 
 
 
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 
 
#if HAVE_CONFIG_H
 
#include <config.h>
 
#endif
 
 
 
#define _GNU_SOURCE     /* for strndup */
 
 
 
#include <sys/types.h>  /* open() */
 
#include <sys/stat.h>   /* open() */
 
#include <fcntl.h>      /* open() */
 
#if HAVE_MALLOC_H
 
#include <malloc.h>     /* calloc, free */
 
#endif
 
#include <string.h>     /* strndup(), strchr() */
 
#include <errno.h>      /* errno */
 
#include <unistd.h>     /* close() */
 
 
 
#include "channel.h"    /* struct channel_ops */
   This program is free software; you can redistribute it and/or modify it
#include "fd.h"         /* struct fd_channel, fd_read(), fd_write() */
   under the terms of the GNU General Public License as published by the Free
 
   Software Foundation; either version 3 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.
 
 
 
   You should have received a copy of the GNU General Public License along
 
   with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 
/* This program is commented throughout in a fashion suitable for processing
 
   with Doxygen. */
 
 
 
 
 
/* Autoconf and/or portability configuration */
 
#include "config.h"
 
#include "port.h"
 
 
 
/* System includes */
 
#include <stdlib.h>
 
#include <unistd.h>
 
#include <errno.h>
 
#include <fcntl.h>
 
 
 
/* Package includes */
 
#include "channel.h"
 
#include "fd.h"
 
 
 
/*! Data structure representing a channel to/from a file */
struct file_channel
struct file_channel
{
{
        struct fd_channel fds;
        struct fd_channel fds;
        char * namein;
        char * namein;
        char * nameout;
        char * nameout;
};
};
 
 
static void * file_init(const char * args)
 
 
/* Forward declarations of static routines */
 
static void *file_init (const char *args);
 
static int   file_open (void *data);
 
static void  file_close (void *data);
 
static void  file_free (void *data);
 
 
 
/*! Data structure with all the operations for communicating with a file
 
    channel */
 
struct channel_ops  file_channel_ops = {
 
        .init  = file_init,
 
        .open  = file_open,
 
        .close = file_close,
 
        .read  = fd_read,
 
        .write = fd_write,
 
        .free  = file_free,
 
};
 
 
 
 
 
static void *
 
file_init (const char *args)
{
{
        struct file_channel * retval;
        struct file_channel * retval;
        char * nameout;
        char * nameout;
 
 
        if(!args)
        if(!args)
Line 79... Line 102...
        }
        }
 
 
        return (void*)retval;
        return (void*)retval;
}
}
 
 
static int file_open(void * data)
static int
 
file_open (void *data)
{
{
        struct file_channel * files = (struct file_channel *)data;
        struct file_channel * files = (struct file_channel *)data;
 
 
        if(!files)
        if(!files)
        {
        {
Line 118... Line 142...
        }
        }
 
 
        return 0;
        return 0;
}
}
 
 
static void file_close(void * data)
static void
 
file_close (void *data)
{
{
        struct file_channel * files = (struct file_channel *)data;
        struct file_channel * files = (struct file_channel *)data;
 
 
        if(files->fds.fdin != files->fds.fdout)
        if(files->fds.fdin != files->fds.fdout)
                close(files->fds.fdin);
                close(files->fds.fdin);
Line 131... Line 156...
 
 
        files->fds.fdin  = -1;
        files->fds.fdin  = -1;
        files->fds.fdout = -1;
        files->fds.fdout = -1;
}
}
 
 
static void file_free(void * data)
static void
 
file_free (void *data)
{
{
        struct file_channel * files = (struct file_channel *)data;
        struct file_channel * files = (struct file_channel *)data;
 
 
        if(files->namein != files->nameout)
        if(files->namein != files->nameout)
                free(files->namein);
                free(files->namein);
Line 143... Line 169...
        free(files->nameout);
        free(files->nameout);
 
 
        free(files);
        free(files);
}
}
 
 
struct channel_ops file_channel_ops =
 
{
 
        init:   file_init,
 
        open:   file_open,
 
        close:  file_close,
 
        read:   fd_read,
 
        write:  fd_write,
 
        free:   file_free,
 
};
 
 
 
/*
 
 * Local variables:
 
 * c-file-style: "linux"
 
 * End:
 
 */
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.