示例#1
0
 /******************************************************************************
    TrackDel:
    Delete current character in the tracking mode. The function returns TRUE
    if track-deletion is successful.  
 ******************************************************************************/
BOOL TrackDel(PTERWND w, long line, int col, BOOL forward)
{
    int font;
    LPWORD fmt;
    long SaveLine=CurLine;

    if (!TrackChanges) return false;

    font=GetCurCfmt(w,line,col);

    if (True(TerFont[font].style&PICT)) return false;   // 20061208: delete of picture not yet supported for track-changes

    if (TerFont[font].InsRev==TrackRev) return false;  // this character was inserted by the current reviewer, so it let be deleted normally

    if (True(TerFont[font].DelRev)) goto END;  // already track deleted

    SaveUndo(w,line,col,line,col,'F');  // save undo of current formatting

    fmt=OpenCfmt(w,line);

    fmt[col]=SetTrackingFont(w,fmt[col],TRACK_DEL);
     
    CloseCfmt(w,line);

    END:

    if (forward) NextTextPos(w,&CurLine,&CurCol);

    return true;
} 
示例#2
0
void DualshockPad::receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) {
  if (message != 1 || length != 49 || tp != HIDReportType::Input)
    return;
  DualshockPadState state = *reinterpret_cast<const DualshockPadState*>(data);

  for (int i = 0; i < 3; i++)
    state.m_accelerometer[i] = bswap16(state.m_accelerometer[i]);

  state.m_gyrometerZ = bswap16(state.m_gyrometerZ);
  const double zeroG = 511.5; // 1.65/3.3*1023 (1,65V);
  float accXval = -((double)state.m_accelerometer[0] - zeroG);
  float accYval = -((double)state.m_accelerometer[1] - zeroG);
  float accZval = -((double)state.m_accelerometer[2] - zeroG);
  state.accPitch = (atan2(accYval, accZval) + M_PIF) * RAD_TO_DEG;
  state.accYaw = (atan2(accXval, accZval) + M_PIF) * RAD_TO_DEG;
  state.gyroZ = (state.m_gyrometerZ / 1023.f);

  {
    std::lock_guard<std::mutex> lk(m_callbackLock);
    if (m_callback)
      m_callback->controllerUpdate(*this, state);
  }

  if (m_rumbleRequest != m_rumbleState) {
    if (True(m_rumbleRequest & EDualshockMotor::Left)) {
      m_report.rumble.leftDuration = m_rumbleDuration[0];
      m_report.rumble.leftForce = m_rumbleIntensity[0];
    } else {
      m_report.rumble.leftDuration = 0;
      m_report.rumble.leftForce = 0;
    }

    if (True(m_rumbleRequest & EDualshockMotor::Right)) {
      m_report.rumble.rightDuration = m_rumbleDuration[1];
      m_report.rumble.rightOn = m_rumbleIntensity[1] > 0;
    } else {
      m_report.rumble.rightDuration = 0;
      m_report.rumble.rightOn = false;
    }
    sendHIDReport(m_report.buf, sizeof(m_report), HIDReportType::Output, 0x01);
    m_rumbleState = m_rumbleRequest;
  } else {
    if (state.m_reserved5[8] & 0x80)
      m_rumbleRequest &= ~EDualshockMotor::Right;
    if (state.m_reserved5[7] & 0x01)
      m_rumbleRequest &= ~EDualshockMotor::Left;
    m_rumbleState = m_rumbleRequest;
  }
}
示例#3
0
void PrecisionModel::IsFloating(const FunctionCallbackInfo<Value>& args) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);

    PrecisionModel *model = ObjectWrap::Unwrap<PrecisionModel>(args.This());
    args.GetReturnValue().Set(model->_model->isFloating() ? True(isolate) : False(isolate));
}
示例#4
0
Handle<Value> Geometry::Relate(const Arguments& args)
{
    HandleScope scope;
    Geometry *geom = ObjectWrap::Unwrap<Geometry>(args.This());
    if (args.Length() < 1)
        return ThrowException(String::New("requires at least one argument"));
    Geometry *other = ObjectWrap::Unwrap<Geometry>(args[0]->ToObject());
    if (args.Length() == 1) {
        // Gets a relation pattern (string) from the two geometries
        char *pattern = GEOSRelate(geom->geos_geom_, other->geos_geom_);
        if (pattern == NULL)
            return ThrowException(String::New("couldn't get relate pattern"));
        Local<Value> pattern_obj = String::New(pattern);
        GEOSFree(pattern);
        return scope.Close(pattern_obj);
    } else if (args.Length() == 2) {
        // Returns a boolean if the two geometries relate according to the pattern argument
        String::Utf8Value pattern(args[1]->ToString());
        unsigned char r = GEOSRelatePattern(geom->geos_geom_, other->geos_geom_, *pattern);
        if (r == 2) {
            return ThrowException(String::New("relate by pattern failed"));
        }
        return r ? True() : False();
    }
    return ThrowException(String::New("invalid number of arguments"));
}
示例#5
0
void destroy(Hierarchy d) {
  ParticlesTemp all;
  //core::Hierarchy h=d;

  core::gather(d, True(), std::back_inserter(all));
  for (unsigned int i=0; i< all.size(); ++i) {
    if (Bonded::particle_is_instance(all[i])) {
     Bonded b(all[i]);
      while (b.get_number_of_bonds() > 0) {
        destroy_bond(b.get_bond(b.get_number_of_bonds()-1));
      }
    }
    Hierarchy hc(all[i]);
    while (hc.get_number_of_children() > 0) {
      hc.remove_child(hc.get_child(hc.get_number_of_children()-1));
    }
  }

  // If this Hierarchy has a parent, remove the relationship
  Hierarchy parent = d.get_parent();
  if (parent) {
    parent.remove_child(d);
  }

  for (unsigned int i=0; i< all.size(); ++i) {
    all[i]->get_model()->remove_particle(all[i]);
  }
}
示例#6
0
/**
 * When you have an comparison operation, we will handle it differently
 * if it is all numbers. 
 *
 * @version
 * - JR Lewis      2012.03.07
 *   - Initial version.
 */
Element ComparisonBuiltinsImplementation::Interpret_( Environment& 
                                                    , std::vector<Element> const& parms
                                                    , Element const&)
{
    bool result = true;
    bool all_numbers = true;
    
    size_t const PARMS_SIZE = parms.size();
    for(size_t i=0; i<PARMS_SIZE && all_numbers; ++i)
    {
        Element const& element = parms[i];
        all_numbers = (all_numbers && (element.Type() == Types::NUMBER));
    }

    if (all_numbers)
    {
        result = InterpretAllNumbers_(parms); 
    }
    else
    {
        for(size_t i=1; result &&  i<PARMS_SIZE; ++i)
        {
            result = InterpretNext_(parms[i - 1], parms[i] );
        }
    }
    if (result)
    {
        return True();
    } 
    else
    {
        return False();
    }
}
示例#7
0
static word
do_write2(term_t stream, term_t term, int flags)
{ GET_LD
  IOSTREAM *s;

  if ( getTextOutputStream(stream, &s) )
  { write_options options;
    int rc;

    memset(&options, 0, sizeof(options));
    options.flags     = flags;
    options.out	      = s;
    options.module    = MODULE_user;
    if ( options.module
#ifndef __YAP_PROLOG__
	 && True(options.module, M_CHARESCAPE)
#endif
	 )
      options.flags |= PL_WRT_CHARESCAPES;
    if ( truePrologFlag(PLFLAG_BACKQUOTED_STRING) )
      options.flags |= PL_WRT_BACKQUOTED_STRING;

    PutOpenToken(EOF, s);		/* reset this */
    rc = writeTopTerm(term, 1200, &options);
    if ( rc && (flags&PL_WRT_NEWLINE) )
      rc = Putc('\n', s);

    return streamStatus(s) && rc;
  }

  return FALSE;
}
示例#8
0
/**
 * Cast the element to a True.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
True CastToTrue(Element const& element, bool& success)
{
    std::shared_ptr<Element_> element_ = element.ElementHandle();
    std::shared_ptr<True_> f = std::dynamic_pointer_cast<True_>(element_);
    success = (0 != f.get());
    return True();
}
Element ExpectEqBuiltinImplementation::Interpret_( Environment& /*environment*/
                                                 , std::vector<Element> const& parms
                                                 , Element const& /*addParms*/ )
{
    typedef std::vector<Element>::const_iterator Iterator;
    Iterator iter = parms.begin();
    Iterator end = parms.end();

    bool success = true;

    String title = CastToString(*iter, success);
    ++iter;

    std::string first = iter->ToString();

    for(; iter != end; ++iter)
    {
        success = success && (first == iter->ToString());
    }

    if (success)
    {
        Tests::Instance().Success(title.Value());
        return True();        
    }
    else
    {
        std::stringstream ss;
        ss << title.Value() << ": " << parms[1].ToString() << " != " << parms[2].ToString();
        Tests::Instance().Failure(ss.str());
        return False(); 
    }
}
示例#10
0
Handle<Value> Geometry::IsWithinDistance(const Arguments& args) {
    HandleScope scope;
    Geometry* geom = ObjectWrap::Unwrap<Geometry>(args.This());
    Geometry* geom2 = ObjectWrap::Unwrap<Geometry>(args[0]->ToObject());
    double distance = args[0]->NumberValue();
    return geom->_geom->isWithinDistance(geom2->_geom, distance) ? True() : False();
}
示例#11
0
文件: v8base.cpp 项目: pgmsoul/GitLib
	//*,{
	//	"type":"function",
	//	"name":"setConfig(callback,[filename])",
	//	"text":"读取或设置配置文件,配置文件是一个 Json 格式的文本文件,可以是 utf-8 获取 ansi 编码。",
	//	"param":[
	//		{
	//			"type":"function",
	//			"name":"callback(cfg)",
	//			"text":"setConfig 函数如果成功,会触发这个回调函数,cfg 是一个对象,它的属性就是配置内容,对这个对象的任何更改最后都会作为 Json 格式保存到配置文件。"
	//		},
	//		{
	//			"type":"string",
	//			"name":"[filename]",
	//			"text":"配置文件名,缺省是和脚本同路径同名的一个后缀为“.json”的文本文件,如果指定了文件名,则读取和保存对应的文件。"
	//		}
	//	],
	//	"return":{
	//		"type":"boolean",
	//		"text":"如果成功打开了配置文件,函数返回 true,否则返回 undefined。"
	//	}
	//}//*
	Handle<Value> setConfig(const Arguments& args){
		HandleScope stack;
		while(true){
			if(args.Length()<1) break;
			if(!args[0]->IsFunction()) break;
			cs::String file;
			if(args.Length()>1)
				GetString(args[1],file);
			cs::Config cfg(file);
			cs::Json* json = cfg.Lock();
			if(!json) break;

			json->ToString(file,false);
			Handle<Object> glb = GetGlobal();
			Handle<Object> JSON = glb->Get(NEW_STR(JSON))->ToObject();
			Handle<Function> parse = Handle<Function>::Cast(JSON->Get(NEW_STR(parse)));
			Handle<Function> stringify = Handle<Function>::Cast(JSON->Get(NEW_STR(stringify)));
			Handle<Function> callback = Handle<Function>::Cast(args[0]);
			Handle<Value> argv[3];
			argv[0] = NEW_WSTR(file.Handle());
			Handle<Value> v = parse->Call(JSON,1,argv);
			if(v.IsEmpty()||!v->IsObject()) v = Object::New();
			argv[0] = v;
			CallFunc(glb,callback,1,argv);
			v = stringify->Call(JSON,1,argv);
			GetString(v,file);
			json->Parse(file);
			return True();
		}
		return Undefined();
	}
示例#12
0
文件: cast.cpp 项目: signatal/strine
/**
 * Cast the element to a True.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
True CastToTrue(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    True_* f = dynamic_cast<True_*>(element_);
    success = (0 != f);
    return True();
}
示例#13
0
文件: fs.cpp 项目: kyusof/SilkJS
/**
 * writeFile(path, data, size [,mode=0644])
 * @param args
 * @return
 */
static JSVAL fs_writefile(JSARGS args) {
    HandleScope scope;
    String::Utf8Value path(args[0]->ToString());
    String::Utf8Value data(args[1]->ToString());
    ssize_t size;
    if (args.Length() > 2) {
        size = args[2]->IntegerValue();
    } else {
        size = strlen(*data);
    }
    mode_t mode = 0644;
    if (args.Length() > 3) {
        mode = args[3]->IntegerValue();
    }
    int fd = open(*path, O_WRONLY | O_CREAT | O_TRUNC, mode);
    if (fd == -1) {
        return scope.Close(False());
    }
    if (write(fd, *data, size) != size) {
        close(fd);
        return scope.Close(False());
    }
    close(fd);
    return scope.Close(True());
}
示例#14
0
文件: fs.cpp 项目: kyusof/SilkJS
static JSVAL fs_rmdir(JSARGS args) {
    HandleScope scope;
    String::Utf8Value path(args[0]->ToString());
    if (rmdir(*path) == -1) {
        return scope.Close(False());
    }
    return scope.Close(True());
}
示例#15
0
/**
 * @function ssh.writeFile
 * 
 * ### Synopsis
 * 
 * var status = ssh.writeFile(handle, srcPath, dstPath);
 * var status = ssh.writeFile(handle, srcPath, dstPath, mode);
 * 
 * Write file to remote server via SCP.
 * 
 * @param {object} handle - opaque handle to already open SSH2 connection.
 * @param {string} srcPath - path to file in local file system to send.
 * @param {string} dstPath - path to file in remote file system to create.
 * @param {int} mode - desired resulting file permissions of file on remote end.
 * @return {boolean} success - true if the transfer succeeded, string error message if transfer failed.
 * 
 * ### Note
 * If mode is not provided, the file mode of the file being sent will be used.
 */
static JSVAL ssh2_scp_send(JSARGS args) {
	HandleScope scope;
    SSH2 *ssh2 = HANDLE(args[0]);
	String::Utf8Value srcPath(args[1]);
	String::Utf8Value dstPath(args[2]);
    int mode;
    struct stat fileinfo;
    if (stat(*srcPath, &fileinfo) != 0) {
        return scope.Close(String::New(strerror(errno)));
    }
    if (args.Length() > 3) {
        mode = args[3]->IntegerValue();
    }
    else {
        mode = fileinfo.st_mode;
    }
    mode &= 0777;
    int fd = open(*srcPath, O_RDONLY);
    if (fd < 0) {
        return scope.Close(String::New(strerror(errno)));
    }
#ifdef libssh2_scp_send64
    LIBSSH2_CHANNEL *channel = libssh2_scp_send64(ssh2->mSession, *dstPath, mode, fileinfo.st_size, 0, 0);
#else
    LIBSSH2_CHANNEL *channel = libssh2_scp_send(ssh2->mSession, *dstPath, mode, fileinfo.st_size);
#endif
    if (!channel) {
        char *errmsg;
        int errlen;
        libssh2_session_last_error(ssh2->mSession, &errmsg, &errlen, 0);
        return scope.Close(String::New(errmsg, errlen));
    }
    
    char mem[1024];
    ssize_t toWrite = fileinfo.st_size;
    while (toWrite > 0) {
        ssize_t nRead = read(fd, mem, 1024);
        if (nRead < 0) {
            int eNum = errno;
            libssh2_channel_free(channel);
            close(fd);
            return scope.Close(String::New(strerror(eNum)));
        }
        int rc = libssh2_channel_write(channel, mem, nRead);
        if (rc < 0) {
            char *errmsg;
            int errlen;
            libssh2_session_last_error(ssh2->mSession, &errmsg, &errlen, 0);
            libssh2_channel_free(channel);
            close(fd);
            return scope.Close(String::New(errmsg));
        }
        toWrite -= nRead;
    }
    close(fd);
    libssh2_channel_free(channel);
    return scope.Close(True());
}
示例#16
0
static JSVAL sem_Init(JSARGS args) {
	HandleScope scope;
	int ret;
	if ((ret = sem_init(&mutex, 1, 1)) < 0) {
		perror("sem_init");
		return False();
	}
	return True();
}
示例#17
0
static JSVAL popen_puts (JSARGS args) {
    HandleScope scope;
    FILE *fp = (FILE *) JSEXTERN(args[0]);
    String::Utf8Value s(args[1]->ToString());
    if (fputs(*s, fp) == EOF) {
        return scope.Close(False());
    }
    return scope.Close(True());
}
示例#18
0
/**
 * @function SFTP.unlink
 * 
 * ### Synopsis
 * 
 * var success = SFTP.unlink(handle, path);
 * 
 * Remove a file on the remote host.
 * 
 * @param {object} handle - opaque handle to existing SFTP connection (already connected).
 * @param {string} path - path to file on remote server to remove.
 * @returns {boolean} success - true if directory was removed.
 */
JSVAL sftp_unlink (JSARGS args) {
    HandleScope scope;
    SFTP *handle = HANDLE(args[0]);
    String::Utf8Value path(args[1]);
    if (libssh2_sftp_unlink(handle->sftp_session, *path)) {
        return scope.Close(String::New("Could not remove file"));
    }
    return scope.Close(True());
}
示例#19
0
	//by default memory buffers have direct access
    Handle<Value> MemoryBuffer(const Arguments& args) {
	  HandleScope scope;

	  if (args.Length() < 2) {
		return ThrowException(
			String::New("MemoryBuffer constructor must have two parameters (address and size)."));
	  }

	  TryCatch try_catch;
	  uint32_t address = NumberToUint32(args[0], &try_catch);
	  uint32_t length = convertToUint(args[1], &try_catch);
	  uint8_t* data;
	  bool is_external = false;

	  if (try_catch.HasCaught()) return try_catch.Exception();

	  static const int32_t kMaxSize = 0x7fffffff;
	  // Make sure the total size fits into a (signed) int.
	  if (length < 0 || length > kMaxSize) {
		return ThrowException(String::New("ArrayBuffer exceeds maximum size (2G)"));
	  }

	  //check if we should snapshot the value
	  if (args.Length() > 2 && args[2]->IsTrue()) {
		  data = new uint8_t[length];
		  if (data == NULL) {
			return ThrowException(String::New("Memory allocation failed."));
		  }
		  V8::AdjustAmountOfExternalAllocatedMemory(length);

		  PIN_SafeCopy(data, reinterpret_cast<uint8_t *>(address), length);
	  } else {
		  data = reinterpret_cast<uint8_t *>(address);
		  is_external = true;
	  }

	  Handle<Value> buffer = CreateExternalArrayBuffer(length, data);
	  buffer->ToObject()->Set(String::New("snapshot"), (is_external ? False() : True()), ReadOnly);

	  if (is_external)
		buffer->ToObject()->Set(String::New("externalBuffer"), True(), ReadOnly);

	  return scope.Close(buffer);
    }
示例#20
0
/**
 * @function ssh2.exec
 * 
 * ### Synopsis
 * 
 * var success = ssh2.exec(conn, command);
 * 
 * Execute command at remote host.
 * 
 * @param {object} conn - connection returned from ssh.connect()
 * @param {string} command - command line to execute on remote host
 * @return {boolean} success - true if the command was successfuly executed.
 */
static JSVAL ssh2_exec(JSARGS args) {
	HandleScope scope;
	Local<External>wrap = Local<External>::Cast(args[0]);
	SSH2 *ssh2 = (SSH2 *)wrap->Value();
	String::Utf8Value command(args[1]);
	if (!ssh2->RunCommand(*command)) {
		return scope.Close(False());
	}
	return scope.Close(True());
}
示例#21
0
int
ShellCmdArgToggle::operator()(const char * & arg, CmdLine & cmd)
{
   CmdArgToggle  bool_arg(*this);
   int  badval = bool_arg(arg, cmd);
   if (! badval) {
      set((bool_arg) ? True() : False());
   }
   return  badval;
}
示例#22
0
/****************************************************************************
    DrgAbsToRowCol:
    Dragon wrapper for AbsToRowCol
****************************************************************************/
void DrgAbsToRowCol(PTERWND w,long abs,long far *row,int far *col)
{
    bool CountPCharAsCrLf=True(TerFlags4&TFLAG4_COUNT_PCHAR_AS_CRLF);

    TerFlags4|=TFLAG4_COUNT_PCHAR_AS_CRLF;    // count pchar as cr/lf

    AbsToRowCol(w,abs,row,col);

    if (!CountPCharAsCrLf) ResetLongFlag(TerFlags4,TFLAG4_COUNT_PCHAR_AS_CRLF);   // restore status
}       
示例#23
0
void ScriptLineFor::eval()
{
    m_init->eval();
    Bool True(true);
    while(True == m_end_condition->eval())
    {
        m_block->eval();
        m_next->eval();
    }
}
示例#24
0
文件: fs.cpp 项目: kyusof/SilkJS
static JSVAL fs_exists(JSARGS args) {
    HandleScope scope;
    String::Utf8Value path(args[0]->ToString());

    struct stat buf;
    if (stat(*path, &buf)) {
        return scope.Close(False());
    }
    return scope.Close(True());
}
示例#25
0
 Handle<Value> COEquals(const Arguments& args)
 {
    if(!IsComponent(args[0]))
    {
       return False();
    }
    dtEntity::Component* component = UnwrapComponent(args.This());
    dtEntity::Component* other = UnwrapComponent(args[0]);
    return (other == component) ? True() : False();
 }
示例#26
0
/******************************************************************************
    DrgRowColToAbs:
    Dragon wrapper for RowColToAbs
******************************************************************************/
long DrgRowColToAbs(PTERWND w,long row,int col)
{
    long result;
    bool CountPCharAsCrLf=True(TerFlags4&TFLAG4_COUNT_PCHAR_AS_CRLF);

    TerFlags4|=TFLAG4_COUNT_PCHAR_AS_CRLF;    // count pchar as cr/lf

    result=RowColToAbs(w,row,col);
    if (!CountPCharAsCrLf) ResetLongFlag(TerFlags4,TFLAG4_COUNT_PCHAR_AS_CRLF);   // restore status

    return result;
} 
示例#27
0
文件: fs.cpp 项目: kyusof/SilkJS
static JSVAL fs_mkdir(JSARGS args) {
    HandleScope scope;
    String::Utf8Value path(args[0]->ToString());
    mode_t mode = 0700;
    if (args.Length() > 1) {
        mode = args[1]->IntegerValue();
    }
    if (mkdir(*path, mode) == -1) {
        return scope.Close(False());
    }
    return scope.Close(True());
}
示例#28
0
/**
 * @function SFTP.mkdir
 * 
 * ### Synopsis
 * 
 * var success = SFTP.mkdir(handle, path, mode);
 * 
 * Make a directory on the remote host.
 * 
 * @param {object} handle - opaque handle to existing SFTP connection (already connected).
 * @param {string} path - path on remote server to create.
 * @returns {boolean} success - true if directory was created.
 */
JSVAL sftp_mkdir (JSARGS args) {
    HandleScope scope;
    SFTP *handle = HANDLE(args[0]);
    String::Utf8Value path(args[1]);
    int mode = 0755;
    if (args.Length() > 2) {
        mode = args[2]->IntegerValue();
    }
    if (libssh2_sftp_mkdir(handle->sftp_session, *path, mode)) {
        return scope.Close(String::New("Could not create directory"));
    }
    return scope.Close(True());
}
Handle<Value> TiAppPropertiesObject::_hasProperty(void* /*userContext*/, TiObject* /*caller*/, const Arguments& args)
{
    if (args.Length() < 1)
    {
        return ThrowException(String::New(Ti::Msg::Missing_argument));
    }
    if (!args[0]->IsString() && !args[0]->IsStringObject())
    {
        return ThrowException(String::New((string(Ti::Msg::Invalid_argument_expected_) + "String").c_str()));
    }

    QString key = QString::fromUtf8(*String::Utf8Value(args[0]));
    return settings.contains(key) ? True() : False();
}
示例#30
0
文件: fs.cpp 项目: kyusof/SilkJS
static JSVAL fs_cmp(JSARGS args) {
    HandleScope scope;
    String::Utf8Value path1(args[0]->ToString());
    String::Utf8Value path2(args[1]->ToString());
    int fd;
    long size1, size2;
    char buf[1024];

    fd = open(*path1, O_RDONLY);
    if (fd < 0) {
        sprintf(buf, "Could not open %s", *path1);
        return scope.Close(String::New(buf));
    }
    size1 = lseek(fd, 0, 2);
    lseek(fd, 0, 0);
    unsigned char buf1[size1];
    if (read(fd, buf1, size1) != size1) {
        close(fd);
        sprintf(buf, "Error reading %s", *path1);
        return scope.Close(String::New(buf));
    }
    close(fd);

    fd = open(*path2, O_RDONLY);
    if (fd < 0) {
        sprintf(buf, "Could not open %s", *path2);
        return scope.Close(String::New(buf));
    }
    size2 = lseek(fd, 0, 2);
    lseek(fd, 0, 0);
    unsigned char buf2[size2];
    if (read(fd, buf2, size2) != size2) {
        close(fd);
        sprintf(buf, "Error reading %s", *path2);
        return scope.Close(String::New(buf));
    }
    close(fd);

    if (size1 != size2) {
        return scope.Close(String::New("Files differ in size"));
    }

    for (long n=0; n<size1; n++) {
        if (buf1[n] != buf2[n]) {
            sprintf(buf, "Files differ at offset %ld", n);
            return scope.Close(String::New(buf));
        }
    }
    return scope.Close(True());
}