Exemplo n.º 1
0
struct sint sadd(const struct sint *a, const struct sint *b) {
  struct sint r, acp = *a, bcp = *b;
  strim(&acp);
  strim(&bcp);
  for (int i = 0; i < MAX_DIGITS; i++)
    r.digits[i] = '0';
  r.digits[MAX_DIGITS] = '\0';
  
  int lena = strlen(acp.digits);
  int lenb = strlen(bcp.digits);
  int carry = 0;
  for (int i = 0; i < MAX_DIGITS; ++i) {
    int cur = 0;
    if (i < lena)
      cur += acp.digits[lena - 1 - i] - '0';
    if (i < lenb)
      cur += bcp.digits[lenb - 1 - i] - '0';
    cur += carry;
    carry = cur / 10;
    cur %= 10;
    r.digits[MAX_DIGITS - 1 - i] = '0' + cur;
  }
  
  strim(&r);
  return r;
}
Exemplo n.º 2
0
static int bcm47xx_get_invariants(struct ssb_bus *bus,
				  struct ssb_init_invariants *iv)
{
	char buf[20];
	int len, err;

	/* Fill boardinfo structure */
	memset(&iv->boardinfo, 0 , sizeof(struct ssb_boardinfo));

	len = bcm47xx_nvram_getenv("boardvendor", buf, sizeof(buf));
	if (len > 0) {
		err = kstrtou16(strim(buf), 0, &iv->boardinfo.vendor);
		if (err)
			pr_warn("Couldn't parse nvram board vendor entry with value \"%s\"\n",
				buf);
	}
	if (!iv->boardinfo.vendor)
		iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM;

	len = bcm47xx_nvram_getenv("boardtype", buf, sizeof(buf));
	if (len > 0) {
		err = kstrtou16(strim(buf), 0, &iv->boardinfo.type);
		if (err)
			pr_warn("Couldn't parse nvram board type entry with value \"%s\"\n",
				buf);
	}

	memset(&iv->sprom, 0, sizeof(struct ssb_sprom));
	bcm47xx_fill_sprom(&iv->sprom, NULL, false);

	if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
		iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);

	return 0;
}
Exemplo n.º 3
0
/*
 * read_file_line - read a line from a file
 *
 * Used to compose a filename from a printf format and to read a line from this
 * file. All leading and trailing whitespaces (including line endings) are
 * removed. The returned buffer must be freed with free(). This function is
 * supposed for reading variable like content into a buffer, so files > 1024
 * bytes are ignored.
 */
char *read_file_line(const char *fmt, ...)
{
	va_list args;
	char *filename;
	char *buf, *line = NULL;
	size_t size;
	int ret;
	struct stat s;

	va_start(args, fmt);
	filename = bvasprintf(fmt, args);
	va_end(args);

	ret = stat(filename, &s);
	if (ret)
		goto out;

	if (s.st_size > 1024)
		goto out;

	buf = read_file(filename, &size);
	if (!buf)
		goto out;

	line = strim(buf);

	line = xstrdup(line);
	free(buf);
out:
	free(filename);
	return line;
}
Exemplo n.º 4
0
/*
    Test if the version is acceptable based on the supplied critera.
    The acceptable formats for criteria are:

    VER                             Allows prereleases
    1.2.[*xX]                       Wild card version portion. (allows prereleases).
    ~VER                            Compatible with VER at the least significant level.
                                    ~1.2.3 == (>=1.2.3 <1.3.0) Compatible at the patch level
                                    ~1.2 == 1.2.x   Compatible at the minor level
                                    ~1 == 1.x   Compatible at the major level
    ^VER                            Compatible with VER at the most significant level.
                                    ^0.2.3 == 0.2.3 <= VER < 0.3.0
                                    ^1.2.3 == 1.2.3 <= VER < 2.0.0
    [>, >=, <, <=, ==, !=]VER       Create range relative to given version
    EXPR1 - EXPR2                   <=EXPR1 <=EXPR2
    EXPR1 || EXPR2 ...              EXPR1 OR EXPR2
    EXPR1 && EXPR2 ...              EXPR1 AND EXPR2
    EXPR1 EXPR2 ...                 EXPR1 AND EXPR2

    Pre-release versions will only match if the criteria contains a "-.*" prerelease suffix
*/
PUBLIC bool mprIsVersionObjAcceptable(MprVersion *vp, cchar *criteria)
{
    char        *expr, *exprTok, *range, *rangeTok, *low, *high;
    bool        allMatched;

    if (!vp->ok) {
        return 0;
    }
    if (!criteria || *criteria == '\0') {
        return 1;
    }
    criteria = cleanVersion(criteria);
    for (range = (char*) criteria; stok(range, "||", &rangeTok) != 0; range = rangeTok) {
        range = strim(range, " \t", 0);
        allMatched = 1;
        for (expr = (char*) range; sptok(expr, "&&", &exprTok) != 0; expr = exprTok) {
            if (scontains(expr, " - ")) {
                low = sptok(expr, " - ", &high);
                return inRange(vp, sjoin(">=", low, NULL)) && inRange(vp, sjoin("<=", high, NULL));
            }
            if (!inRange(vp, expr)) {
                allMatched = 0;
                break;
            }
        }
        if (allMatched) {
            return 1;
        }
    }
    return 0;
}
static ssize_t table_write(struct file *file,
	const char __user *userbuf, size_t count, loff_t *ppos)
{
	char buf[80];
	int table_idx;
	unsigned int cpu_freq;
	int core_cap_level;

	if (sizeof(buf) <= count)
		return -EINVAL;

	if (copy_from_user(buf, userbuf, count))
		return -EFAULT;

	/* terminate buffer and trim - white spaces may be appended
	 *  at the end when invoked from shell command line */
	buf[count] = '\0';
	strim(buf);

	if (sscanf(buf, "[%d] = %u %d",
		   &table_idx, &cpu_freq, &core_cap_level) != 3)
		return -1;

	if ((table_idx < 0) || (table_idx >= ARRAY_SIZE(throttle_table)))
		return -EINVAL;

	/* round new settings before updating table */
	throttle_table[table_idx].cpu_freq = clip_to_table(cpu_freq);
	throttle_table[table_idx].core_cap_level = (core_cap_level / 50) * 50;

	return count;
}
Exemplo n.º 6
0
/*
    Check if the layout has changed. Returns false if the layout does not exist.
 */
static bool layoutIsStale(EspRoute *eroute, cchar *source, cchar *module)
{
    char    *data, *lpath, *quote;
    cchar   *layout, *layoutsDir;
    ssize   len;
    bool    stale;
    int     recompile;

    stale = 0;
    layoutsDir = httpGetDir(eroute->route, "LAYOUTS");
    if ((data = mprReadPathContents(source, &len)) != 0) {
        if ((lpath = scontains(data, "@ layout \"")) != 0) {
            lpath = strim(&lpath[10], " ", MPR_TRIM_BOTH);
            if ((quote = schr(lpath, '"')) != 0) {
                *quote = '\0';
            }
            layout = (layoutsDir && *lpath) ? mprJoinPath(layoutsDir, lpath) : 0;
        } else {
            layout = (layoutsDir) ? mprJoinPath(layoutsDir, "default.esp") : 0;
        }
        if (layout) {
            stale = espModuleIsStale(layout, module, &recompile);
            if (stale) {
                mprLog("info esp", 4, "esp layout %s is newer than module %s", layout, module);
            }
        }
    }
    return stale;
}
Exemplo n.º 7
0
static ssize_t consumer_unregister_store(const char *s, size_t count)
{
	char name[SYSEDP_NAME_LEN];
	size_t n;
	struct sysedp_consumer *consumer;

	n = count > SYSEDP_NAME_LEN - 1 ? SYSEDP_NAME_LEN - 1 : count;
	strncpy(name, s, n);
	name[n] = 0;
	consumer = sysedp_get_consumer(strim(name));

	if (!consumer)
		return -EINVAL;

	if (!consumer->removable)
		return -EINVAL;


	sysedp_unregister_consumer(consumer);
	kfree(consumer->states);
	kfree(consumer->ocpeaks);
	kfree(consumer);

	return count;
}
Exemplo n.º 8
0
/* Special entry to just crash directly. Available without KPROBEs */
static ssize_t direct_entry(struct file *f, const char __user *user_buf,
		size_t count, loff_t *off)
{
	enum ctype type;
	char *buf;

	if (count >= PAGE_SIZE)
		return -EINVAL;
	if (count < 1)
		return -EINVAL;

	buf = (char *)__get_free_page(GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
	if (copy_from_user(buf, user_buf, count)) {
		free_page((unsigned long) buf);
		return -EFAULT;
	}
	/* NULL-terminate and remove enter */
	buf[count] = '\0';
	strim(buf);

	type = parse_cp_type(buf, count);
	free_page((unsigned long) buf);
	if (type == CT_NONE)
		return -EINVAL;

	pr_info("Performing direct entry %s\n", cp_type_to_str(type));
	lkdtm_do_action(type);
	*off += count;

	return count;
}
Exemplo n.º 9
0
static ssize_t do_register_entry(enum cname which, struct file *f,
		const char __user *user_buf, size_t count, loff_t *off)
{
	char *buf;
	int err;

	if (count >= PAGE_SIZE)
		return -EINVAL;

	buf = (char *)__get_free_page(GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
	if (copy_from_user(buf, user_buf, count)) {
		free_page((unsigned long) buf);
		return -EFAULT;
	}
	/* NULL-terminate and remove enter */
	buf[count] = '\0';
	strim(buf);

	cptype = parse_cp_type(buf, count);
	free_page((unsigned long) buf);

	if (cptype == CT_NONE)
		return -EINVAL;

	err = lkdtm_register_cpoint(which);
	if (err < 0)
		return err;

	*off += count;

	return count;
}
static ssize_t
set_otg_mode(struct device *dev, struct device_attribute *attr,
				const char *buf, size_t count)
{
	struct mv_otg *mvotg = dev_get_drvdata(dev);
	char *usage = "Usage: $echo host/client to switch otg mode";
	char buff[16], *b;

	BUG_ON(mvotg != the_transceiver);
	strncpy(buff, buf, sizeof(buff));
	b = strim(buff);
	pr_info("OTG state is %s\n", state_string[mvotg->otg.state]);
	if (!strcmp(b, "host")) {
		if (mvotg->otg.state == OTG_STATE_B_PERIPHERAL) {
			pr_err("Failed to swich mode, pls don't connect to PC!\n");
			return count;
		}
		otg_force_host_mode = 1;
	} else if (!strcmp(b, "client")) {
		otg_force_host_mode = 0;
	} else {
		pr_err("%s\n", usage);
		return count;
	}
	mv_otg_run_state_machine(mvotg, 0);

	return count;
}
static int diag224_idx2name(int index, char *name)
{
	memcpy(name, diag224_cpu_names + ((index + 1) * DIAG204_CPU_NAME_LEN),
	       DIAG204_CPU_NAME_LEN);
	name[DIAG204_CPU_NAME_LEN] = 0;
	strim(name);
	return 0;
}
Exemplo n.º 12
0
int AGITool_Init(AGI_TOOLS *tool)
{
	char buffer[1024], *field, *value;
	
	// open stdin
	tool->in = stdin;
	
	// open stdout
	tool->out = stdout;
	
	/*
    * Often contains any/all of the following:
    *   agi_network - value is yes if this is a fastagi
    *   agi_network_script - name of the script to execute
    *   agi_request - name of agi script
    *   agi_channel - current channel
    *   agi_language - current language
    *   agi_type - channel type (SIP, ZAP, IAX, ...)
    *   agi_uniqueid - unique id based on unix time
    *   agi_callerid - callerID string
    *   agi_dnid - dialed number id
    *   agi_rdnis - referring DNIS number
    *   agi_context - current context
    *   agi_extension - extension dialed
    *   agi_priority - current priority
    *   agi_enhanced - value is 1.0 if started as an EAGI script
    *   agi_accountcode - set by SetAccount in the dialplan
    */
	
	// read the request
	tool->agi_vars=tool->settings=NULL;
	
	if ( fgets(buffer,sizeof(buffer),stdin) ) {
		while(strcmp(buffer, "\n") != 0) {
			field=buffer;
			value=strchr(buffer,':');
			if (value) {
				value[0]=0;
				value+=2;

				strim(value);
				tool->agi_vars = AGITool_ListAddItem(tool->agi_vars, field,value);
			}
	
			if ( !fgets(buffer,sizeof(buffer),stdin) ) {
				// if failed, may have lost pipe, but sigpipe is blocked.
				break;
			}
		}
	}
	
	// These could be configured in an ini...
	tool->settings = AGITool_ListAddItem(tool->settings, "tmpdir","/tmp/");
	tool->settings = AGITool_ListAddItem(tool->settings, "festival_text2wave","text2wave");
	tool->settings = AGITool_ListAddItem(tool->settings, "cepstral_swift","swift");

	return 0;
}
Exemplo n.º 13
0
/**
 * hname_tail - find the last component of an hname
 * @name: hname to find the base profile name component of  (NOT NULL)
 *
 * Returns: the tail (base profile name) name component of an hname
 */
static const char *hname_tail(const char *hname)
{
	char *split;
	hname = strim((char *)hname);
	for (split = strstr(hname, "//"); split; split = strstr(hname, "//"))
		hname = split + 2;

	return hname;
}
Exemplo n.º 14
0
PUBLIC bool websProcessUploadData(Webs *wp)
{
    char    *line, *nextTok;
    ssize   len, nbytes;
    bool    canProceed;

    line = 0;
    canProceed = 1; 
    while (canProceed && !wp->finalized && wp->uploadState != UPLOAD_CONTENT_END) {
        if  (wp->uploadState == UPLOAD_BOUNDARY || wp->uploadState == UPLOAD_CONTENT_HEADER) {
            /*
                Parse the next input line
             */
            line = wp->input.servp;
            if ((nextTok = memchr(line, '\n', bufLen(&wp->input))) == 0) {
                /* Incomplete line */
                canProceed = 0;
                break;
            }
            *nextTok++ = '\0';
            nbytes = nextTok - line;
            websConsumeInput(wp, nbytes);
            strim(line, "\r", WEBS_TRIM_END);
            len = strlen(line);
            if (line[len - 1] == '\r') {
                line[len - 1] = '\0';
            }
        }
        switch (wp->uploadState) {
        case 0:
            initUpload(wp);
            break;

        case UPLOAD_BOUNDARY:
            processContentBoundary(wp, line);
            break;

        case UPLOAD_CONTENT_HEADER:
            processUploadHeader(wp, line);
            break;

        case UPLOAD_CONTENT_DATA:
            canProceed = processContentData(wp);
            if (bufLen(&wp->input) < wp->boundaryLen) {
                /*  Incomplete boundary - return to get more data */
                canProceed = 0;
            }
            break;

        case UPLOAD_CONTENT_END:
            break;
        }
    }
    bufCompact(&wp->input);
    return canProceed;
}
Exemplo n.º 15
0
int main(void) {
	char in = 0;
	int digit = 0;
	struct sint current;
	struct sint max;
	max.digits[0]=0;
	struct sint min;
	for (int i=0; i<51; i++){
		min.digits[i]='9';
	}
	struct sint acc;
	acc.digits[0]=0;
	
	while (scanf("%c", &in)!=EOF){
		if (in > '9' || in < '0'){
			current.digits[digit] = 0;
			acc = sadd(&current, &acc);
			if (scomp(&current, &max)==1) {
				max = current;
			}
			if (scomp(&min, &current)==1) {
				min = current;
			}
			digit = 0;
			for (int i=0; i<51; i++){
				current.digits[i]=0;
			}
		}
		else {
			current.digits[digit] = in;
			digit++;
		}
	}
	strim(&min);
	strim(&max);
	strim(&acc);
	printf("min:%s\n", min.digits);
	printf("max:%s\n", max.digits);
	printf("sum:%s\n", acc.digits);
}
static inline void part_hdr__part_name(enum diag204_format type, void *hdr,
				       char *name)
{
	if (type == DIAG204_INFO_SIMPLE)
		memcpy(name, ((struct diag204_part_hdr *)hdr)->part_name,
		       DIAG204_LPAR_NAME_LEN);
	else /* DIAG204_INFO_EXT */
		memcpy(name, ((struct diag204_x_part_hdr *)hdr)->part_name,
		       DIAG204_LPAR_NAME_LEN);
	EBCASC(name, DIAG204_LPAR_NAME_LEN);
	name[DIAG204_LPAR_NAME_LEN] = 0;
	strim(name);
}
Exemplo n.º 17
0
static char *cleanVersion(cchar *version) 
{
    char    *cp;

    cp = strim(version, " \tv=", 0);
    if (schr(cp, 'X')) {
        cp = sreplace(cp, "X", "x");
    }
    if (schr(cp, '*')) {
        cp = sreplace(cp, "*", "x");
    }
    return cp;
}
Exemplo n.º 18
0
static int edp_reg_override_write(struct file *file,
	const char __user *userbuf, size_t count, loff_t *ppos)
{
	char buf[32], *end;
	unsigned int edp_reg_override_mA_temp;
	unsigned int edp_reg_override_mA_prev = edp_reg_override_mA;

	if (sizeof(buf) <= count)
		goto override_err;

	if (copy_from_user(buf, userbuf, count))
		goto override_err;

	/* terminate buffer and trim - white spaces may be appended
	 *  at the end when invoked from shell command line */
	buf[count]='\0';
	strim(buf);

	edp_reg_override_mA_temp = simple_strtoul(buf, &end, 10);
	if (*end != '\0')
		goto override_err;

	if (edp_reg_override_mA_temp >= regulator_cur)
		goto override_err;

	if (edp_reg_override_mA == edp_reg_override_mA_temp)
		return count;

	edp_reg_override_mA = edp_reg_override_mA_temp;
	if (init_cpu_edp_limits_calculated()) {
		/* Revert to previous override value if new value fails */
		edp_reg_override_mA = edp_reg_override_mA_prev;
		goto override_err;
	}

	if (tegra_cpu_set_speed_cap(NULL)) {
		pr_err("FAILED: Set CPU freq cap with new VDD_CPU EDP table\n");
		goto override_out;
	}

	pr_info("Reinitialized VDD_CPU EDP table with regulator current limit"
			" %u mA\n", regulator_cur - edp_reg_override_mA);

	return count;

override_err:
	pr_err("FAILED: Reinitialize VDD_CPU EDP table with override \"%s\"",
	       buf);
override_out:
	return -EINVAL;
}
static ssize_t mc96fr1196c_ir_send_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t size)
{
	struct mc96fr116c_data *data = dev_get_drvdata(dev);
	unsigned int value;
	char *string, *pstring;
	int signal_length = 2; /* By default, 2 bytes for data length */
	int ir_sum = 0;
	int number_freq = 0;
	int ret;

	if (data->mode != MC96FR116C_USER_IR_MODE) {
		dev_err(&data->client->dev, "%s: Not user IR mode.\n",
				__func__);
		return -EINVAL;
	}

	if (!mutex_trylock(&data->signal_mutex))
		return -EBUSY;

	string = (char*)kmalloc(size + 1, GFP_KERNEL);
	strlcpy(string, buf, size);
	pstring = strim(string);

	while (pstring) {
		char *curr_string;

		curr_string = strsep(&pstring, " ,");

		if (*curr_string == '\0')
			continue;

		ret = kstrtouint(curr_string, 0, &value);

		if (!value)
			break;

		if (ret < 0) {
			dev_err(dev, "Error: Invalid argument. Could not convert.\n");
			goto out;
		}
		if (signal_length == 2) {
			data->carrier_freq = value;
			data->signal[2] = (value >> 16) & 0xFF;
			data->signal[3] = (value >> 8) & 0xFF;
			data->signal[4] = value & 0xFF;
			signal_length += 3;
		} else {
Exemplo n.º 20
0
/*
    Match a keyword in the content returned from the last request
    Format is:
        KEYWORD = value
 */
bool match(MprTestGroup *gp, char *key, char *value)
{
    char    *vp, *trim;

    vp = lookupValue(gp, key);
    if (vp == 0 && value == 0) {
        return 1;
    }
    trim = strim(vp, "\"", MPR_TRIM_BOTH);
    if (vp == 0 || value == 0 || scmp(trim, value) != 0) {
        mprLog("appweb test match", 0, "Match %s failed. Got \"%s\" expected \"%s\"", key, vp, value);
        mprLog("appweb test match", 0, "Content %s", gp->content);
        return 0;
    }
    return 1;
}
Exemplo n.º 21
0
static void int_to_ext_kekl(struct tape3592_kekl *in,
			    struct tape390_kekl *out)
{
	memset(out, 0, sizeof(*out));
	if(in->flags & 0x40)
		out->type = TAPE390_KEKL_TYPE_HASH;
	else
		out->type = TAPE390_KEKL_TYPE_LABEL;
	if(in->flags & 0x80)
		out->type_on_tape = TAPE390_KEKL_TYPE_HASH;
	else
		out->type_on_tape = TAPE390_KEKL_TYPE_LABEL;
	memcpy(out->label, in->label, sizeof(in->label));
	EBCASC(out->label, sizeof(in->label));
	strim(out->label);
}
Exemplo n.º 22
0
static inline bool __split_insert_one_part(char *subject, char *begin, int32_t len, split_node_t *split_node, bool need_strim)
{
    bool insert_ok = false;
    /* begin, len */
    split_node->part_len = len;

    if (likely(need_strim)) {
        begin = strim(begin, &(split_node->part_len));
    }

    if (PTR_NOT_NULL(begin) && split_node->part_len > 0) {
        split_node->begin_offset = begin - subject;
        insert_ok = true;
    }

    return insert_ok;
}
Exemplo n.º 23
0
static ssize_t __alt_name_store(struct device *dev, const char *buf,
		const size_t len)
{
	char *input, *pos, *alt_name, **ns_altname;
	ssize_t rc;

	if (is_namespace_pmem(dev)) {
		struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev);

		ns_altname = &nspm->alt_name;
	} else if (is_namespace_blk(dev)) {
		struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev);

		ns_altname = &nsblk->alt_name;
	} else
		return -ENXIO;

	if (dev->driver || to_ndns(dev)->claim)
		return -EBUSY;

	input = kmemdup(buf, len + 1, GFP_KERNEL);
	if (!input)
		return -ENOMEM;

	input[len] = '\0';
	pos = strim(input);
	if (strlen(pos) + 1 > NSLABEL_NAME_LEN) {
		rc = -EINVAL;
		goto out;
	}

	alt_name = kzalloc(NSLABEL_NAME_LEN, GFP_KERNEL);
	if (!alt_name) {
		rc = -ENOMEM;
		goto out;
	}
	kfree(*ns_altname);
	*ns_altname = alt_name;
	sprintf(*ns_altname, "%s", pos);
	rc = len;

out:
	kfree(input);
	return rc;
}
Exemplo n.º 24
0
static int do_readf(int argc, char *argv[])
{
	unsigned char *buf = NULL, *val;
	char *variable, *filename;
	struct stat s;
	size_t size;
	int ret, i;

	if (argc != 3)
		return COMMAND_ERROR_USAGE;

	filename = argv[1];
	variable = argv[2];

	ret = stat(filename, &s);
	if (ret)
		goto out;

	if (s.st_size > 1024) {
		ret = -EFBIG;
		goto out;
	}

	buf = read_file(filename, &size);
	if (!buf)
		goto out;

	for (i = 0; i < size; i++) {
		if (!isprint(buf[i])) {
			buf[i] = '\0';
			break;
		}
	}

	val = strim(buf);

	ret = setenv(variable, val);
out:
	free(buf);

	return ret;
}
Exemplo n.º 25
0
ssize_t read_string_list(const char *buf, const char * const list[])
{
	size_t i;
	char *s, *d = strdup(buf);
	if (!d)
		return -ENOMEM;

	s = strim(d);

	for (i = 0; list[i]; i++)
		if (!strcmp(list[i], s))
			break;

	free(d);

	if (!list[i])
		return -EINVAL;

	return i;
}
Exemplo n.º 26
0
/*
    Match a keyword an ignore case for windows
 */
bool matchAnyCase(MprTestGroup *gp, char *key, char *value)
{
    char    *vp, *trim;

    vp = lookupValue(gp, key);
    if (vp == 0 && value == 0) {
        return 1;
    }
    trim = strim(vp, "\"", MPR_TRIM_BOTH);
#if BIT_WIN_LIKE
    if (vp == 0 || scaselesscmp(trim, value) != 0)
#else
    if (vp == 0 || value == 0 || scmp(trim, value) != 0)
#endif
    {
        mprLog("appweb test match", 0, "Match %s failed. Got %s expected %s", key, vp, value);
        return 0;
    }
    return 1;
}
Exemplo n.º 27
0
/**
 * aa_split_fqname - split a fqname into a profile and namespace name
 * @fqname: a full qualified name in namespace profile format (NOT NULL)
 * @ns_name: pointer to portion of the string containing the ns name (NOT NULL)
 *
 * Returns: profile name or NULL if one is not specified
 *
 * Split a namespace name from a profile name (see policy.c for naming
 * description).  If a portion of the name is missing it returns NULL for
 * that portion.
 *
 * NOTE: may modify the @fqname string.  The pointers returned point
 *       into the @fqname string.
 */
char *aa_split_fqname(char *fqname, char **ns_name)
{
	char *name = strim(fqname);

	*ns_name = NULL;
	if (name[0] == ':') {
		char *split = strchr(&name[1], ':');
		*ns_name = skip_spaces(&name[1]);
		if (split) {
			/* overwrite ':' with \0 */
			*split = 0;
			name = skip_spaces(split + 1);
		} else
			/* a ns name without a following profile is allowed */
			name = NULL;
	}
	if (name && *name == 0)
		name = NULL;

	return name;
}
static ssize_t iso_res_realize_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t size)
{

	unsigned int bw;
	unsigned int ult = 4;
	char buff[50];
	char *val, *s;
	int ret;
	struct tegra_bbc_proxy *bbc = dev_get_drvdata(dev);

	strlcpy(buff, buf, sizeof(buff));
	s = strim(buff);

	/* first param is bw */
	val = strsep(&s, ",");
	ret = kstrtouint(val, 10, &bw);
	if (ret) {
		pr_err("invalid bw setting\n");
		return -EINVAL;
	}

	/* second param is latency */
	if (s) {
		ret = kstrtouint(s, 10, &ult);
		if (ret) {
			pr_err("invalid latency setting\n");
			return -EINVAL;
		}
	}

	mutex_lock(&bbc->iso_lock);
	bbc->last_bw = bw;
	bbc->last_ult = ult;

	ret = bbc_bw_request_unlocked(dev, 0, bw, ult, bbc->margin);
	mutex_unlock(&bbc->iso_lock);

	return ret ? ret : size;
}
Exemplo n.º 29
0
/*  
    Read input from the console (stdin)
 */
static int consoleGets(EcStream *stream)
{
    char    prompt[MPR_MAX_STRING], *line, *cp;
    int     level;

    if (stream->flags & EC_STREAM_EOL) {
        return 0;
    }
    level = stream->compiler->state ? stream->compiler->state->blockNestCount : 0;
    fmt(prompt, sizeof(prompt), "%s-%d> ", EJS_NAME, level);

    mprYield(MPR_YIELD_STICKY);
    line = readline(prompt);
    mprResetYield();
    if (line == NULL) {
        stream->eof = 1;
        mprPrintf("\n");
        return -1;
    }
    cp = strim(line, "\r\n", MPR_TRIM_BOTH);
    ecSetStreamBuf(stream, cp, slen(cp));
    stream->flags |= EC_STREAM_EOL;
    return (int) slen(cp);
}
Exemplo n.º 30
0
static int __init init_fssuper(void) 
{

	struct super_block *sb;
	struct block_device *bdev = NULL;
	
	printk(KERN_INFO "Start module from here\t");

	if(dev == NULL) {
		printk(KERN_ERR "Device not specified");
		return 0;
	} 
	
	bdev = lookup_bdev(strim(dev));
	
	if(IS_ERR(bdev)) {	
		if(bdev == ERR_PTR(-EBUSY)) 
			printk(KERN_ERR "Device busy\t");
	
		printk(KERN_ERR "Couldn't lock device <%ld>", PTR_ERR(bdev));
		return 0;
	}
	
	sb = get_super(bdev);
	bdput(bdev);
	
	if(IS_ERR(sb)) {
		printk(KERN_ERR "Can't load sb <%ld>", PTR_ERR(sb));
		return 0;
	}
	
	printk(KERN_INFO "Sucessfuly loaded sb, uuid %x \t", *(sb->s_uuid));
	printk(KERN_INFO "File system : %s \t", sb->s_type->name);
	printk(KERN_INFO "Device: %x, super %x", bdev, sb);
	return 0;
}