-/* $Id: httpd.js,v 1.54 2005/07/12 12:13:48 mmondor Exp $ */
+/* $Id: httpd.js,v 1.55 2005/07/12 13:00:14 mmondor Exp $ */
/*
* Copyright (c) 2005, Matthew Mondor
* Server identification
*/
SERVER_VERSION = 'mmondor_js_httpd/0.0.1 (NetBSD)';
-SERVER_CVSID = '$Id: httpd.js,v 1.54 2005/07/12 12:13:48 mmondor Exp $';
+SERVER_CVSID = '$Id: httpd.js,v 1.55 2005/07/12 13:00:14 mmondor Exp $';
{
var contents = '';
var data;
+ var fd;
- var fd = new FD();
try {
- fd.open(file, FD.O_RDONLY);
+ /*
+ * If we were provided with a filename, rather than a
+ * filedescriptor object, open the filename. Otherwise,
+ * read from the specified FD.
+ */
+ if (typeof file != 'object') {
+ fd = new FD();
+ fd.open(file, FD.O_RDONLY);
+ } else
+ fd = file;
for (;;) {
data = fd.read(8192);
if (data.length == 0)
} catch (x) {
err.put(x + " at file_read()\n");
}
- fd.close();
-
- return contents;
-}
-
-/*
- * Similar to the above function, but works with an already open FD object
- * and closes it.
- */
-function file_read2(fd)
-{
- var contents = '';
- var data;
-
- try {
- for (;;) {
- data = fd.read(8192);
- if (data.length == 0)
- break;
- contents += data;
- }
- } catch (x) {
- err.put(x + " at file_read2()\n");
- }
- fd.close();
+ if (typeof file != 'object')
+ fd.close();
return contents;
}
fd.close();
} else {
try {
- data = file_read2(fd);
+ data = file_read(fd);
s = 'obj.script = function() {' + data + '}';
eval(s);
o = new JSO(path.real, st.st_mtime,