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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [libnetworking/] [rtems_webserver/] [webpage.c] - Diff between revs 30 and 173

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 30 Rev 173
/*
/*
 * Page.c -- Support for page retrieval.
 * Page.c -- Support for page retrieval.
 *
 *
 * Copyright (c) Go Ahead Software Inc., 1995-1999. All Rights Reserved.
 * Copyright (c) Go Ahead Software Inc., 1995-1999. All Rights Reserved.
 *
 *
 * See the file "license.txt" for usage and redistribution license requirements
 * See the file "license.txt" for usage and redistribution license requirements
 */
 */
 
 
/******************************** Description *********************************/
/******************************** Description *********************************/
 
 
/*
/*
 *      This module provides page retrieval handling. It provides support for
 *      This module provides page retrieval handling. It provides support for
 *      reading web pages from file systems and has expansion for ROMed web
 *      reading web pages from file systems and has expansion for ROMed web
 *      pages.
 *      pages.
 */
 */
 
 
/********************************* Includes ***********************************/
/********************************* Includes ***********************************/
 
 
#include        "wsIntrn.h"
#include        "wsIntrn.h"
 
 
/*********************************** Code *************************************/
/*********************************** Code *************************************/
/*
/*
 *      Open a web page. lpath is the local filename. path is the URL path name.
 *      Open a web page. lpath is the local filename. path is the URL path name.
 */
 */
 
 
int websPageOpen(webs_t wp, char_t *lpath, char_t *path, int mode, int perm)
int websPageOpen(webs_t wp, char_t *lpath, char_t *path, int mode, int perm)
{
{
        a_assert(websValid(wp));
        a_assert(websValid(wp));
 
 
#if WEBS_PAGE_ROM
#if WEBS_PAGE_ROM
        return websRomPageOpen(wp, path, mode, perm);
        return websRomPageOpen(wp, path, mode, perm);
#else
#else
        return (wp->docfd = gopen(lpath, mode, perm));
        return (wp->docfd = gopen(lpath, mode, perm));
#endif /* WEBS_PAGE_ROM */
#endif /* WEBS_PAGE_ROM */
}
}
 
 
/******************************************************************************/
/******************************************************************************/
/*
/*
 *      Close a web page
 *      Close a web page
 */
 */
 
 
void websPageClose(webs_t wp)
void websPageClose(webs_t wp)
{
{
#if WEBS_PAGE_ROM
#if WEBS_PAGE_ROM
        websRomPageClose(wp->docfd);
        websRomPageClose(wp->docfd);
#else
#else
        if (wp->docfd >= 0) {
        if (wp->docfd >= 0) {
                close(wp->docfd);
                close(wp->docfd);
                wp->docfd = -1;
                wp->docfd = -1;
        }
        }
#endif
#endif
}
}
 
 
/******************************************************************************/
/******************************************************************************/
/*
/*
 *      Stat a web page lpath is the local filename. path is the URL path name.
 *      Stat a web page lpath is the local filename. path is the URL path name.
 */
 */
 
 
int websPageStat(webs_t wp, char_t *lpath, char_t *path, websStatType* sbuf)
int websPageStat(webs_t wp, char_t *lpath, char_t *path, websStatType* sbuf)
{
{
#if WEBS_PAGE_ROM
#if WEBS_PAGE_ROM
        return websRomPageStat(path, sbuf);
        return websRomPageStat(path, sbuf);
#else
#else
        gstat_t s;
        gstat_t s;
 
 
        if (gstat(lpath, &s) < 0) {
        if (gstat(lpath, &s) < 0) {
                return -1;
                return -1;
        }
        }
        sbuf->size = s.st_size;
        sbuf->size = s.st_size;
        sbuf->mtime = s.st_mtime;
        sbuf->mtime = s.st_mtime;
        sbuf->isDir = s.st_mode & S_IFDIR;
        sbuf->isDir = s.st_mode & S_IFDIR;
        return 0;
        return 0;
#endif
#endif
}
}
 
 
/******************************************************************************/
/******************************************************************************/
/*
/*
 *      Is this file a directory?
 *      Is this file a directory?
 */
 */
 
 
int websPageIsDirectory(char_t *lpath)
int websPageIsDirectory(char_t *lpath)
{
{
#if WEBS_PAGE_ROM
#if WEBS_PAGE_ROM
        websStatType    sbuf;
        websStatType    sbuf;
 
 
        if (websRomPageStat(lpath, &sbuf) >= 0) {
        if (websRomPageStat(lpath, &sbuf) >= 0) {
                return(sbuf.isDir);
                return(sbuf.isDir);
        } else {
        } else {
                return 0;
                return 0;
        }
        }
#else
#else
        gstat_t sbuf;
        gstat_t sbuf;
 
 
        if (gstat(lpath, &sbuf) >= 0) {
        if (gstat(lpath, &sbuf) >= 0) {
                return(sbuf.st_mode & S_IFDIR);
                return(sbuf.st_mode & S_IFDIR);
        } else {
        } else {
                return 0;
                return 0;
        }
        }
#endif
#endif
}
}
 
 
 
 
/******************************************************************************/
/******************************************************************************/
/*
/*
 *      Read a web page. Returns the number of _bytes_ read.
 *      Read a web page. Returns the number of _bytes_ read.
 *      len is the size of buf, in bytes.
 *      len is the size of buf, in bytes.
 */
 */
 
 
int websPageReadData(webs_t wp, char *buf, int nBytes)
int websPageReadData(webs_t wp, char *buf, int nBytes)
{
{
 
 
#if WEBS_PAGE_ROM
#if WEBS_PAGE_ROM
        a_assert(websValid(wp));
        a_assert(websValid(wp));
        return websRomPageReadData(wp, buf, nBytes);
        return websRomPageReadData(wp, buf, nBytes);
#else
#else
        a_assert(websValid(wp));
        a_assert(websValid(wp));
        return read(wp->docfd, buf, nBytes);
        return read(wp->docfd, buf, nBytes);
#endif
#endif
}
}
 
 
/******************************************************************************/
/******************************************************************************/
/*
/*
 *      Move file pointer offset bytes.
 *      Move file pointer offset bytes.
 */
 */
 
 
void websPageSeek(webs_t wp, long offset)
void websPageSeek(webs_t wp, long offset)
{
{
        a_assert(websValid(wp));
        a_assert(websValid(wp));
 
 
#if WEBS_PAGE_ROM
#if WEBS_PAGE_ROM
        websRomPageSeek(wp, offset, SEEK_CUR);
        websRomPageSeek(wp, offset, SEEK_CUR);
#else
#else
        lseek(wp->docfd, offset, SEEK_CUR);
        lseek(wp->docfd, offset, SEEK_CUR);
#endif
#endif
}
}
 
 
/******************************************************************************/
/******************************************************************************/
 
 
 
 

powered by: WebSVN 2.1.0

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