/*
* JS File object
*/
-#if defined(JS_HAS_FILE_OBJECT) && (JS_HAS_FILE_OBJECT - 0) /* OSSP BUGFIX */
-
-#ifdef OSSP
+#ifdef OSSP_HACK
#include "../config.h"
#endif
/* ----------------- Platform-specific includes and defines ----------------- */
#if defined(XP_WIN) || defined(XP_OS2)
# include <direct.h>
-#ifdef OSSP
+#ifdef OSSP_HACK
# include <dirent.h>
# include <fcntl.h>
# include <time.h>
# define CURRENT_DIR "c:\\"
# define POPEN _popen
# define PCLOSE _pclose
-#ifdef OSSP
+#ifdef OSSP_HACK
# undef mkdir
# define mkdir(file, mode) _mkdir(file)
#endif
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
-#ifdef OSSP
+#ifdef OSSP_HACK
# include <sys/types.h>
# include <sys/stat.h>
# include <dirent.h>
#include "jsscript.h"
#include "jsstr.h"
#include "jsutil.h" /* Added by JSIFY */
-#ifdef OSSP /* CLEANUP */
+#ifdef OSSP_HACK /* CLEANUP */
#include "jsfile.h"
#endif
#include <string.h>
/* NSPR dependencies */
-#ifdef OSSP
+#ifdef OSSP_HACK
#define PR_RDONLY 0x01
#define PR_WRONLY 0x02
#define PR_RDWR 0x04
#undef MSG_DEF
};
-#ifdef OSSP
+#ifdef OSSP_HACK
static
#endif
const JSErrorFormatString *
JSBool hasAutoflush; /* should we force a flush for each line break? */
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 */
-#ifdef OSSP
+#ifdef OSSP_HACK
FILE *handle; /* the handle for the file, if open. */
#else
PRFileDesc *handle; /* the handle for the file, if open. */
/* Buffered version of PR_Read. Used by js_FileRead */
static int32
-#ifdef OSSP
+#ifdef OSSP_HACK
js_BufferedRead(JSFile * f, unsigned char *buf, int32 len)
#else
js_BufferedRead(JSFile * f, char *buf, int32 len)
}
if (len>0) {
-#ifdef OSSP
+#ifdef OSSP_HACK
count += (!f->isNative)
? fread(buf, 1, len, f->handle)
: fread(buf, 1, len, f->nativehandle);
break;
case UCS2:
-#ifdef OSSP
+#ifdef OSSP_HACK
count = js_BufferedRead(file, (unsigned char*)buf, len*2) >> 1;
#else
count = js_BufferedRead(file, (char*)buf, len*2) >> 1;
switch (mode) {
case ASCII:
-#ifdef OSSP
+#ifdef OSSP_HACK
count = fseek(file->handle, len, SEEK_CUR);
#else
count = PR_Seek(file->handle, len, PR_SEEK_CUR);
break;
case UCS2:
-#ifdef OSSP
+#ifdef OSSP_HACK
count = fseek(file->handle, len*2, SEEK_CUR)/2;
#else
count = PR_Seek(file->handle, len*2, PR_SEEK_CUR)/2;
for (i = 0; i<len; i++)
aux[i] = buf[i] % 256;
-#ifdef OSSP
+#ifdef OSSP_HACK
count = (!file->isNative)
? fwrite(aux, 1, len, file->handle)
: fwrite(aux, 1, len, file->nativehandle);
}
i+=j;
}
-#ifdef OSSP
+#ifdef OSSP_HACK
j = (!file->isNative)
? fwrite(utfbuf, 1, i, file->handle)
: fwrite(utfbuf, 1, i, file->nativehandle);
break;
case UCS2:
-#ifdef OSSP
+#ifdef OSSP_HACK
count = (!file->isNative)
? fwrite(buf, 1, len*2, file->handle) >> 1
: fwrite(buf, 1, len*2, file->nativehandle) >> 1;
return JS_FALSE;
}
-#ifdef OSSP
+#ifdef OSSP_HACK
return access(file->path, F_OK) == 0;
#else
return PR_Access(file->path, PR_ACCESS_EXISTS) == PR_SUCCESS;
if (!file->isNative) {
if (file->isOpen && !(file->mode & PR_RDONLY))
return JS_FALSE;
-#ifdef OSSP
+#ifdef OSSP_HACK
return access(file->path, R_OK) == 0;
#else
return PR_Access(file->path, PR_ACCESS_READ_OK) == PR_SUCCESS;
if (!file->isNative) {
if (file->isOpen && !(file->mode & PR_WRONLY))
return JS_FALSE;
-#ifdef OSSP
+#ifdef OSSP_HACK
return access(file->path, W_OK) == 0;
#else
return PR_Access(file->path, PR_ACCESS_WRITE_OK) == PR_SUCCESS;
js_isFile(JSContext *cx, JSFile *file)
{
if (!file->isNative) {
-#ifdef OSSP
+#ifdef OSSP_HACK
struct stat info;
if (file->isOpen
js_isDirectory(JSContext *cx, JSFile *file)
{
if(!file->isNative){
-#ifdef OSSP
+#ifdef OSSP_HACK
struct stat info;
#else
PRFileInfo info;
if (!js_exists(cx, file))
return JS_FALSE;
-#ifdef OSSP
+#ifdef OSSP_HACK
if (file->isOpen
? fstat(fileno(file->handle), &info) != 0
: stat(file->path, &info) != 0) {
static jsval
js_size(JSContext *cx, JSFile *file)
{
-#ifdef OSSP
+#ifdef OSSP_HACK
struct stat info;
#else
PRFileInfo info;
JSFILE_CHECK_NATIVE("size");
-#ifdef OSSP
+#ifdef OSSP_HACK
if (file->isOpen
? fstat(fileno(file->handle), &info) != 0
: stat(file->path, &info) != 0) {
}
} else {
/* TODO: what about the permissions?? Java ignores the problem... */
-#ifdef OSSP
+#ifdef OSSP_HACK
{
int my_fd;
int my_fd_mode = 0;
JS_ReportWarning(cx, "Unable to close a native file, proceeding", file->path);
goto out;
}else{
-#ifdef OSSP
+#ifdef OSSP_HACK
if (file->handle && fclose(file->handle) != 0) {
#else
if(file->handle && PR_Close(file->handle)){
JSFILE_CHECK_NATIVE("remove");
JSFILE_CHECK_CLOSED("remove");
-#ifdef OSSP
+#ifdef OSSP_HACK
if (remove(file->path) == 0) {
#else
if ((js_isDirectory(cx, file) ?
{
JSFile *file = JS_GetInstancePrivate(cx, obj, &file_class, NULL);
char *dest = NULL;
-#ifdef OSSP
+#ifdef OSSP_HACK
FILE *handle = NULL;
#else
PRFileDesc *handle = NULL;
goto out;
}
-#ifdef OSSP
+#ifdef OSSP_HACK
{
int my_fd;
if ((my_fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC, 0644)) != -1)
buffer = JS_malloc(cx, size);
-#ifdef OSSP
+#ifdef OSSP_HACK
count = INT_TO_JSVAL((int)fread(buffer, 1, (size_t)size, file->handle));
#else
count = INT_TO_JSVAL(PR_Read(file->handle, buffer, size));
goto out;
}
-#ifdef OSSP
+#ifdef OSSP_HACK
count = INT_TO_JSVAL((int)fwrite(buffer, 1, (size_t)JSVAL_TO_INT(size), handle));
#else
count = INT_TO_JSVAL(PR_Write(handle, buffer, JSVAL_TO_INT(size)));
if(!file_close(cx, obj, 0, NULL, rval)) goto out;
}
-#ifdef OSSP
+#ifdef OSSP_HACK
if (fclose(handle) != 0) {
#else
if(PR_Close(handle)!=PR_SUCCESS){
return JS_TRUE;
out:
if(file->isOpen && !fileInitiallyOpen){
-#ifdef OSSP
+#ifdef OSSP_HACK
if (fclose(file->handle) != 0) {
#else
if(PR_Close(file->handle)!=PR_SUCCESS){
}
}
-#ifdef OSSP
+#ifdef OSSP_HACK
if (handle && fclose(handle) != 0) {
#else
if(handle && PR_Close(handle)!=PR_SUCCESS){
dest = RESOLVE_PATH(cx, JS_GetStringBytes(JS_ValueToString(cx, argv[0])));
-#ifdef OSSP
+#ifdef OSSP_HACK
if (rename(file->path, dest) == 0){
#else
if (PR_Rename(file->path, dest)==PR_SUCCESS){
JSFILE_CHECK_NATIVE("flush");
JSFILE_CHECK_OPEN("flush");
-#ifdef OSSP
+#ifdef OSSP_HACK
if (fflush(file->handle) == 0){
#else
if (PR_Sync(file->handle)==PR_SUCCESS){
static JSBool
file_list(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
-#ifdef OSSP
+#ifdef OSSP_HACK
DIR *dir;
struct dirent *entry;
#else
goto out;
}
-#ifdef OSSP
+#ifdef OSSP_HACK
dir = opendir(file->path);
#else
dir = PR_OpenDir(file->path);
array = JS_NewArrayObject(cx, 0, NULL);
len = 0;
-#ifdef OSSP
+#ifdef OSSP_HACK
while ((entry = readdir(dir))!=NULL) {
#else
while ((entry = PR_ReadDir(dir, PR_SKIP_BOTH))!=NULL) {
#endif
-#ifdef OSSP
+#ifdef OSSP_HACK
if ( strcmp(entry->d_name, ".") == 0
|| strcmp(entry->d_name, "..") == 0)
continue;
if (re!=NULL) {
size_t index = 0;
-#ifdef OSSP
+#ifdef OSSP_HACK
str = JS_NewStringCopyZ(cx, entry->d_name);
#else
str = JS_NewStringCopyZ(cx, entry->name);
}
}else
if (func!=NULL) {
-#ifdef OSSP
+#ifdef OSSP_HACK
str = JS_NewStringCopyZ(cx, entry->d_name);
#else
str = JS_NewStringCopyZ(cx, entry->name);
}
}
-#ifdef OSSP
+#ifdef OSSP_HACK
filePath = js_combinePath(cx, file->path, (char*)entry->d_name);
#else
filePath = js_combinePath(cx, file->path, (char*)entry->name);
}
v = OBJECT_TO_JSVAL(eachFile);
JS_SetElement(cx, array, len, &v);
-#ifdef OSSP
+#ifdef OSSP_HACK
JS_SetProperty(cx, array, entry->d_name, &v);
#else
JS_SetProperty(cx, array, entry->name, &v);
len++;
}
-#ifdef OSSP
+#ifdef OSSP_HACK
if (closedir(dir) != 0) {
#else
if(PR_CloseDir(dir)!=PR_SUCCESS){
char *fullName;
fullName = js_combinePath(cx, file->path, dirName);
-#ifdef OSSP
+#ifdef OSSP_HACK
if (mkdir(fullName, 0755) == 0) {
#else
if (PR_MkDir(fullName, 0755)==PR_SUCCESS){
file_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval*rval)
{
JSFile *file = JS_GetInstancePrivate(cx, obj, &file_class, NULL);
-#ifdef OSSP
+#ifdef OSSP_HACK
JSString *str;
if ((str = JS_NewStringCopyZ(cx, file->path)) == NULL)
JSFile *file = JS_GetInstancePrivate(cx, obj, &file_class, NULL);
char url[MAX_PATH_LENGTH];
jschar *urlChars;
-#ifdef OSSP
size_t len;
+#ifdef OSSP_HACK
JSString *str;
#endif
sprintf(url, "file://%s", file->path);
/* TODO: js_escape in jsstr.h may go away at some point */
-#ifdef OSSP /* BUGFIX */
+#ifdef OSSP_HACK /* BUGFIX */
len = strlen(url);
if ((urlChars = js_InflateString(cx, url, &len)) == NULL)
return JS_FALSE;
}
*rval = STRING_TO_JSVAL(str);
#else
- urlChars = js_InflateString(cx, url, strlen(url));
+ len = strlen(url);
+ urlChars = js_InflateString(cx, url, &len);
if (urlChars == NULL) return JS_FALSE;
*rval = STRING_TO_JSVAL(js_NewString(cx, urlChars, strlen(url), 0));
#endif
}
/* Internal function, used for cases which NSPR file support doesn't cover */
-#ifdef OSSP /* CLEANUP */
+#ifdef OSSP_HACK /* CLEANUP */
static
#endif
JSObject*
FILE_APPEND = -19,
FILE_REPLACE = -20,
FILE_AUTOFLUSH = -21,
-#ifdef OSSP /* BUGFIX */
+#ifdef OSSP_HACK /* BUGFIX */
FILE_ISNATIVE = -22
#else
FILE_ISNATIVE = -22,
char *bytes;
JSString *str;
jsint tiny;
-#ifdef OSSP
+#ifdef OSSP_HACK
struct stat info;
#else
PRFileInfo info;
#endif
JSBool flag;
-#ifdef OSSP
+#ifdef OSSP_HACK
struct tm *tm;
time_t t;
#else
case FILE_CREATED:
SECURITY_CHECK(cx, NULL, "creationTime", file);
JSFILE_CHECK_NATIVE("creationTime");
-#ifdef OSSP
+#ifdef OSSP_HACK
if (file->isOpen
? fstat(fileno(file->handle), &info) != 0
: stat(file->path, &info) != 0) {
case FILE_MODIFIED:
SECURITY_CHECK(cx, NULL, "lastModified", file);
JSFILE_CHECK_NATIVE("lastModified");
-#ifdef OSSP
+#ifdef OSSP_HACK
if (file->isOpen
? fstat(fileno(file->handle), &info) != 0
: stat(file->path, &info) != 0) {
JSFILE_CHECK_NATIVE("length");
if (js_isDirectory(cx, file)) { /* XXX debug me */
-#ifdef OSSP
+#ifdef OSSP_HACK
DIR *dir;
struct dirent *entry;
#else
#endif
jsint count = 0;
-#ifdef OSSP
+#ifdef OSSP_HACK
if(!(dir = opendir(file->path))){
#else
if(!(dir = PR_OpenDir(file->path))){
goto out;
}
-#ifdef OSSP
+#ifdef OSSP_HACK
while ((entry = readdir(dir))) {
if ( strcmp(entry->d_name, ".") == 0
|| strcmp(entry->d_name, "..") == 0)
count++;
}
-#ifdef OSSP
+#ifdef OSSP_HACK
if(closedir(dir) != 0){
#else
if(!PR_CloseDir(dir)){
}
if (file->isOpen && js_isFile(cx, file)) {
-#ifdef OSSP
+#ifdef OSSP_HACK
int pos = fseek(file->handle, 0, SEEK_CUR);
#else
int pos = PR_Seek(file->handle, 0, PR_SEEK_CUR);
/* this is some other property -- try to use the dir["file"] syntax */
if (js_isDirectory(cx, file)) {
-#ifdef OSSP
+#ifdef OSSP_HACK
DIR *dir = NULL;
struct dirent *entry = NULL;
#else
prop_name = JS_GetStringBytes(str);
/* no native files past this point */
-#ifdef OSSP
+#ifdef OSSP_HACK
dir = opendir(file->path);
#else
dir = PR_OpenDir(file->path);
return JS_FALSE;
}
-#ifdef OSSP
+#ifdef OSSP_HACK
while ((entry = readdir(dir)) != NULL) {
if ( strcmp(entry->d_name, ".") == 0
|| strcmp(entry->d_name, "..") == 0)
bytes = js_combinePath(cx, file->path, prop_name);
*vp = OBJECT_TO_JSVAL(js_NewFileObject(cx, bytes));
JS_free(cx, bytes);
-#ifdef OSSP /* BUGFIX */
+#ifdef OSSP_HACK /* BUGFIX */
closedir(dir);
#else
PR_CloseDir(dir);
return JS_TRUE;
}
}
-#ifdef OSSP /* BUGFIX */
+#ifdef OSSP_HACK /* BUGFIX */
closedir(dir);
#else
PR_CloseDir(dir);
goto out;
}
-#ifdef OSSP
+#ifdef OSSP_HACK
pos = fseek(file->handle, offset, SEEK_SET);
#else
pos = PR_Seek(file->handle, offset, PR_SEEK_SET);
JSPROP_ENUMERATE | JSPROP_READONLY );
return file;
}
-#endif /* JS_HAS_FILE_OBJECT */