Ejemplo n.º 1
0
Dev*
opendev(char *fn)
{
	Dev *d;
	int l;

	if(access("/dev/usb", AEXIST) < 0 && bind("#u", "/dev", MBEFORE) < 0)
		return nil;
	d = emallocz(sizeof(Dev), 1);
	incref(d);

	l = strlen(fn);
	d->dfd = -1;
	/*
	 * +30 to allocate extra size to concat "/<epfilename>"
	 * we should probably remove that feature from the manual
	 * and from the code after checking out that nobody relies on
	 * that.
	 */
	d->dir = emallocz(l + 30, 0);
	strcpy(d->dir, fn);
	strcpy(d->dir+l, "/ctl");
	d->cfd = open(d->dir, ORDWR|OCEXEC);
	d->dir[l] = 0;
	d->id = nameid(fn);
	if(d->cfd < 0){
		werrstr("can't open endpoint %s: %r", d->dir);
		free(d->dir);
		free(d);
		return nil;
	}
	dprint(2, "%s: opendev %#p %s\n", argv0, d, fn);
	return d;
}
Ejemplo n.º 2
0
JSDProperty*
jsd_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* nameStr)
{
    JSContext* cx = jsdc->dumbContext;
    JSDProperty* jsdprop;
    JSDProperty* iter = NULL;
    JS::RootedObject obj(cx);
    JS::RootedString name(cx, nameStr);
    unsigned  attrs = 0;
    JSBool found;
    JSPropertyDesc pd;
    const jschar * nameChars;
    size_t nameLen;
    JS::RootedValue val(cx), nameval(cx);
    JS::RootedId nameid(cx);
    JSCompartment* oldCompartment = NULL;

    if(!jsd_IsValueObject(jsdc, jsdval))
        return NULL;

    /* If we already have the prop, then return it */
    while(NULL != (jsdprop = jsd_IterateProperties(jsdc, jsdval, &iter)))
    {
        JSString* propName = jsd_GetValueString(jsdc, jsdprop->name);
        if(propName) {
            int result;
            if (JS_CompareStrings(cx, propName, name, &result) && !result)
                return jsdprop;
        }
        JSD_DropProperty(jsdc, jsdprop);
    }
    /* Not found in property list, look it up explicitly */

    if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
        return NULL;

    if (!(nameChars = JS_GetStringCharsZAndLength(cx, name, &nameLen)))
        return NULL;

    JS_BeginRequest(cx);
    oldCompartment = JS_EnterCompartment(cx, obj);

    JS_GetUCPropertyAttributes(cx, obj, nameChars, nameLen, &attrs, &found);
    if (!found)
    {
        JS_LeaveCompartment(cx, oldCompartment);
        JS_EndRequest(cx);
        return NULL;
    }

    JS_ClearPendingException(cx);

    if(!JS_GetUCProperty(cx, obj, nameChars, nameLen, val.address()))
    {
        if (JS_IsExceptionPending(cx))
        {
            if (!JS_GetPendingException(cx, &pd.value))
            {
                JS_LeaveCompartment(cx, oldCompartment);
                JS_EndRequest(cx);
                return NULL;
            }
            pd.flags = JSPD_EXCEPTION;
        }
        else
        {
            pd.flags = JSPD_ERROR;
            pd.value = JSVAL_VOID;
        }
    }
    else
    {
        pd.value = val;
    }

    JS_LeaveCompartment(cx, oldCompartment);
    JS_EndRequest(cx);

    nameval = STRING_TO_JSVAL(name);
    if (!JS_ValueToId(cx, nameval, nameid.address()) ||
        !JS_IdToValue(cx, nameid, &pd.id)) {
        return NULL;
    }

    pd.spare = 0;
    pd.alias = JSVAL_NULL;
    pd.flags |= (attrs & JSPROP_ENUMERATE) ? JSPD_ENUMERATE : 0
        | (attrs & JSPROP_READONLY)  ? JSPD_READONLY  : 0
        | (attrs & JSPROP_PERMANENT) ? JSPD_PERMANENT : 0;

    return _newProperty(jsdc, &pd, JSDPD_HINTED);
}