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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [libnetworking/] [rtems_webserver/] [webpage.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 * Page.c -- Support for page retrieval.
3
 *
4
 * Copyright (c) GoAhead Software Inc., 1995-2000. All Rights Reserved.
5
 *
6
 * See the file "license.txt" for usage and redistribution license requirements
7
 */
8
 
9
/******************************** Description *********************************/
10
 
11
/*
12
 *      This module provides page retrieval handling. It provides support for
13
 *      reading web pages from file systems and has expansion for ROMed web
14
 *      pages.
15
 */
16
 
17
/********************************* Includes ***********************************/
18
 
19
#include        "wsIntrn.h"
20
 
21
/*********************************** Code *************************************/
22
/*
23
 *      Open a web page. lpath is the local filename. path is the URL path name.
24
 */
25
 
26
int websPageOpen(webs_t wp, char_t *lpath, char_t *path, int mode, int perm)
27
{
28
        a_assert(websValid(wp));
29
 
30
#if WEBS_PAGE_ROM
31
        return websRomPageOpen(wp, path, mode, perm);
32
#else
33
        return (wp->docfd = gopen(lpath, mode, perm));
34
#endif /* WEBS_PAGE_ROM */
35
}
36
 
37
/******************************************************************************/
38
/*
39
 *      Close a web page
40
 */
41
 
42
void websPageClose(webs_t wp)
43
{
44
        a_assert(websValid(wp));
45
 
46
#if WEBS_PAGE_ROM
47
        websRomPageClose(wp->docfd);
48
#else
49
        if (wp->docfd >= 0) {
50
                close(wp->docfd);
51
                wp->docfd = -1;
52
        }
53
#endif
54
}
55
 
56
/******************************************************************************/
57
/*
58
 *      Stat a web page lpath is the local filename. path is the URL path name.
59
 */
60
 
61
int websPageStat(webs_t wp, char_t *lpath, char_t *path, websStatType* sbuf)
62
{
63
#if WEBS_PAGE_ROM
64
        return websRomPageStat(path, sbuf);
65
#else
66
        gstat_t s;
67
 
68
        if (gstat(lpath, &s) < 0) {
69
                return -1;
70
        }
71
        sbuf->size = s.st_size;
72
        sbuf->mtime = s.st_mtime;
73
        sbuf->isDir = s.st_mode & S_IFDIR;
74
        return 0;
75
#endif
76
}
77
 
78
/******************************************************************************/
79
/*
80
 *      Is this file a directory?
81
 */
82
 
83
int websPageIsDirectory(char_t *lpath)
84
{
85
#if WEBS_PAGE_ROM
86
        websStatType    sbuf;
87
 
88
        if (websRomPageStat(lpath, &sbuf) >= 0) {
89
                return(sbuf.isDir);
90
        } else {
91
                return 0;
92
        }
93
#else
94
        gstat_t sbuf;
95
 
96
        if (gstat(lpath, &sbuf) >= 0) {
97
                return(sbuf.st_mode & S_IFDIR);
98
        } else {
99
                return 0;
100
        }
101
#endif
102
}
103
 
104
 
105
/******************************************************************************/
106
/*
107
 *      Read a web page. Returns the number of _bytes_ read.
108
 *      len is the size of buf, in bytes.
109
 */
110
 
111
int websPageReadData(webs_t wp, char *buf, int nBytes)
112
{
113
 
114
#if WEBS_PAGE_ROM
115
        a_assert(websValid(wp));
116
        return websRomPageReadData(wp, buf, nBytes);
117
#else
118
        a_assert(websValid(wp));
119
        return read(wp->docfd, buf, nBytes);
120
#endif
121
}
122
 
123
/******************************************************************************/
124
/*
125
 *      Move file pointer offset bytes.
126
 */
127
 
128
void websPageSeek(webs_t wp, long offset)
129
{
130
        a_assert(websValid(wp));
131
 
132
#if WEBS_PAGE_ROM
133
        websRomPageSeek(wp, offset, SEEK_CUR);
134
#else
135
        lseek(wp->docfd, offset, SEEK_CUR);
136
#endif
137
}
138
 
139
/******************************************************************************/
140
 

powered by: WebSVN 2.1.0

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