add file object from spidermonkey.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4018 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2007-01-22 17:59:27 +00:00
parent ecb1e9dae0
commit afc95ee798

View File

@ -41,9 +41,7 @@
/* /*
* JS File object * JS File object
*/ */
#if defined(JS_HAS_FILE_OBJECT) && (JS_HAS_FILE_OBJECT - 0) /* OSSP BUGFIX */ #ifdef OSSP_HACK
#ifdef OSSP
#include "../config.h" #include "../config.h"
#endif #endif
@ -52,7 +50,7 @@
/* ----------------- Platform-specific includes and defines ----------------- */ /* ----------------- Platform-specific includes and defines ----------------- */
#if defined(XP_WIN) || defined(XP_OS2) #if defined(XP_WIN) || defined(XP_OS2)
# include <direct.h> # include <direct.h>
#ifdef OSSP #ifdef OSSP_HACK
# include <dirent.h> # include <dirent.h>
# include <fcntl.h> # include <fcntl.h>
# include <time.h> # include <time.h>
@ -65,7 +63,7 @@
# define CURRENT_DIR "c:\\" # define CURRENT_DIR "c:\\"
# define POPEN _popen # define POPEN _popen
# define PCLOSE _pclose # define PCLOSE _pclose
#ifdef OSSP #ifdef OSSP_HACK
# undef mkdir # undef mkdir
# define mkdir(file, mode) _mkdir(file) # define mkdir(file, mode) _mkdir(file)
#endif #endif
@ -74,7 +72,7 @@
# include <stdio.h> # include <stdio.h>
# include <stdlib.h> # include <stdlib.h>
# include <unistd.h> # include <unistd.h>
#ifdef OSSP #ifdef OSSP_HACK
# include <sys/types.h> # include <sys/types.h>
# include <sys/stat.h> # include <sys/stat.h>
# include <dirent.h> # include <dirent.h>
@ -104,13 +102,13 @@
#include "jsscript.h" #include "jsscript.h"
#include "jsstr.h" #include "jsstr.h"
#include "jsutil.h" /* Added by JSIFY */ #include "jsutil.h" /* Added by JSIFY */
#ifdef OSSP /* CLEANUP */ #ifdef OSSP_HACK /* CLEANUP */
#include "jsfile.h" #include "jsfile.h"
#endif #endif
#include <string.h> #include <string.h>
/* NSPR dependencies */ /* NSPR dependencies */
#ifdef OSSP #ifdef OSSP_HACK
#define PR_RDONLY 0x01 #define PR_RDONLY 0x01
#define PR_WRONLY 0x02 #define PR_WRONLY 0x02
#define PR_RDWR 0x04 #define PR_RDWR 0x04
@ -174,7 +172,7 @@ JSErrorFormatString JSFile_ErrorFormatString[JSFileErr_Limit] = {
#undef MSG_DEF #undef MSG_DEF
}; };
#ifdef OSSP #ifdef OSSP_HACK
static static
#endif #endif
const JSErrorFormatString * const JSErrorFormatString *
@ -270,7 +268,7 @@ typedef struct JSFile {
JSBool hasAutoflush; /* should we force a flush for each line break? */ JSBool hasAutoflush; /* should we force a flush for each line break? */
JSBool isNative; /* if the file is using OS-specific file FILE type */ JSBool isNative; /* if the file is using OS-specific file FILE type */
/* We can actually put the following two in a union since they should never be used at the same time */ /* We can actually put the following two in a union since they should never be used at the same time */
#ifdef OSSP #ifdef OSSP_HACK
FILE *handle; /* the handle for the file, if open. */ FILE *handle; /* the handle for the file, if open. */
#else #else
PRFileDesc *handle; /* the handle for the file, if open. */ PRFileDesc *handle; /* the handle for the file, if open. */
@ -823,7 +821,7 @@ js_FileOpen(JSContext *cx, JSObject *obj, JSFile *file, char *mode){
/* Buffered version of PR_Read. Used by js_FileRead */ /* Buffered version of PR_Read. Used by js_FileRead */
static int32 static int32
#ifdef OSSP #ifdef OSSP_HACK
js_BufferedRead(JSFile * f, unsigned char *buf, int32 len) js_BufferedRead(JSFile * f, unsigned char *buf, int32 len)
#else #else
js_BufferedRead(JSFile * f, char *buf, int32 len) js_BufferedRead(JSFile * f, char *buf, int32 len)
@ -842,7 +840,7 @@ js_BufferedRead(JSFile * f, char *buf, int32 len)
} }
if (len>0) { if (len>0) {
#ifdef OSSP #ifdef OSSP_HACK
count += (!f->isNative) count += (!f->isNative)
? fread(buf, 1, len, f->handle) ? fread(buf, 1, len, f->handle)
: fread(buf, 1, len, f->nativehandle); : fread(buf, 1, len, f->nativehandle);
@ -921,7 +919,7 @@ js_FileRead(JSContext *cx, JSFile *file, jschar *buf, int32 len, int32 mode)
break; break;
case UCS2: case UCS2:
#ifdef OSSP #ifdef OSSP_HACK
count = js_BufferedRead(file, (unsigned char*)buf, len*2) >> 1; count = js_BufferedRead(file, (unsigned char*)buf, len*2) >> 1;
#else #else
count = js_BufferedRead(file, (char*)buf, len*2) >> 1; count = js_BufferedRead(file, (char*)buf, len*2) >> 1;
@ -954,7 +952,7 @@ js_FileSeek(JSContext *cx, JSFile *file, int32 len, int32 mode)
switch (mode) { switch (mode) {
case ASCII: case ASCII:
#ifdef OSSP #ifdef OSSP_HACK
count = fseek(file->handle, len, SEEK_CUR); count = fseek(file->handle, len, SEEK_CUR);
#else #else
count = PR_Seek(file->handle, len, PR_SEEK_CUR); count = PR_Seek(file->handle, len, PR_SEEK_CUR);
@ -994,7 +992,7 @@ js_FileSeek(JSContext *cx, JSFile *file, int32 len, int32 mode)
break; break;
case UCS2: case UCS2:
#ifdef OSSP #ifdef OSSP_HACK
count = fseek(file->handle, len*2, SEEK_CUR)/2; count = fseek(file->handle, len*2, SEEK_CUR)/2;
#else #else
count = PR_Seek(file->handle, len*2, PR_SEEK_CUR)/2; count = PR_Seek(file->handle, len*2, PR_SEEK_CUR)/2;
@ -1030,7 +1028,7 @@ js_FileWrite(JSContext *cx, JSFile *file, jschar *buf, int32 len, int32 mode)
for (i = 0; i<len; i++) for (i = 0; i<len; i++)
aux[i] = buf[i] % 256; aux[i] = buf[i] % 256;
#ifdef OSSP #ifdef OSSP_HACK
count = (!file->isNative) count = (!file->isNative)
? fwrite(aux, 1, len, file->handle) ? fwrite(aux, 1, len, file->handle)
: fwrite(aux, 1, len, file->nativehandle); : fwrite(aux, 1, len, file->nativehandle);
@ -1060,7 +1058,7 @@ js_FileWrite(JSContext *cx, JSFile *file, jschar *buf, int32 len, int32 mode)
} }
i+=j; i+=j;
} }
#ifdef OSSP #ifdef OSSP_HACK
j = (!file->isNative) j = (!file->isNative)
? fwrite(utfbuf, 1, i, file->handle) ? fwrite(utfbuf, 1, i, file->handle)
: fwrite(utfbuf, 1, i, file->nativehandle); : fwrite(utfbuf, 1, i, file->nativehandle);
@ -1078,7 +1076,7 @@ js_FileWrite(JSContext *cx, JSFile *file, jschar *buf, int32 len, int32 mode)
break; break;
case UCS2: case UCS2:
#ifdef OSSP #ifdef OSSP_HACK
count = (!file->isNative) count = (!file->isNative)
? fwrite(buf, 1, len*2, file->handle) >> 1 ? fwrite(buf, 1, len*2, file->handle) >> 1
: fwrite(buf, 1, len*2, file->nativehandle) >> 1; : fwrite(buf, 1, len*2, file->nativehandle) >> 1;
@ -1114,7 +1112,7 @@ js_exists(JSContext *cx, JSFile *file)
return JS_FALSE; return JS_FALSE;
} }
#ifdef OSSP #ifdef OSSP_HACK
return access(file->path, F_OK) == 0; return access(file->path, F_OK) == 0;
#else #else
return PR_Access(file->path, PR_ACCESS_EXISTS) == PR_SUCCESS; return PR_Access(file->path, PR_ACCESS_EXISTS) == PR_SUCCESS;
@ -1127,7 +1125,7 @@ js_canRead(JSContext *cx, JSFile *file)
if (!file->isNative) { if (!file->isNative) {
if (file->isOpen && !(file->mode & PR_RDONLY)) if (file->isOpen && !(file->mode & PR_RDONLY))
return JS_FALSE; return JS_FALSE;
#ifdef OSSP #ifdef OSSP_HACK
return access(file->path, R_OK) == 0; return access(file->path, R_OK) == 0;
#else #else
return PR_Access(file->path, PR_ACCESS_READ_OK) == PR_SUCCESS; return PR_Access(file->path, PR_ACCESS_READ_OK) == PR_SUCCESS;
@ -1148,7 +1146,7 @@ js_canWrite(JSContext *cx, JSFile *file)
if (!file->isNative) { if (!file->isNative) {
if (file->isOpen && !(file->mode & PR_WRONLY)) if (file->isOpen && !(file->mode & PR_WRONLY))
return JS_FALSE; return JS_FALSE;
#ifdef OSSP #ifdef OSSP_HACK
return access(file->path, W_OK) == 0; return access(file->path, W_OK) == 0;
#else #else
return PR_Access(file->path, PR_ACCESS_WRITE_OK) == PR_SUCCESS; return PR_Access(file->path, PR_ACCESS_WRITE_OK) == PR_SUCCESS;
@ -1168,7 +1166,7 @@ static JSBool
js_isFile(JSContext *cx, JSFile *file) js_isFile(JSContext *cx, JSFile *file)
{ {
if (!file->isNative) { if (!file->isNative) {
#ifdef OSSP #ifdef OSSP_HACK
struct stat info; struct stat info;
if (file->isOpen if (file->isOpen
@ -1203,7 +1201,7 @@ static JSBool
js_isDirectory(JSContext *cx, JSFile *file) js_isDirectory(JSContext *cx, JSFile *file)
{ {
if(!file->isNative){ if(!file->isNative){
#ifdef OSSP #ifdef OSSP_HACK
struct stat info; struct stat info;
#else #else
PRFileInfo info; PRFileInfo info;
@ -1213,7 +1211,7 @@ js_isDirectory(JSContext *cx, JSFile *file)
if (!js_exists(cx, file)) if (!js_exists(cx, file))
return JS_FALSE; return JS_FALSE;
#ifdef OSSP #ifdef OSSP_HACK
if (file->isOpen if (file->isOpen
? fstat(fileno(file->handle), &info) != 0 ? fstat(fileno(file->handle), &info) != 0
: stat(file->path, &info) != 0) { : stat(file->path, &info) != 0) {
@ -1243,7 +1241,7 @@ js_isDirectory(JSContext *cx, JSFile *file)
static jsval static jsval
js_size(JSContext *cx, JSFile *file) js_size(JSContext *cx, JSFile *file)
{ {
#ifdef OSSP #ifdef OSSP_HACK
struct stat info; struct stat info;
#else #else
PRFileInfo info; PRFileInfo info;
@ -1251,7 +1249,7 @@ js_size(JSContext *cx, JSFile *file)
JSFILE_CHECK_NATIVE("size"); JSFILE_CHECK_NATIVE("size");
#ifdef OSSP #ifdef OSSP_HACK
if (file->isOpen if (file->isOpen
? fstat(fileno(file->handle), &info) != 0 ? fstat(fileno(file->handle), &info) != 0
: stat(file->path, &info) != 0) { : stat(file->path, &info) != 0) {
@ -1495,7 +1493,7 @@ file_open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
} }
} else { } else {
/* TODO: what about the permissions?? Java ignores the problem... */ /* TODO: what about the permissions?? Java ignores the problem... */
#ifdef OSSP #ifdef OSSP_HACK
{ {
int my_fd; int my_fd;
int my_fd_mode = 0; int my_fd_mode = 0;
@ -1562,7 +1560,7 @@ file_close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JS_ReportWarning(cx, "Unable to close a native file, proceeding", file->path); JS_ReportWarning(cx, "Unable to close a native file, proceeding", file->path);
goto out; goto out;
}else{ }else{
#ifdef OSSP #ifdef OSSP_HACK
if (file->handle && fclose(file->handle) != 0) { if (file->handle && fclose(file->handle) != 0) {
#else #else
if(file->handle && PR_Close(file->handle)){ if(file->handle && PR_Close(file->handle)){
@ -1599,7 +1597,7 @@ file_remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JSFILE_CHECK_NATIVE("remove"); JSFILE_CHECK_NATIVE("remove");
JSFILE_CHECK_CLOSED("remove"); JSFILE_CHECK_CLOSED("remove");
#ifdef OSSP #ifdef OSSP_HACK
if (remove(file->path) == 0) { if (remove(file->path) == 0) {
#else #else
if ((js_isDirectory(cx, file) ? if ((js_isDirectory(cx, file) ?
@ -1624,7 +1622,7 @@ file_copyTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
JSFile *file = JS_GetInstancePrivate(cx, obj, &file_class, NULL); JSFile *file = JS_GetInstancePrivate(cx, obj, &file_class, NULL);
char *dest = NULL; char *dest = NULL;
#ifdef OSSP #ifdef OSSP_HACK
FILE *handle = NULL; FILE *handle = NULL;
#else #else
PRFileDesc *handle = NULL; PRFileDesc *handle = NULL;
@ -1655,7 +1653,7 @@ file_copyTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
goto out; goto out;
} }
#ifdef OSSP #ifdef OSSP_HACK
{ {
int my_fd; int my_fd;
if ((my_fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC, 0644)) != -1) if ((my_fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC, 0644)) != -1)
@ -1677,7 +1675,7 @@ file_copyTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
buffer = JS_malloc(cx, size); buffer = JS_malloc(cx, size);
#ifdef OSSP #ifdef OSSP_HACK
count = INT_TO_JSVAL((int)fread(buffer, 1, (size_t)size, file->handle)); count = INT_TO_JSVAL((int)fread(buffer, 1, (size_t)size, file->handle));
#else #else
count = INT_TO_JSVAL(PR_Read(file->handle, buffer, size)); count = INT_TO_JSVAL(PR_Read(file->handle, buffer, size));
@ -1691,7 +1689,7 @@ file_copyTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
goto out; goto out;
} }
#ifdef OSSP #ifdef OSSP_HACK
count = INT_TO_JSVAL((int)fwrite(buffer, 1, (size_t)JSVAL_TO_INT(size), handle)); count = INT_TO_JSVAL((int)fwrite(buffer, 1, (size_t)JSVAL_TO_INT(size), handle));
#else #else
count = INT_TO_JSVAL(PR_Write(handle, buffer, JSVAL_TO_INT(size))); count = INT_TO_JSVAL(PR_Write(handle, buffer, JSVAL_TO_INT(size)));
@ -1711,7 +1709,7 @@ file_copyTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if(!file_close(cx, obj, 0, NULL, rval)) goto out; if(!file_close(cx, obj, 0, NULL, rval)) goto out;
} }
#ifdef OSSP #ifdef OSSP_HACK
if (fclose(handle) != 0) { if (fclose(handle) != 0) {
#else #else
if(PR_Close(handle)!=PR_SUCCESS){ if(PR_Close(handle)!=PR_SUCCESS){
@ -1725,7 +1723,7 @@ file_copyTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return JS_TRUE; return JS_TRUE;
out: out:
if(file->isOpen && !fileInitiallyOpen){ if(file->isOpen && !fileInitiallyOpen){
#ifdef OSSP #ifdef OSSP_HACK
if (fclose(file->handle) != 0) { if (fclose(file->handle) != 0) {
#else #else
if(PR_Close(file->handle)!=PR_SUCCESS){ if(PR_Close(file->handle)!=PR_SUCCESS){
@ -1734,7 +1732,7 @@ out:
} }
} }
#ifdef OSSP #ifdef OSSP_HACK
if (handle && fclose(handle) != 0) { if (handle && fclose(handle) != 0) {
#else #else
if(handle && PR_Close(handle)!=PR_SUCCESS){ if(handle && PR_Close(handle)!=PR_SUCCESS){
@ -1759,7 +1757,7 @@ file_renameTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
dest = RESOLVE_PATH(cx, JS_GetStringBytes(JS_ValueToString(cx, argv[0]))); dest = RESOLVE_PATH(cx, JS_GetStringBytes(JS_ValueToString(cx, argv[0])));
#ifdef OSSP #ifdef OSSP_HACK
if (rename(file->path, dest) == 0){ if (rename(file->path, dest) == 0){
#else #else
if (PR_Rename(file->path, dest)==PR_SUCCESS){ if (PR_Rename(file->path, dest)==PR_SUCCESS){
@ -1788,7 +1786,7 @@ file_flush(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JSFILE_CHECK_NATIVE("flush"); JSFILE_CHECK_NATIVE("flush");
JSFILE_CHECK_OPEN("flush"); JSFILE_CHECK_OPEN("flush");
#ifdef OSSP #ifdef OSSP_HACK
if (fflush(file->handle) == 0){ if (fflush(file->handle) == 0){
#else #else
if (PR_Sync(file->handle)==PR_SUCCESS){ if (PR_Sync(file->handle)==PR_SUCCESS){
@ -2096,7 +2094,7 @@ out:
static JSBool static JSBool
file_list(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) file_list(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
#ifdef OSSP #ifdef OSSP_HACK
DIR *dir; DIR *dir;
struct dirent *entry; struct dirent *entry;
#else #else
@ -2136,7 +2134,7 @@ file_list(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
goto out; goto out;
} }
#ifdef OSSP #ifdef OSSP_HACK
dir = opendir(file->path); dir = opendir(file->path);
#else #else
dir = PR_OpenDir(file->path); dir = PR_OpenDir(file->path);
@ -2151,12 +2149,12 @@ file_list(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
array = JS_NewArrayObject(cx, 0, NULL); array = JS_NewArrayObject(cx, 0, NULL);
len = 0; len = 0;
#ifdef OSSP #ifdef OSSP_HACK
while ((entry = readdir(dir))!=NULL) { while ((entry = readdir(dir))!=NULL) {
#else #else
while ((entry = PR_ReadDir(dir, PR_SKIP_BOTH))!=NULL) { while ((entry = PR_ReadDir(dir, PR_SKIP_BOTH))!=NULL) {
#endif #endif
#ifdef OSSP #ifdef OSSP_HACK
if ( strcmp(entry->d_name, ".") == 0 if ( strcmp(entry->d_name, ".") == 0
|| strcmp(entry->d_name, "..") == 0) || strcmp(entry->d_name, "..") == 0)
continue; continue;
@ -2165,7 +2163,7 @@ file_list(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if (re!=NULL) { if (re!=NULL) {
size_t index = 0; size_t index = 0;
#ifdef OSSP #ifdef OSSP_HACK
str = JS_NewStringCopyZ(cx, entry->d_name); str = JS_NewStringCopyZ(cx, entry->d_name);
#else #else
str = JS_NewStringCopyZ(cx, entry->name); str = JS_NewStringCopyZ(cx, entry->name);
@ -2180,7 +2178,7 @@ file_list(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
} }
}else }else
if (func!=NULL) { if (func!=NULL) {
#ifdef OSSP #ifdef OSSP_HACK
str = JS_NewStringCopyZ(cx, entry->d_name); str = JS_NewStringCopyZ(cx, entry->d_name);
#else #else
str = JS_NewStringCopyZ(cx, entry->name); str = JS_NewStringCopyZ(cx, entry->name);
@ -2195,7 +2193,7 @@ file_list(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
} }
} }
#ifdef OSSP #ifdef OSSP_HACK
filePath = js_combinePath(cx, file->path, (char*)entry->d_name); filePath = js_combinePath(cx, file->path, (char*)entry->d_name);
#else #else
filePath = js_combinePath(cx, file->path, (char*)entry->name); filePath = js_combinePath(cx, file->path, (char*)entry->name);
@ -2209,7 +2207,7 @@ file_list(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
} }
v = OBJECT_TO_JSVAL(eachFile); v = OBJECT_TO_JSVAL(eachFile);
JS_SetElement(cx, array, len, &v); JS_SetElement(cx, array, len, &v);
#ifdef OSSP #ifdef OSSP_HACK
JS_SetProperty(cx, array, entry->d_name, &v); JS_SetProperty(cx, array, entry->d_name, &v);
#else #else
JS_SetProperty(cx, array, entry->name, &v); JS_SetProperty(cx, array, entry->name, &v);
@ -2217,7 +2215,7 @@ file_list(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
len++; len++;
} }
#ifdef OSSP #ifdef OSSP_HACK
if (closedir(dir) != 0) { if (closedir(dir) != 0) {
#else #else
if(PR_CloseDir(dir)!=PR_SUCCESS){ if(PR_CloseDir(dir)!=PR_SUCCESS){
@ -2259,7 +2257,7 @@ file_mkdir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
char *fullName; char *fullName;
fullName = js_combinePath(cx, file->path, dirName); fullName = js_combinePath(cx, file->path, dirName);
#ifdef OSSP #ifdef OSSP_HACK
if (mkdir(fullName, 0755) == 0) { if (mkdir(fullName, 0755) == 0) {
#else #else
if (PR_MkDir(fullName, 0755)==PR_SUCCESS){ if (PR_MkDir(fullName, 0755)==PR_SUCCESS){
@ -2283,7 +2281,7 @@ static JSBool
file_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval*rval) file_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval*rval)
{ {
JSFile *file = JS_GetInstancePrivate(cx, obj, &file_class, NULL); JSFile *file = JS_GetInstancePrivate(cx, obj, &file_class, NULL);
#ifdef OSSP #ifdef OSSP_HACK
JSString *str; JSString *str;
if ((str = JS_NewStringCopyZ(cx, file->path)) == NULL) if ((str = JS_NewStringCopyZ(cx, file->path)) == NULL)
@ -2301,8 +2299,8 @@ file_toURL(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JSFile *file = JS_GetInstancePrivate(cx, obj, &file_class, NULL); JSFile *file = JS_GetInstancePrivate(cx, obj, &file_class, NULL);
char url[MAX_PATH_LENGTH]; char url[MAX_PATH_LENGTH];
jschar *urlChars; jschar *urlChars;
#ifdef OSSP
size_t len; size_t len;
#ifdef OSSP_HACK
JSString *str; JSString *str;
#endif #endif
@ -2311,7 +2309,7 @@ file_toURL(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
sprintf(url, "file://%s", file->path); sprintf(url, "file://%s", file->path);
/* TODO: js_escape in jsstr.h may go away at some point */ /* TODO: js_escape in jsstr.h may go away at some point */
#ifdef OSSP /* BUGFIX */ #ifdef OSSP_HACK /* BUGFIX */
len = strlen(url); len = strlen(url);
if ((urlChars = js_InflateString(cx, url, &len)) == NULL) if ((urlChars = js_InflateString(cx, url, &len)) == NULL)
return JS_FALSE; return JS_FALSE;
@ -2321,7 +2319,8 @@ file_toURL(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
} }
*rval = STRING_TO_JSVAL(str); *rval = STRING_TO_JSVAL(str);
#else #else
urlChars = js_InflateString(cx, url, strlen(url)); len = strlen(url);
urlChars = js_InflateString(cx, url, &len);
if (urlChars == NULL) return JS_FALSE; if (urlChars == NULL) return JS_FALSE;
*rval = STRING_TO_JSVAL(js_NewString(cx, urlChars, strlen(url), 0)); *rval = STRING_TO_JSVAL(js_NewString(cx, urlChars, strlen(url), 0));
#endif #endif
@ -2399,7 +2398,7 @@ js_NewFileObject(JSContext *cx, char *filename)
} }
/* Internal function, used for cases which NSPR file support doesn't cover */ /* Internal function, used for cases which NSPR file support doesn't cover */
#ifdef OSSP /* CLEANUP */ #ifdef OSSP_HACK /* CLEANUP */
static static
#endif #endif
JSObject* JSObject*
@ -2514,7 +2513,7 @@ enum file_tinyid {
FILE_APPEND = -19, FILE_APPEND = -19,
FILE_REPLACE = -20, FILE_REPLACE = -20,
FILE_AUTOFLUSH = -21, FILE_AUTOFLUSH = -21,
#ifdef OSSP /* BUGFIX */ #ifdef OSSP_HACK /* BUGFIX */
FILE_ISNATIVE = -22 FILE_ISNATIVE = -22
#else #else
FILE_ISNATIVE = -22, FILE_ISNATIVE = -22,
@ -2554,13 +2553,13 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
char *bytes; char *bytes;
JSString *str; JSString *str;
jsint tiny; jsint tiny;
#ifdef OSSP #ifdef OSSP_HACK
struct stat info; struct stat info;
#else #else
PRFileInfo info; PRFileInfo info;
#endif #endif
JSBool flag; JSBool flag;
#ifdef OSSP #ifdef OSSP_HACK
struct tm *tm; struct tm *tm;
time_t t; time_t t;
#else #else
@ -2703,7 +2702,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
case FILE_CREATED: case FILE_CREATED:
SECURITY_CHECK(cx, NULL, "creationTime", file); SECURITY_CHECK(cx, NULL, "creationTime", file);
JSFILE_CHECK_NATIVE("creationTime"); JSFILE_CHECK_NATIVE("creationTime");
#ifdef OSSP #ifdef OSSP_HACK
if (file->isOpen if (file->isOpen
? fstat(fileno(file->handle), &info) != 0 ? fstat(fileno(file->handle), &info) != 0
: stat(file->path, &info) != 0) { : stat(file->path, &info) != 0) {
@ -2749,7 +2748,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
case FILE_MODIFIED: case FILE_MODIFIED:
SECURITY_CHECK(cx, NULL, "lastModified", file); SECURITY_CHECK(cx, NULL, "lastModified", file);
JSFILE_CHECK_NATIVE("lastModified"); JSFILE_CHECK_NATIVE("lastModified");
#ifdef OSSP #ifdef OSSP_HACK
if (file->isOpen if (file->isOpen
? fstat(fileno(file->handle), &info) != 0 ? fstat(fileno(file->handle), &info) != 0
: stat(file->path, &info) != 0) { : stat(file->path, &info) != 0) {
@ -2793,7 +2792,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
JSFILE_CHECK_NATIVE("length"); JSFILE_CHECK_NATIVE("length");
if (js_isDirectory(cx, file)) { /* XXX debug me */ if (js_isDirectory(cx, file)) { /* XXX debug me */
#ifdef OSSP #ifdef OSSP_HACK
DIR *dir; DIR *dir;
struct dirent *entry; struct dirent *entry;
#else #else
@ -2802,7 +2801,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
#endif #endif
jsint count = 0; jsint count = 0;
#ifdef OSSP #ifdef OSSP_HACK
if(!(dir = opendir(file->path))){ if(!(dir = opendir(file->path))){
#else #else
if(!(dir = PR_OpenDir(file->path))){ if(!(dir = PR_OpenDir(file->path))){
@ -2812,7 +2811,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
goto out; goto out;
} }
#ifdef OSSP #ifdef OSSP_HACK
while ((entry = readdir(dir))) { while ((entry = readdir(dir))) {
if ( strcmp(entry->d_name, ".") == 0 if ( strcmp(entry->d_name, ".") == 0
|| strcmp(entry->d_name, "..") == 0) || strcmp(entry->d_name, "..") == 0)
@ -2824,7 +2823,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
count++; count++;
} }
#ifdef OSSP #ifdef OSSP_HACK
if(closedir(dir) != 0){ if(closedir(dir) != 0){
#else #else
if(!PR_CloseDir(dir)){ if(!PR_CloseDir(dir)){
@ -2859,7 +2858,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
} }
if (file->isOpen && js_isFile(cx, file)) { if (file->isOpen && js_isFile(cx, file)) {
#ifdef OSSP #ifdef OSSP_HACK
int pos = fseek(file->handle, 0, SEEK_CUR); int pos = fseek(file->handle, 0, SEEK_CUR);
#else #else
int pos = PR_Seek(file->handle, 0, PR_SEEK_CUR); int pos = PR_Seek(file->handle, 0, PR_SEEK_CUR);
@ -2882,7 +2881,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
/* this is some other property -- try to use the dir["file"] syntax */ /* this is some other property -- try to use the dir["file"] syntax */
if (js_isDirectory(cx, file)) { if (js_isDirectory(cx, file)) {
#ifdef OSSP #ifdef OSSP_HACK
DIR *dir = NULL; DIR *dir = NULL;
struct dirent *entry = NULL; struct dirent *entry = NULL;
#else #else
@ -2898,7 +2897,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
prop_name = JS_GetStringBytes(str); prop_name = JS_GetStringBytes(str);
/* no native files past this point */ /* no native files past this point */
#ifdef OSSP #ifdef OSSP_HACK
dir = opendir(file->path); dir = opendir(file->path);
#else #else
dir = PR_OpenDir(file->path); dir = PR_OpenDir(file->path);
@ -2909,7 +2908,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
return JS_FALSE; return JS_FALSE;
} }
#ifdef OSSP #ifdef OSSP_HACK
while ((entry = readdir(dir)) != NULL) { while ((entry = readdir(dir)) != NULL) {
if ( strcmp(entry->d_name, ".") == 0 if ( strcmp(entry->d_name, ".") == 0
|| strcmp(entry->d_name, "..") == 0) || strcmp(entry->d_name, "..") == 0)
@ -2922,7 +2921,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
bytes = js_combinePath(cx, file->path, prop_name); bytes = js_combinePath(cx, file->path, prop_name);
*vp = OBJECT_TO_JSVAL(js_NewFileObject(cx, bytes)); *vp = OBJECT_TO_JSVAL(js_NewFileObject(cx, bytes));
JS_free(cx, bytes); JS_free(cx, bytes);
#ifdef OSSP /* BUGFIX */ #ifdef OSSP_HACK /* BUGFIX */
closedir(dir); closedir(dir);
#else #else
PR_CloseDir(dir); PR_CloseDir(dir);
@ -2930,7 +2929,7 @@ file_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
return JS_TRUE; return JS_TRUE;
} }
} }
#ifdef OSSP /* BUGFIX */ #ifdef OSSP_HACK /* BUGFIX */
closedir(dir); closedir(dir);
#else #else
PR_CloseDir(dir); PR_CloseDir(dir);
@ -2977,7 +2976,7 @@ file_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
goto out; goto out;
} }
#ifdef OSSP #ifdef OSSP_HACK
pos = fseek(file->handle, offset, SEEK_SET); pos = fseek(file->handle, offset, SEEK_SET);
#else #else
pos = PR_Seek(file->handle, offset, PR_SEEK_SET); pos = PR_Seek(file->handle, offset, PR_SEEK_SET);
@ -3108,4 +3107,3 @@ js_InitFileClass(JSContext *cx, JSObject* obj)
JSPROP_ENUMERATE | JSPROP_READONLY ); JSPROP_ENUMERATE | JSPROP_READONLY );
return file; return file;
} }
#endif /* JS_HAS_FILE_OBJECT */