您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ startswith函数代码示例

51自学网 2021-06-03 08:22:22
  C++
这篇教程C++ startswith函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中startswith函数的典型用法代码示例。如果您正苦于以下问题:C++ startswith函数的具体用法?C++ startswith怎么用?C++ startswith使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了startswith函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: gnuv3_is_vtable_name

static intgnuv3_is_vtable_name (const char *name){  return startswith (name, "_ZTV");}
开发者ID:Jactry,项目名称:binutils-gdb,代码行数:5,


示例2: assert

bool PhiAnalysis::isRequired(const std::string &name, CFGBlock* block) {    assert(!startswith(name, "!"));    return required_phis[block].count(name) != 0;}
开发者ID:eschlon,项目名称:pyston,代码行数:4,


示例3: parse_time

int parse_time(const char *t, usec_t *usec, usec_t default_unit) {        const char *p, *s;        usec_t r = 0;        bool something = false;        assert(t);        assert(usec);        assert(default_unit > 0);        p = t;        p += strspn(p, WHITESPACE);        s = startswith(p, "infinity");        if (s) {                s += strspn(s, WHITESPACE);                if (*s != 0)                        return -EINVAL;                *usec = USEC_INFINITY;                return 0;        }        for (;;) {                long long l, z = 0;                char *e;                unsigned n = 0;                usec_t multiplier = default_unit, k;                p += strspn(p, WHITESPACE);                if (*p == 0) {                        if (!something)                                return -EINVAL;                        break;                }                errno = 0;                l = strtoll(p, &e, 10);                if (errno > 0)                        return -errno;                if (l < 0)                        return -ERANGE;                if (*e == '.') {                        char *b = e + 1;                        errno = 0;                        z = strtoll(b, &e, 10);                        if (errno > 0)                                return -errno;                        if (z < 0)                                return -ERANGE;                        if (e == b)                                return -EINVAL;                        n = e - b;                } else if (e == p)                        return -EINVAL;                e += strspn(e, WHITESPACE);                p = extract_multiplier(e, &multiplier);                something = true;                k = (usec_t) z * multiplier;                for (; n > 0; n--)                        k /= 10;                r += (usec_t) l * multiplier + k;        }        *usec = r;        return 0;}
开发者ID:atulhjp,项目名称:NetworkManager,代码行数:80,


示例4: explicit_location_lex_one

static gdb::unique_xmalloc_ptr<char>explicit_location_lex_one (const char **inp,			   const struct language_defn *language,			   explicit_completion_info *completion_info){  const char *start = *inp;  if (*start == '/0')    return NULL;  /* If quoted, skip to the ending quote.  */  if (strchr (get_gdb_linespec_parser_quote_characters (), *start))    {      if (completion_info != NULL)	completion_info->quoted_arg_start = start;      const char *end = find_end_quote (start + 1, *start);      if (end == NULL)	{	  if (completion_info == NULL)	    error (_("Unmatched quote, %s."), start);	  end = start + strlen (start);	  *inp = end;	  return gdb::unique_xmalloc_ptr<char> (savestring (start + 1,							    *inp - start - 1));	}      if (completion_info != NULL)	completion_info->quoted_arg_end = end;      *inp = end + 1;      return gdb::unique_xmalloc_ptr<char> (savestring (start + 1,							*inp - start - 2));    }  /* If the input starts with '-' or '+', the string ends with the next     whitespace or comma.  */  if (*start == '-' || *start == '+')    {      while (*inp[0] != '/0' && *inp[0] != ',' && !isspace (*inp[0]))	++(*inp);    }  else    {      /* Handle numbers first, stopping at the next whitespace or ','.  */      while (isdigit (*inp[0]))	++(*inp);      if (*inp[0] == '/0' || isspace (*inp[0]) || *inp[0] == ',')	return gdb::unique_xmalloc_ptr<char> (savestring (start,							  *inp - start));      /* Otherwise stop at the next occurrence of whitespace, '/0',	 keyword, or ','.  */      *inp = start;      while ((*inp)[0]	     && (*inp)[0] != ','	     && !(isspace ((*inp)[0])		  || linespec_lexer_lex_keyword (&(*inp)[1])))	{	  /* Special case: C++ operator,.  */	  if (language->la_language == language_cplus	      && startswith (*inp, CP_OPERATOR_STR))	    (*inp) += CP_OPERATOR_LEN;	  ++(*inp);	}    }  if (*inp - start > 0)    return gdb::unique_xmalloc_ptr<char> (savestring (start, *inp - start));  return NULL;}
开发者ID:jon-turney,项目名称:binutils-gdb,代码行数:73,


示例5: parse_size

//.........这里部分代码省略.........        { "K", 1024ULL },        { "B", 1ULL },        { "",  1ULL },    };    static const struct table si[] = {        { "E", 1000ULL*1000ULL*1000ULL*1000ULL*1000ULL*1000ULL },        { "P", 1000ULL*1000ULL*1000ULL*1000ULL*1000ULL },        { "T", 1000ULL*1000ULL*1000ULL*1000ULL },        { "G", 1000ULL*1000ULL*1000ULL },        { "M", 1000ULL*1000ULL },        { "K", 1000ULL },        { "B", 1ULL },        { "",  1ULL },    };    const struct table *table;    const char *p;    unsigned long long r = 0;    unsigned n_entries, start_pos = 0;    assert(t);    assert(base == 1000 || base == 1024);    assert(size);    if (base == 1000) {        table = si;        n_entries = ELEMENTSOF(si);    } else {        table = iec;        n_entries = ELEMENTSOF(iec);    }    p = t;    do {        unsigned long long l, tmp;        double frac = 0;        char *e;        unsigned i;        p += strspn(p, WHITESPACE);        if (*p == '-')            return -ERANGE;        errno = 0;        l = strtoull(p, &e, 10);        if (errno > 0)            return -errno;        if (e == p)            return -EINVAL;        if (*e == '.') {            e++;            /* strtoull() itself would accept space/+/- */            if (*e >= '0' && *e <= '9') {                unsigned long long l2;                char *e2;                l2 = strtoull(e, &e2, 10);                if (errno > 0)                    return -errno;                /* Ignore failure. E.g. 10.M is valid */                frac = l2;                for (; e < e2; e++)                    frac /= 10;            }        }        e += strspn(e, WHITESPACE);        for (i = start_pos; i < n_entries; i++)            if (startswith(e, table[i].suffix))                break;        if (i >= n_entries)            return -EINVAL;        if (l + (frac > 0) > ULLONG_MAX / table[i].factor)            return -ERANGE;        tmp = l * table[i].factor + (unsigned long long) (frac * table[i].factor);        if (tmp > ULLONG_MAX - r)            return -ERANGE;        r += tmp;        if ((unsigned long long) (uint64_t) r != r)            return -ERANGE;        p = e + strlen(table[i].suffix);        start_pos = i + 1;    } while (*p);    *size = r;    return 0;}
开发者ID:rhdrjones,项目名称:systemd,代码行数:101,


示例6: get_file_options

//.........这里部分代码省略.........                while (isspace(*buf))                        buf++;                /* blank or all whitespace line */                if (*buf == '/0')                        continue;                /* comment line */                if (*buf == '#')                        continue;                str1 = strsep(&buf, "=");                if (str1 && strcaseeq(str1, "VENDOR")) {                        str1 = get_value(&buf);                        if (!str1) {                                retval = log_oom();                                break;                        }                        vendor_in = str1;                        str1 = strsep(&buf, "=");                        if (str1 && strcaseeq(str1, "MODEL")) {                                str1 = get_value(&buf);                                if (!str1) {                                        retval = log_oom();                                        break;                                }                                model_in = str1;                                str1 = strsep(&buf, "=");                        }                }                if (str1 && strcaseeq(str1, "OPTIONS")) {                        str1 = get_value(&buf);                        if (!str1) {                                retval = log_oom();                                break;                        }                        options_in = str1;                }                /*                 * Only allow: [vendor=foo[,model=bar]]options=stuff                 */                if (!options_in || (!vendor_in && model_in)) {                        log_error("Error parsing config file line %d '%s'", lineno, buffer);                        retval = -1;                        break;                }                if (vendor == NULL) {                        if (vendor_in == NULL)                                break;                } else if (vendor_in &&                           startswith(vendor, vendor_in) &&                           (!model_in || startswith(model, model_in))) {                                /*                                 * Matched vendor and optionally model.                                 *                                 * Note: a short vendor_in or model_in can                                 * give a partial match (that is FOO                                 * matches FOOBAR).                                 */                                break;                }        }        if (retval == 0) {                if (vendor_in != NULL || model_in != NULL ||                    options_in != NULL) {                        /*                         * Something matched. Allocate newargv, and store                         * values found in options_in.                         */                        strcpy(buffer, options_in);                        c = argc_count(buffer) + 2;                        *newargv = calloc(c, sizeof(**newargv));                        if (!*newargv)                                retval = log_oom();                        else {                                *argc = c;                                c = 0;                                /*                                 * argv[0] at 0 is skipped by getopt, but                                 * store the buffer address there for                                 * later freeing                                 */                                (*newargv)[c] = buffer;                                for (c = 1; c < *argc; c++)                                        (*newargv)[c] = strsep(&buffer, " /t");                        }                } else {                        /* No matches  */                        retval = 1;                }        }        if (retval != 0)                free(buffer);        return retval;}
开发者ID:dankor,项目名称:systemd,代码行数:101,


示例7: _nss_myhostname_gethostbyname4_r

enum nss_status _nss_myhostname_gethostbyname4_r(                const char *name,                struct gaih_addrtuple **pat,                char *buffer, size_t buflen,                int *errnop, int *h_errnop,                int32_t *ttlp) {        struct gaih_addrtuple *r_tuple, *r_tuple_prev = NULL;        _cleanup_free_ struct local_address *addresses = NULL;        _cleanup_free_ char *hn = NULL;        const char *canonical = NULL;        int n_addresses = 0;        uint32_t local_address_ipv4;        struct local_address *a;        size_t l, idx, ms;        char *r_name;        unsigned n;        PROTECT_ERRNO;        BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);        assert(name);        assert(pat);        assert(buffer);        assert(errnop);        assert(h_errnop);        if (is_localhost(name)) {                /* We respond to 'localhost', so that /etc/hosts                 * is optional */                canonical = "localhost";                local_address_ipv4 = htobe32(INADDR_LOOPBACK);        } else if (is_gateway_hostname(name)) {                n_addresses = local_gateways(NULL, 0, AF_UNSPEC, &addresses);                if (n_addresses <= 0) {                        *h_errnop = HOST_NOT_FOUND;                        return NSS_STATUS_NOTFOUND;                }                canonical = "_gateway";        } else {                hn = gethostname_malloc();                if (!hn) {                        *errnop = ENOMEM;                        *h_errnop = NO_RECOVERY;                        return NSS_STATUS_TRYAGAIN;                }                /* We respond to our local host name, our hostname suffixed with a single dot. */                if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) {                        *h_errnop = HOST_NOT_FOUND;                        return NSS_STATUS_NOTFOUND;                }                n_addresses = local_addresses(NULL, 0, AF_UNSPEC, &addresses);                if (n_addresses < 0)                        n_addresses = 0;                canonical = hn;                local_address_ipv4 = LOCALADDRESS_IPV4;        }        l = strlen(canonical);        ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * (n_addresses > 0 ? n_addresses : 2);        if (buflen < ms) {                *errnop = ERANGE;                *h_errnop = NETDB_INTERNAL;                return NSS_STATUS_TRYAGAIN;        }        /* First, fill in hostname */        r_name = buffer;        memcpy(r_name, canonical, l+1);        idx = ALIGN(l+1);        assert(n_addresses >= 0);        if (n_addresses == 0) {                /* Second, fill in IPv6 tuple */                r_tuple = (struct gaih_addrtuple*) (buffer + idx);                r_tuple->next = r_tuple_prev;                r_tuple->name = r_name;                r_tuple->family = AF_INET6;                memcpy(r_tuple->addr, LOCALADDRESS_IPV6, 16);                r_tuple->scopeid = 0;                idx += ALIGN(sizeof(struct gaih_addrtuple));                r_tuple_prev = r_tuple;                /* Third, fill in IPv4 tuple */                r_tuple = (struct gaih_addrtuple*) (buffer + idx);                r_tuple->next = r_tuple_prev;                r_tuple->name = r_name;                r_tuple->family = AF_INET;                *(uint32_t*) r_tuple->addr = local_address_ipv4;                r_tuple->scopeid = 0;//.........这里部分代码省略.........
开发者ID:Keruspe,项目名称:systemd,代码行数:101,


示例8: while

/** Built-in preprocessing callback * * Built-in preprocessing callback to break or not to break URLs according to * some rules by Chicago Manual of Style 15th ed. * If data is NULL, prohibit break. * Otherwise, allow break by rule above. */gcstring_t *linebreak_prep_URIBREAK(linebreak_t * lbobj, void *data,				    unistr_t * str, unistr_t * text){    gcstring_t *gcstr;    size_t i;    unichar_t *ptr;    /* Pass I */    if (text != NULL) {	/*	 * Search URL in str.	 * Following code loosely refers RFC3986 but some practical	 * assumptions are put:	 *	 * o Broken pct-encoded sequences (e.g. single "%") are allowed.	 * o scheme names must end with alphanumeric, must be longer than	 *   or equal to two octets, and must not contain more than one	 *   non-alphanumeric ("+", "-" or ".").	 * o URLs containing neither non-empty path, query part nor fragment	 *   (e.g. "about:") are omitted: they are treated as ordinal words.	 */	for (ptr = NULL, i = 0; i < str->len; ptr = NULL, i++) {	    int has_double_slash, has_authority, has_empty_path,		has_no_query, has_no_fragment;	    size_t alphadigit, nonalphadigit;	    /* skip non-alpha. */	    if (!is_alpha(str, i))		continue;	    ptr = str->str + i;	    /* "url:" - case insensitive */	    if (startswith(str, i, "url:", 4, 0))		i += 4;	    /* scheme */	    if (is_alpha(str, i))		i++;	    else		continue;	    nonalphadigit = 0;	    alphadigit = 1;	    while (1) {		if (is_alpha(str, i) || is_digit(str, i))		    alphadigit++;		else if (is(str, i, '+') || is(str, i, '-') || is(str, i, '.'))		    nonalphadigit++;		else		    break;		i++;	    }	    if (alphadigit < 2 || 1 < nonalphadigit ||	        ! (is_digit(str, i - 1) || is_alpha(str, i - 1)))		continue;	    /* ":" */	    if (is(str, i, ':'))		i++;	    else		continue;	    /* hier-part */	    has_double_slash = 0;	    has_authority = 0;	    has_empty_path = 0;	    has_no_query = 0;	    has_no_fragment = 0;	    if (startswith(str, i, "//", 2, 0)) {		/* "//" */		has_double_slash = 1;		i += 2;		/* authority - FIXME:syntax relaxed */		if (is(str, i, '[') || is(str, i, ':') || is(str, i, '@') ||		    is_unreserved(str, i) || is_pct_encoded(str, i) ||		    is_sub_delim(str, i)) {		    has_authority = 1;		    i++;		    while (is(str, i, '[') || is(str, i, ']') ||			   is(str, i, ':') || is(str, i, '@') ||			   is_unreserved(str, i) || is_pct_encoded(str, i) ||			   is_sub_delim(str, i))			i++;		}	    }	    /* path */	    if (has_double_slash) {		if (has_authority)		    goto path_abempty;//.........这里部分代码省略.........
开发者ID:gitpan,项目名称:Unicode-LineBreak,代码行数:101,


示例9: proto_tick

void proto_tick() {	int nbytes;	char data[BUFSIZE/2];	while (bot->running) {		memset(&data, 0, BUFSIZE/2);tick:		tick_functions();		recv:		if ((nbytes = recv(bot->socket, data, (BUFSIZE/2)-1, 0)) == -1) {			if (errno == EINTR) {				// what a pain in the ass,				// we got interrupted >.>				goto recv;			}			if (errno == EAGAIN) {				usleep(16666);				goto tick;			}			perror("recv failed");			exit(4);		}		strcat(bot->buffer, data);		if (nbytes == 0) {			bot->running = 0;		}		char *i = irc_getline(bot);		if (i == NULL) {			return;		}		for (; i != NULL; i = irc_nextline(bot)) {			printf("%s/n", i);			if (startswith(i, "PING")) {				char *t = last(i);				sockprintf(bot->socket, "PONG %s", t);				free(t);				free(i);				continue;			}			struct message *msg = parse(i);			if (EQ(msg->meth, "422") || EQ(msg->meth, "376")) {				sockprintf(bot->socket, "JOIN #bots");			}			Link *handlers = hashmap_get(msg->meth, bot->handlers);			for (Link *i = handlers; i != NULL; i = i->next) {				((handler_t)i->ptr)(bot, msg);			}			freemsg(msg);			free(i);		}	}}
开发者ID:svkampen,项目名称:Apollo,代码行数:66,


示例10: builtin_keyboard

static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], bool test) {        struct udev_list_entry *entry;        unsigned release[1024];        unsigned release_count = 0;        _cleanup_close_ int fd = -1;        const char *node;        int has_abs = -1;        node = udev_device_get_devnode(dev);        if (!node) {                log_error("No device node for /"%s/"", udev_device_get_syspath(dev));                return EXIT_FAILURE;        }        udev_list_entry_foreach(entry, udev_device_get_properties_list_entry(dev)) {                const char *key;                char *endptr;                key = udev_list_entry_get_name(entry);                if (startswith(key, "KEYBOARD_KEY_")) {                        const char *keycode;                        unsigned scancode;                        /* KEYBOARD_KEY_<hex scan code>=<key identifier string> */                        scancode = strtoul(key + 13, &endptr, 16);                        if (endptr[0] != '/0') {                                log_warning("Unable to parse scan code from /"%s/"", key);                                continue;                        }                        keycode = udev_list_entry_get_value(entry);                        /* a leading '!' needs a force-release entry */                        if (keycode[0] == '!') {                                keycode++;                                release[release_count] = scancode;                                if (release_count <  ELEMENTSOF(release)-1)                                        release_count++;                                if (keycode[0] == '/0')                                        continue;                        }                        if (fd == -1) {                                fd = open_device(node);                                if (fd < 0)                                        return EXIT_FAILURE;                        }                        map_keycode(fd, node, scancode, keycode);                } else if (startswith(key, "EVDEV_ABS_")) {                        unsigned evcode;                        /* EVDEV_ABS_<EV_ABS code>=<min>:<max>:<res>:<fuzz>:<flat> */                        evcode = strtoul(key + 10, &endptr, 16);                        if (endptr[0] != '/0') {                                log_warning("Unable to parse EV_ABS code from /"%s/"", key);                                continue;                        }                        if (fd == -1) {                                fd = open_device(node);                                if (fd < 0)                                        return EXIT_FAILURE;                        }                        if (has_abs == -1) {                                unsigned long bits;                                int rc;                                rc = ioctl(fd, EVIOCGBIT(0, sizeof(bits)), &bits);                                if (rc < 0) {                                        log_error_errno(errno, "Unable to EVIOCGBIT device /"%s/"", node);                                        return EXIT_FAILURE;                                }                                has_abs = !!(bits & (1 << EV_ABS));                                if (!has_abs)                                        log_warning("EVDEV_ABS override set but no EV_ABS present on device /"%s/"", node);                        }                        if (!has_abs)                                continue;                        override_abs(fd, node, evcode, udev_list_entry_get_value(entry));                } else if (streq(key, "POINTINGSTICK_SENSITIVITY"))                        set_trackpoint_sensitivity(dev, udev_list_entry_get_value(entry));        }        /* install list of force-release codes */        if (release_count > 0)                install_force_release(dev, release, release_count);        return EXIT_SUCCESS;}
开发者ID:Hariprasathganesh,项目名称:testsysd,代码行数:96,


示例11: c_type_print_base

voidc_type_print_base (struct type *type, struct ui_file *stream,		   int show, int level, const struct type_print_options *flags){  int i;  int len, real_len;  enum    {      s_none, s_public, s_private, s_protected    }  section_type;  int need_access_label = 0;  int j, len2;  QUIT;  if (type == NULL)    {      fputs_filtered (_("<type unknown>"), stream);      return;    }  /* When SHOW is zero or less, and there is a valid type name, then     always just print the type name directly from the type.  */  /* If we have "typedef struct foo {. . .} bar;" do we want to print     it as "struct foo" or as "bar"?  Pick the latter, because C++     folk tend to expect things like "class5 *foo" rather than "struct     class5 *foo".  */  if (show <= 0      && TYPE_NAME (type) != NULL)    {      c_type_print_modifier (type, stream, 0, 1);      print_name_maybe_canonical (TYPE_NAME (type), flags, stream);      return;    }  type = check_typedef (type);  switch (TYPE_CODE (type))    {    case TYPE_CODE_TYPEDEF:      /* If we get here, the typedef doesn't have a name, and we	 couldn't resolve TYPE_TARGET_TYPE.  Not much we can do.  */      gdb_assert (TYPE_NAME (type) == NULL);      gdb_assert (TYPE_TARGET_TYPE (type) == NULL);      fprintf_filtered (stream, _("<unnamed typedef>"));      break;    case TYPE_CODE_ARRAY:    case TYPE_CODE_PTR:    case TYPE_CODE_MEMBERPTR:    case TYPE_CODE_REF:    case TYPE_CODE_FUNC:    case TYPE_CODE_METHOD:    case TYPE_CODE_METHODPTR:      c_type_print_base (TYPE_TARGET_TYPE (type),			 stream, show, level, flags);      break;    case TYPE_CODE_STRUCT:    case TYPE_CODE_UNION:      {	struct type_print_options local_flags = *flags;	struct type_print_options semi_local_flags = *flags;	struct cleanup *local_cleanups = make_cleanup (null_cleanup, NULL);	local_flags.local_typedefs = NULL;	semi_local_flags.local_typedefs = NULL;	if (!flags->raw)	  {	    if (flags->local_typedefs)	      local_flags.local_typedefs		= copy_typedef_hash (flags->local_typedefs);	    else	      local_flags.local_typedefs = create_typedef_hash ();	    make_cleanup_free_typedef_hash (local_flags.local_typedefs);	  }	c_type_print_modifier (type, stream, 0, 1);	if (TYPE_CODE (type) == TYPE_CODE_UNION)	  fprintf_filtered (stream, "union ");	else if (TYPE_DECLARED_CLASS (type))	  fprintf_filtered (stream, "class ");	else	  fprintf_filtered (stream, "struct ");	/* Print the tag if it exists.  The HP aCC compiler emits a	   spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed	   enum}" tag for unnamed struct/union/enum's, which we don't	   want to print.  */	if (TYPE_TAG_NAME (type) != NULL	    && !startswith (TYPE_TAG_NAME (type), "{unnamed"))	  {	    /* When printing the tag name, we are still effectively	       printing in the outer context, hence the use of FLAGS	       here.  */	    print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);//.........这里部分代码省略.........
开发者ID:Caleb1994,项目名称:stewieos-binutils,代码行数:101,


示例12: tfile_open

static voidtfile_open (const char *arg, int from_tty){  char *temp;  struct cleanup *old_chain;  int flags;  int scratch_chan;  char header[TRACE_HEADER_SIZE];  char linebuf[1000]; /* Should be max remote packet size or so.  */  gdb_byte byte;  int bytes, i;  struct trace_status *ts;  struct uploaded_tp *uploaded_tps = NULL;  struct uploaded_tsv *uploaded_tsvs = NULL;  char *filename;  target_preopen (from_tty);  if (!arg)    error (_("No trace file specified."));  filename = tilde_expand (arg);  if (!IS_ABSOLUTE_PATH(filename))    {      temp = concat (current_directory, "/", filename, (char *) NULL);      xfree (filename);      filename = temp;    }  old_chain = make_cleanup (xfree, filename);  flags = O_BINARY | O_LARGEFILE;  flags |= O_RDONLY;  scratch_chan = gdb_open_cloexec (filename, flags, 0);  if (scratch_chan < 0)    perror_with_name (filename);  /* Looks semi-reasonable.  Toss the old trace file and work on the new.  */  discard_cleanups (old_chain);	/* Don't free filename any more.  */  unpush_target (&tfile_ops);  trace_filename = xstrdup (filename);  trace_fd = scratch_chan;  /* Make sure this is clear.  */  buffer_free (&trace_tdesc);  bytes = 0;  /* Read the file header and test for validity.  */  tfile_read ((gdb_byte *) &header, TRACE_HEADER_SIZE);  bytes += TRACE_HEADER_SIZE;  if (!(header[0] == 0x7f	&& (startswith (header + 1, "TRACE0/n"))))    error (_("File is not a valid trace file."));  push_target (&tfile_ops);  trace_regblock_size = 0;  ts = current_trace_status ();  /* We know we're working with a file.  Record its name.  */  ts->filename = trace_filename;  /* Set defaults in case there is no status line.  */  ts->running_known = 0;  ts->stop_reason = trace_stop_reason_unknown;  ts->traceframe_count = -1;  ts->buffer_free = 0;  ts->disconnected_tracing = 0;  ts->circular_buffer = 0;  TRY    {      /* Read through a section of newline-terminated lines that	 define things like tracepoints.  */      i = 0;      while (1)	{	  tfile_read (&byte, 1);	  ++bytes;	  if (byte == '/n')	    {	      /* Empty line marks end of the definition section.  */	      if (i == 0)		break;	      linebuf[i] = '/0';	      i = 0;	      tfile_interp_line (linebuf, &uploaded_tps, &uploaded_tsvs);	    }	  else	    linebuf[i++] = byte;	  if (i >= 1000)	    error (_("Excessively long lines in trace file"));	}      /* By now, tdesc lines have been read from tfile - let's parse them.  */      target_find_description ();      /* Record the starting offset of the binary trace data.  */      trace_frames_offset = bytes;//.........这里部分代码省略.........
开发者ID:kraj,项目名称:binutils-gdb,代码行数:101,


示例13: dict_hash

static unsigned intdict_hash (const char *string0){  /* The Ada-encoded version of a name P1.P2...Pn has either the form     P1__P2__...Pn<suffix> or _ada_P1__P2__...Pn<suffix> (where the Pi     are lower-cased identifiers).  The <suffix> (which can be empty)     encodes additional information about the denoted entity.  This     routine hashes such names to msymbol_hash_iw(Pn).  It actually     does this for a superset of both valid Pi and of <suffix>, but      in other cases it simply returns msymbol_hash_iw(STRING0).  */  const char *string;  unsigned int hash;  string = string0;  if (*string == '_')    {      if (startswith (string, "_ada_"))	string += 5;      else	return msymbol_hash_iw (string0);    }  hash = 0;  while (*string)    {      /* Ignore "TKB" suffixes.	 These are used by Ada for subprograms implementing a task body.	 For instance for a task T inside package Pck, the name of the	 subprogram implementing T's body is `pck__tTKB'.  We need to	 ignore the "TKB" suffix because searches for this task body	 subprogram are going to be performed using `pck__t' (the encoded	 version of the natural name `pck.t').  */      if (strcmp (string, "TKB") == 0)	return hash;      switch (*string)	{	case '$':	case '.':	case 'X':	  if (string0 == string)	    return msymbol_hash_iw (string0);	  else	    return hash;	case ' ':	case '(':	  return msymbol_hash_iw (string0);	case '_':	  if (string[1] == '_' && string != string0)	    {	      int c = string[2];	      if ((c < 'a' || c > 'z') && c != 'O')		return hash;	      hash = 0;	      string += 2;	      break;	    }	  /* FALL THROUGH */	default:	  hash = SYMBOL_HASH_NEXT (hash, *string);	  string += 1;	  break;	}    }  return hash;}
开发者ID:ajinkya93,项目名称:netbsd-src,代码行数:69,


示例14: gnuv3_is_operator_name

static intgnuv3_is_operator_name (const char *name){  return startswith (name, "operator");}
开发者ID:Jactry,项目名称:binutils-gdb,代码行数:5,


示例15: list_x11_keymaps

static int list_x11_keymaps(DBusConnection *bus, char **args, unsigned n) {        _cleanup_fclose_ FILE *f = NULL;        _cleanup_strv_free_ char **list = NULL;        char line[LINE_MAX];        enum {                NONE,                MODELS,                LAYOUTS,                VARIANTS,                OPTIONS        } state = NONE, look_for;        int r;        if (n > 2) {                log_error("Too many arguments.");                return -EINVAL;        }        f = fopen("/usr/share/X11/xkb/rules/base.lst", "re");        if (!f) {                log_error("Failed to open keyboard mapping list. %m");                return -errno;        }        if (streq(args[0], "list-x11-keymap-models"))                look_for = MODELS;        else if (streq(args[0], "list-x11-keymap-layouts"))                look_for = LAYOUTS;        else if (streq(args[0], "list-x11-keymap-variants"))                look_for = VARIANTS;        else if (streq(args[0], "list-x11-keymap-options"))                look_for = OPTIONS;        else                assert_not_reached("Wrong parameter");        FOREACH_LINE(line, f, break) {                char *l, *w;                l = strstrip(line);                if (isempty(l))                        continue;                if (l[0] == '!') {                        if (startswith(l, "! model"))                                state = MODELS;                        else if (startswith(l, "! layout"))                                state = LAYOUTS;                        else if (startswith(l, "! variant"))                                state = VARIANTS;                        else if (startswith(l, "! option"))                                state = OPTIONS;                        else                                state = NONE;                        continue;                }                if (state != look_for)                        continue;                w = l + strcspn(l, WHITESPACE);                if (n > 1) {                        char *e;                        if (*w == 0)                                continue;                        *w = 0;                        w++;                        w += strspn(w, WHITESPACE);                        e = strchr(w, ':');                        if (!e)                                continue;                        *e = 0;                        if (!streq(w, args[1]))                                continue;                } else                        *w = 0;                 r = strv_extend(&list, l);                 if (r < 0)                         return log_oom();        }        if (strv_isempty(list)) {                log_error("Couldn't find any entries.");                return -ENOENT;        }        strv_sort(list);        strv_uniq(list);        pager_open_if_enabled();        strv_print(list);//.........这里部分代码省略.........
开发者ID:kwirk,项目名称:systemd,代码行数:101,


示例16: main

//.........这里部分代码省略.........        goto cleanup;    }    strv_uniq(arg_disks);    if (arg_read_crypttab) {        struct stat st;        f = fopen("/etc/crypttab", "re");        if (!f) {            if (errno == ENOENT)                r = EXIT_SUCCESS;            else                log_error("Failed to open /etc/crypttab: %m");            goto next;        }        if (fstat(fileno(f), &st) < 0) {            log_error("Failed to stat /etc/crypttab: %m");            goto next;        }        /* If we readd support for specifying passphrases         * directly in crypttabe we should upgrade the warning         * below, though possibly only if a passphrase is         * specified directly. */        if (st.st_mode & 0005)            log_debug("/etc/crypttab is world-readable. This is usually not a good idea.");        for (;;) {            char line[LINE_MAX], *l;            _cleanup_free_ char *name = NULL, *device = NULL, *password = NULL, *options = NULL;            int k;            if (!fgets(line, sizeof(line), f))                break;            n++;            l = strstrip(line);            if (*l == '#' || *l == 0)                continue;            k = sscanf(l, "%ms %ms %ms %ms", &name, &device, &password, &options);            if (k < 2 || k > 4) {                log_error("Failed to parse /etc/crypttab:%u, ignoring.", n);                continue;            }            /*              If options are specified on the kernel commandline, let them override              the ones from crypttab.            */            STRV_FOREACH(i, arg_options) {                _cleanup_free_ char *proc_uuid = NULL, *proc_options = NULL;                const char *p = *i;                k = sscanf(p, "%m[0-9a-fA-F-]=%ms", &proc_uuid, &proc_options);                if (k == 2 && streq(proc_uuid, device + 5)) {                    free(options);                    options = strdup(p);                    if (!proc_options) {                        log_oom();                        goto cleanup;                    }                }            }            if (arg_disks) {                /*                  If luks UUIDs are specified on the kernel command line, use them as a filter                  for /etc/crypttab and only generate units for those.                */                STRV_FOREACH(i, arg_disks) {                    _cleanup_free_ char *proc_device = NULL, *proc_name = NULL;                    const char *p = *i;                    if (startswith(p, "luks-"))                        p += 5;                    proc_name = strappend("luks-", p);                    proc_device = strappend("UUID=", p);                    if (!proc_name || !proc_device) {                        log_oom();                        goto cleanup;                    }                    if (streq(proc_device, device) || streq(proc_name, name)) {                        if (create_disk(name, device, password, options) < 0)                            goto cleanup;                        if (strv_extend(&disks_done, p) < 0) {                            log_oom();                            goto cleanup;                        }                    }                }            } else if (create_disk(name, device, password, options) < 0)
开发者ID:kyoiora,项目名称:systemd,代码行数:101,


示例17: handle_line_of_input

char *handle_line_of_input (struct buffer *cmd_line_buffer,		      char *rl, int repeat, char *annotation_suffix){  struct ui *ui = current_ui;  int from_tty = ui->instream == ui->stdin_stream;  char *p1;  char *cmd;  if (rl == NULL)    return (char *) EOF;  cmd = command_line_append_input_line (cmd_line_buffer, rl);  if (cmd == NULL)    return NULL;  /* We have a complete command line now.  Prepare for the next     command, but leave ownership of memory to the buffer .  */  cmd_line_buffer->used_size = 0;  if (from_tty && annotation_level > 1)    {      printf_unfiltered (("/n/032/032post-"));      puts_unfiltered (annotation_suffix);      printf_unfiltered (("/n"));    }#define SERVER_COMMAND_PREFIX "server "  if (startswith (cmd, SERVER_COMMAND_PREFIX))    {      /* Note that we don't set `saved_command_line'.  Between this         and the check in dont_repeat, this insures that repeating         will still do the right thing.  */      return cmd + strlen (SERVER_COMMAND_PREFIX);    }  /* Do history expansion if that is wished.  */  if (history_expansion_p && from_tty && input_interactive_p (current_ui))    {      char *history_value;      int expanded;      expanded = history_expand (cmd, &history_value);      if (expanded)	{	  size_t len;	  /* Print the changes.  */	  printf_unfiltered ("%s/n", history_value);	  /* If there was an error, call this function again.  */	  if (expanded < 0)	    {	      xfree (history_value);	      return cmd;	    }	  /* history_expand returns an allocated string.  Just replace	     our buffer with it.  */	  len = strlen (history_value);	  xfree (buffer_finish (cmd_line_buffer));	  cmd_line_buffer->buffer = history_value;	  cmd_line_buffer->buffer_size = len + 1;	  cmd = history_value;	}    }  /* If we just got an empty line, and that is supposed to repeat the     previous command, return the previously saved command.  */  for (p1 = cmd; *p1 == ' ' || *p1 == '/t'; p1++)    ;  if (repeat && *p1 == '/0')    return saved_command_line;  /* Add command to history if appropriate.  Note: lines consisting     solely of comments are also added to the command history.  This     is useful when you type a command, and then realize you don't     want to execute it quite yet.  You can comment out the command     and then later fetch it from the value history and remove the     '#'.  The kill ring is probably better, but some people are in     the habit of commenting things out.  */  if (*cmd != '/0' && from_tty && input_interactive_p (current_ui))    gdb_add_history (cmd);  /* Save into global buffer if appropriate.  */  if (repeat)    {      xfree (saved_command_line);      saved_command_line = xstrdup (cmd);      return saved_command_line;    }  else    return cmd;}
开发者ID:ibuclaw,项目名称:gdb,代码行数:94,


示例18: readdir_tarfs

static struct dirent * readdir_tarfs(fs_node_t *node, uint32_t index) {	if (index == 0) {		struct dirent * out = malloc(sizeof(struct dirent));		memset(out, 0x00, sizeof(struct dirent));		out->ino = 0;		strcpy(out->name, ".");		return out;	}	if (index == 1) {		struct dirent * out = malloc(sizeof(struct dirent));		memset(out, 0x00, sizeof(struct dirent));		out->ino = 0;		strcpy(out->name, "..");		return out;	}	index -= 2;	struct tarfs * self = node->device;	/* Go through each file and pick the ones are at the root */	/* Root files will have no /, so this is easy */	unsigned int offset = node->inode;	/* Read myself */	struct ustar * file = malloc(sizeof(struct ustar));	int status = ustar_from_offset(self, node->inode, file);	char my_filename[256];	/* Figure out my own filename, with forward slash */	memset(my_filename, 0, 256);	strncat(my_filename, file->prefix, 155);	strncat(my_filename, file->filename, 100);	while (offset < self->length) {		ustar_from_offset(self, offset, file);		if (!status) {			free(file);			return NULL;		}		char filename_workspace[256];		memset(filename_workspace, 0, 256);		strncat(filename_workspace, file->prefix, 155);		strncat(filename_workspace, file->filename, 100);		if (startswith(filename_workspace, my_filename)) {			if (!count_slashes(filename_workspace + strlen(my_filename))) {				if (strlen(filename_workspace + strlen(my_filename))) {					if (index == 0) {						char * slash = strstr(filename_workspace+strlen(my_filename),"/");						if (slash) *slash = '/0'; /* remove trailing slash */						struct dirent * out = malloc(sizeof(struct dirent));						memset(out, 0x00, sizeof(struct dirent));						out->ino = offset;						strcpy(out->name, filename_workspace+strlen(my_filename));						free(file);						return out;					} else {						index--;					}				}			}		}		offset += 512;		offset += round_to_512(interpret_size(file));	}	free(file);	return NULL;}
开发者ID:klange,项目名称:toaruos,代码行数:74,


示例19: resolve_defaultroute_one

//.........这里部分代码省略.........		/* Parse one route entry */		zero(&r_interface);		r_source[0] = r_gateway[0] = r_destination[0] = '/0';		struct rtattr *rtattr = (struct rtattr *) RTM_RTA(rtmsg);		int rtlen = RTM_PAYLOAD(nlmsg);		while (RTA_OK(rtattr, rtlen)) {			switch (rtattr->rta_type) {			case RTA_OIF:				if_indextoname(*(int *)RTA_DATA(rtattr),					r_interface);				break;			case RTA_PREFSRC:				inet_ntop(rtmsg->rtm_family, RTA_DATA(rtattr),					r_source, sizeof(r_source));				break;			case RTA_GATEWAY:				inet_ntop(rtmsg->rtm_family, RTA_DATA(rtattr),					r_gateway, sizeof(r_gateway));				break;			case RTA_DST:				inet_ntop(rtmsg->rtm_family, RTA_DATA(rtattr),					r_destination,					sizeof(r_destination));				break;			}			rtattr = RTA_NEXT(rtattr, rtlen);		}		/*		 * Ignore if not main table.		 * Ignore ipsecX or mastX interfaces.		 */		bool ignore = rtmsg->rtm_table != RT_TABLE_MAIN ||			startswith(r_interface, "ipsec") ||			startswith(r_interface, "mast");		if (verbose) {			printf("dst %s via %s dev %s src %s table %d%s/n",				r_destination,				r_gateway,				r_interface,				r_source, rtmsg->rtm_table,				ignore ? "" : " (ignored)");		}		if (ignore)			continue;		if (seeking_src && r_source[0] != '/0') {			err_t err = tnatoaddr(r_source, 0, rtmsg->rtm_family,					&host->addr);			if (err == NULL) {				host->addrtype = KH_IPADDR;				seeking_src = FALSE;				if (verbose)					printf("set addr: %s/n", r_source);			} else if (verbose) {				printf("unknown source results from kernel (%s): %s/n",					r_source, err);			}		}		if (seeking_gateway && r_destination[0] == '/0' &&			(has_dst || r_source[0] == '/0')) {			if (r_gateway[0] == '/0' && r_interface[0] != '/0') {				/*				 * Point-to-Point default gw without "via IP"				 * Attempt to find r_gateway as the IP address				 * on the interface.				 */				resolve_ppp_peer(r_interface, host->addr_family,						 r_gateway);			}			if (r_gateway[0] != '/0') {				err_t err = tnatoaddr(r_gateway, 0,						rtmsg->rtm_family,						&host->nexthop);				if (err != NULL) {					printf("unknown gateway results from kernel: %s/n",						err);				} else {					/* Note: Use first even if multiple */					host->nexttype = KH_IPADDR;					seeking_gateway = FALSE;					if (verbose)						printf("set nexthop: %s/n",							r_gateway);				}			}		}	}	return query_again;}
开发者ID:NetworkManager,项目名称:libreswan,代码行数:101,


示例20: locale_message_handler

static DBusHandlerResult locale_message_handler(                DBusConnection *connection,                DBusMessage *message,                void *userdata) {        DBusMessage *reply = NULL, *changed = NULL;        DBusError error;        int r;        assert(connection);        assert(message);        dbus_error_init(&error);        if (dbus_message_is_method_call(message, "org.freedesktop.locale1", "SetLocale")) {                char **l = NULL, **i;                dbus_bool_t interactive;                DBusMessageIter iter;                bool modified = false;                bool passed[_PROP_MAX];                int p;                if (!dbus_message_iter_init(message, &iter))                        return bus_send_error_reply(connection, message, NULL, -EINVAL);                r = bus_parse_strv_iter(&iter, &l);                if (r < 0) {                        if (r == -ENOMEM)                                goto oom;                        return bus_send_error_reply(connection, message, NULL, r);                }                if (!dbus_message_iter_next(&iter) ||                    dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN)  {                        strv_free(l);                        return bus_send_error_reply(connection, message, NULL, -EINVAL);                }                dbus_message_iter_get_basic(&iter, &interactive);                zero(passed);                /* Check whether a variable changed and if so valid */                STRV_FOREACH(i, l) {                        bool valid = false;                        for (p = 0; p < _PROP_MAX; p++) {                                size_t k;                                k = strlen(names[p]);                                if (startswith(*i, names[p]) &&                                    (*i)[k] == '=' &&                                    string_is_safe((*i) + k + 1)) {                                        valid = true;                                        passed[p] = true;                                        if (!streq_ptr(*i + k + 1, data[p]))                                                modified = true;                                        break;                                }                        }                        if (!valid) {                                strv_free(l);                                return bus_send_error_reply(connection, message, NULL, -EINVAL);                        }                }
开发者ID:RoadRunnr,项目名称:systemd,代码行数:69,


示例21: _nss_myhostname_gethostbyname3_r

enum nss_status _nss_myhostname_gethostbyname3_r(                const char *name,                int af,                struct hostent *host,                char *buffer, size_t buflen,                int *errnop, int *h_errnop,                int32_t *ttlp,                char **canonp) {        _cleanup_free_ struct local_address *addresses = NULL;        const char *canonical, *additional = NULL;        _cleanup_free_ char *hn = NULL;        uint32_t local_address_ipv4 = 0;        int n_addresses = 0;        PROTECT_ERRNO;        BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);        assert(name);        assert(host);        assert(buffer);        assert(errnop);        assert(h_errnop);        if (af == AF_UNSPEC)                af = AF_INET;        if (!IN_SET(af, AF_INET, AF_INET6)) {                *errnop = EAFNOSUPPORT;                *h_errnop = NO_DATA;                return NSS_STATUS_UNAVAIL;        }        if (is_localhost(name)) {                canonical = "localhost";                local_address_ipv4 = htobe32(INADDR_LOOPBACK);        } else if (is_gateway_hostname(name)) {                n_addresses = local_gateways(NULL, 0, af, &addresses);                if (n_addresses <= 0) {                        *h_errnop = HOST_NOT_FOUND;                        return NSS_STATUS_NOTFOUND;                }                canonical = "_gateway";        } else {                hn = gethostname_malloc();                if (!hn) {                        *errnop = ENOMEM;                        *h_errnop = NO_RECOVERY;                        return NSS_STATUS_TRYAGAIN;                }                if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) {                        *h_errnop = HOST_NOT_FOUND;                        return NSS_STATUS_NOTFOUND;                }                n_addresses = local_addresses(NULL, 0, af, &addresses);                if (n_addresses < 0)                        n_addresses = 0;                canonical = hn;                additional = n_addresses <= 0 && af == AF_INET6 ? "localhost" : NULL;                local_address_ipv4 = LOCALADDRESS_IPV4;        }        return fill_in_hostent(                        canonical, additional,                        af,                        addresses, n_addresses,                        local_address_ipv4,                        host,                        buffer, buflen,                        errnop, h_errnop,                        ttlp,                        canonp);}
开发者ID:Keruspe,项目名称:systemd,代码行数:80,


示例22: start_website

const char* start_website( int fd, char* url, char* ip ) {    static char error_msg[64] = "";    website_t* website;    website_data_t* website_data;    if ( ( website = website_get_by_full_url( url, ip ) ) )        return "FAIL website already exists";    int exlisnfd = zsocket( inet_addr( ip ), get_port_from_url( url ), ZSOCK_LISTEN, exsock_event_hdlr, startswith( url, "https://" ) );    if ( exlisnfd == -1 ) {        sprintf( error_msg, "FAIL error opening external socket: %s, %s", ip, strerror( errno ) );        return error_msg;    }    website = website_add( fd, url, ip );    syslog( LOG_INFO, "website: starting /"%s/" on /"%s/"", website->full_url, website->ip );    website_data = (website_data_t*) malloc( sizeof( website_data_t ) );    website->udata = website_data;    website_data->exlisnfd = exlisnfd;    zs_set_read( website_data->exlisnfd );    return "OK";}
开发者ID:ianhalpern,项目名称:zimr,代码行数:26,


示例23: bus_creds_add_more

int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {        uint64_t missing;        int r;        assert(c);        assert(c->allocated);        missing = mask & ~c->mask;        if (missing == 0)                return 0;        /* Try to retrieve PID from creds if it wasn't passed to us */        if (pid <= 0 && (c->mask & SD_BUS_CREDS_PID))                pid = c->pid;        if (tid <= 0 && (c->mask & SD_BUS_CREDS_TID))                tid = c->pid;        /* Without pid we cannot do much... */        if (pid <= 0)                return 0;        if (missing & (SD_BUS_CREDS_UID | SD_BUS_CREDS_GID |                       SD_BUS_CREDS_EFFECTIVE_CAPS | SD_BUS_CREDS_INHERITABLE_CAPS |                       SD_BUS_CREDS_PERMITTED_CAPS | SD_BUS_CREDS_BOUNDING_CAPS)) {                _cleanup_fclose_ FILE *f = NULL;                char line[LINE_MAX];                const char *p;                p = procfs_file_alloca(pid, "status");                f = fopen(p, "re");                if (!f)                        return errno == ENOENT ? -ESRCH : -errno;                FOREACH_LINE(line, f, return -errno) {                        truncate_nl(line);                        if (missing & SD_BUS_CREDS_UID) {                                p = startswith(line, "Uid:");                                if (p) {                                        unsigned long uid;                                        p += strspn(p, WHITESPACE);                                        if (sscanf(p, "%lu", &uid) != 1)                                                return -EIO;                                        c->uid = (uid_t) uid;                                        c->mask |= SD_BUS_CREDS_UID;                                        continue;                                }                        }                        if (missing & SD_BUS_CREDS_GID) {                                p = startswith(line, "Gid:");                                if (p) {                                        unsigned long gid;                                        p += strspn(p, WHITESPACE);                                        if (sscanf(p, "%lu", &gid) != 1)                                                return -EIO;                                        c->gid = (uid_t) gid;                                        c->mask |= SD_BUS_CREDS_GID;                                        continue;                                }                        }                        if (missing & SD_BUS_CREDS_EFFECTIVE_CAPS) {                                p = startswith(line, "CapEff:");                                if (p) {                                        r = parse_caps(c, CAP_OFFSET_EFFECTIVE, p);                                        if (r < 0)                                                return r;                                        c->mask |= SD_BUS_CREDS_EFFECTIVE_CAPS;                                        continue;                                }                        }                        if (missing & SD_BUS_CREDS_PERMITTED_CAPS) {                                p = startswith(line, "CapPrm:");                                if (p) {                                        r = parse_caps(c, CAP_OFFSET_PERMITTED, p);                                        if (r < 0)                                                return r;                                        c->mask |= SD_BUS_CREDS_PERMITTED_CAPS;                                        continue;                                }                        }                        if (missing & SD_BUS_CREDS_INHERITABLE_CAPS) {                                p = startswith(line, "CapInh:");                                if (p) {                                        r = parse_caps(c, CAP_OFFSET_INHERITABLE, p);                                        if (r < 0)                                                return r;//.........这里部分代码省略.........
开发者ID:jaanek,项目名称:systemd,代码行数:101,


示例24: exread

void exread( int sockfd ) {    void* ptr;    conn_data_t* conn_data = connections[ sockfd ];    if ( !conn_data->buffer ) {        conn_data->buffer = malloc(PACK_DATA_SIZE);        conn_data->bufferlen = 0;        memset( conn_data->buffer, 0, PACK_DATA_SIZE );    }    website_t* website;    ssize_t len = zs_read( sockfd, conn_data->buffer + conn_data->bufferlen, PACK_DATA_SIZE - conn_data->bufferlen );    // TODO: wait for entire header before looking up website    if ( len <= 0 ) {cleanup:        // cleanup        cleanup_connection( sockfd );        return;    }    if ( conn_data->postlen == -1 ) /* if we have received all the data already, ignore */        return;    conn_data->bufferlen += len;    //printf( "%d: read %zu/n", sockfd, len );    ptr = conn_data->buffer;    if ( conn_data->website_sockfd == -1 ) {        /* If req_info is NULL this is the start of a request and the           HTTP request headers need to be parsed. */        struct hostent* hp;        hp = NULL;//gethostbyaddr( (char*) &conn_data->addr, sizeof( conn_data->addr ), AF_INET );        char* endofhdrs;        if ( !( endofhdrs = strnstr( conn_data->buffer, HTTP_HDR_ENDL HTTP_HDR_ENDL, PACK_DATA_SIZE ) ) ) {            if ( conn_data->bufferlen == PACK_DATA_SIZE ) {                /* If the end of the headers was not found the request was either                   malformatted or too long, DO NOT send to website. */                zs_write( sockfd, html_error_414, sizeof( html_error_414 ) );                syslog( LOG_WARNING, "exread: headers to long" );                goto cleanup;            }            // Have not received the full header yet, wait            zs_set_read( sockfd );            return;        }        endofhdrs += sizeof( HTTP_HDR_ENDL HTTP_HDR_ENDL ) - 1;        /* Get HTTP request type */        if ( startswith( conn_data->buffer, HTTP_GET ) )            conn_data->request_type = HTTP_GET_TYPE;        else if ( startswith( conn_data->buffer, HTTP_POST ) )            conn_data->request_type = HTTP_POST_TYPE;        else {            zs_write( sockfd, html_error_400, sizeof( html_error_400 ) );            goto cleanup;        }        /* Find website for request from HTTP header */        char urlbuf[ PACK_DATA_SIZE ];        if ( !get_url_from_http_header( conn_data->buffer, urlbuf, sizeof( urlbuf ) ) ) {            //syslog( LOG_WARNING, "exread: no url found in http request headers: %s %s",            //  inet_ntoa( conn_data->addr.sin_addr ), hp ? hp->h_name : "" );            zs_write( sockfd, html_error_400, sizeof( html_error_400 ) );            goto cleanup;        }        if ( !( website = website_find( urlbuf, conn_data->is_https ? "https://" : "http://",                                        inet_ntoa( zs_get_addr( conn_data->exlisnfd )->sin_addr ) ) ) ) {            //syslog( LOG_WARNING, "exread: no website to service request: %s %s %s",            //  inet_ntoa( conn_data->addr.sin_addr ), hp ? hp->h_name : "", urlbuf );            zs_write( sockfd, html_error_404, sizeof( html_error_404 ) );            goto cleanup;        }        /* Set the website id so that furthur sections of this           request can check if the website is still alive. */        conn_data->website_sockfd = website->sockfd;        /* Check the websites socket to make sure the request came in on           the right socket. */        website_data_t* website_data = website->udata;        if ( website_data->exlisnfd != conn_data->exlisnfd ) {            //syslog( LOG_WARNING, "exread: no website to service request: %s %s %s",            //  inet_ntoa( conn_data->addr.sin_addr ), hp ? hp->h_name : "", urlbuf );            zs_write( sockfd, html_error_404, sizeof( html_error_404 ) );            goto cleanup;        }        //printf( "%s/n", buffer );        /* Create a new message to send the request to the corresponding           website. The msgid should be set to the external file descriptor           to send the response back to. */        conn_data->msgid = msg_open( website->sockfd, sockfd );        zs_set_write( sockfd );        // If request_type is POST check if there is content after the HTTP header//.........这里部分代码省略.........
开发者ID:ianhalpern,项目名称:zimr,代码行数:101,


示例25: pull_find_old_etags

int pull_find_old_etags(                const char *url,                const char *image_root,                int dt,                const char *prefix,                const char *suffix,                char ***etags) {        _cleanup_free_ char *escaped_url = NULL;        _cleanup_closedir_ DIR *d = NULL;        _cleanup_strv_free_ char **l = NULL;        struct dirent *de;        int r;        assert(url);        assert(etags);        if (!image_root)                image_root = "/var/lib/machines";        escaped_url = xescape(url, FILENAME_ESCAPE);        if (!escaped_url)                return -ENOMEM;        d = opendir(image_root);        if (!d) {                if (errno == ENOENT) {                        *etags = NULL;                        return 0;                }                return -errno;        }        FOREACH_DIRENT_ALL(de, d, return -errno) {                const char *a, *b;                char *u;                if (de->d_type != DT_UNKNOWN &&                    de->d_type != dt)                        continue;                if (prefix) {                        a = startswith(de->d_name, prefix);                        if (!a)                                continue;                } else                        a = de->d_name;                a = startswith(a, escaped_url);                if (!a)                        continue;                a = startswith(a, ".");                if (!a)                        continue;                if (suffix) {                        b = endswith(de->d_name, suffix);                        if (!b)                                continue;                } else                        b = strchr(de->d_name, 0);                if (a >= b)                        continue;                r = cunescape_length(a, b - a, 0, &u);                if (r < 0)                        return r;                if (!http_etag_is_valid(u)) {                        free(u);                        continue;                }                r = strv_consume(&l, u);                if (r < 0)                        return r;        }        *etags = l;        l = NULL;        return 0;}
开发者ID:josephgbr,项目名称:systemd,代码行数:86,


示例26: proc_cmdline_get_key

int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {        _cleanup_free_ char *line = NULL, *ret = NULL;        bool found = false;        const char *p;        int r;        /* Looks for a specific key on the kernel command line. Supports two modes:         *         * a) The "value" parameter is used. In this case a parameter beginning with the "key" string followed by "="         *    is searched, and the value following this is returned in "value".         *         * b) as above, but the PROC_CMDLINE_VALUE_OPTIONAL flag is set. In this case if the key is found as a         *    separate word (i.e. not followed by "=" but instead by whitespace or the end of the command line), then         *    this is also accepted, and "value" is returned as NULL.         *         * c) The "value" parameter is NULL. In this case a search for the exact "key" parameter is performed.         *         * In all three cases, > 0 is returned if the key is found, 0 if not. */        if (isempty(key))                return -EINVAL;        if ((flags & PROC_CMDLINE_VALUE_OPTIONAL) && !value)                return -EINVAL;        r = proc_cmdline(&line);        if (r < 0)                return r;        p = line;        for (;;) {                _cleanup_free_ char *word = NULL;                const char *e;                r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX);                if (r < 0)                        return r;                if (r == 0)                        break;                /* Automatically filter out arguments that are intended only for the initrd, if we are not in the                 * initrd. */                if (!in_initrd() && startswith(word, "rd."))                        continue;                if (value) {                        e = proc_cmdline_key_startswith(word, key);                        if (!e)                                continue;                        if (*e == '=') {                                r = free_and_strdup(&ret, e+1);                                if (r < 0)                                        return r;                                found = true;                        } else if (*e == 0 && (flags & PROC_CMDLINE_VALUE_OPTIONAL))                                found = true;                } else {                        if (streq(word, key))                                found = true;                }        }        if (value)                *value = TAKE_PTR(ret);        return found;}
开发者ID:Hariprasathganesh,项目名称:testsysd,代码行数:71,


示例27: adm_builtin

static int adm_builtin(struct udev *udev, int argc, char *argv[]){        static const struct option options[] = {                { "help", no_argument, NULL, 'h' },                {}        };        char *command = NULL;        char *syspath = NULL;        char filename[UTIL_PATH_SIZE];        struct udev_device *dev = NULL;        enum udev_builtin_cmd cmd;        int rc = EXIT_SUCCESS, c;        while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)                switch (c) {                case 'h':                        help(udev);                        goto out;                }        command = argv[optind++];        if (command == NULL) {                fprintf(stderr, "command missing/n");                help(udev);                rc = 2;                goto out;        }        syspath = argv[optind++];        if (syspath == NULL) {                fprintf(stderr, "syspath missing/n");                rc = 3;                goto out;        }        udev_builtin_init(udev);        cmd = udev_builtin_lookup(command);        if (cmd >= UDEV_BUILTIN_MAX) {                fprintf(stderr, "unknown command '%s'/n", command);                help(udev);                rc = 5;                goto out;        }        /* add /sys if needed */        if (!startswith(syspath, "/sys"))                strscpyl(filename, sizeof(filename), "/sys", syspath, NULL);        else                strscpy(filename, sizeof(filename), syspath);        util_remove_trailing_chars(filename, '/');        dev = udev_device_new_from_syspath(udev, filename);        if (dev == NULL) {                fprintf(stderr, "unable to open device '%s'/n/n", filename);                rc = 4;                goto out;        }        rc = udev_builtin_run(dev, cmd, command, true);        if (rc < 0) {                fprintf(stderr, "error executing '%s', exit code %i/n/n", command, rc);                rc = 6;        }out:        udev_device_unref(dev);        udev_builtin_exit(udev);        return rc;}
开发者ID:daks-ua,项目名称:eudev,代码行数:69,


示例28: parse_proc_cmdline

static int parse_proc_cmdline(char ***arg_proc_cmdline_disks, char ***arg_proc_cmdline_options, char **arg_proc_cmdline_keyfile) {        _cleanup_free_ char *line = NULL;        char *w = NULL, *state = NULL;        int r;        size_t l;        if (detect_container(NULL) > 0)                return 0;        r = read_one_line_file("/proc/cmdline", &line);        if (r < 0) {                log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));                return 0;        }        FOREACH_WORD_QUOTED(w, l, line, state) {                _cleanup_free_ char *word = NULL;                word = strndup(w, l);                if (!word)                        return log_oom();                if (startswith(word, "luks=")) {                        r = parse_boolean(word + 5);                        if (r < 0)                                log_warning("Failed to parse luks switch %s. Ignoring.", word + 5);                        else                                arg_enabled = r;                } else if (startswith(word, "rd.luks=")) {                        if (in_initrd()) {                                r = parse_boolean(word + 8);                                if (r < 0)                                        log_warning("Failed to parse luks switch %s. Ignoring.", word + 8);                                else                                        arg_enabled = r;                        }                } else if (startswith(word, "luks.crypttab=")) {                        r = parse_boolean(word + 14);                        if (r < 0)                                log_warning("Failed to parse luks crypttab switch %s. Ignoring.", word + 14);                        else                                arg_read_crypttab = r;                } else if (startswith(word, "rd.luks.crypttab=")) {                        if (in_initrd()) {                                r = parse_boolean(word + 17);                                if (r < 0)                                        log_warning("Failed to parse luks crypttab switch %s. Ignoring.", word + 17);                                else                                        arg_read_crypttab = r;                        }                } else if (startswith(word, "luks.uuid=")) {                        if (strv_extend(arg_proc_cmdline_disks, word + 10) < 0)                                return log_oom();                } else if (startswith(word, "rd.luks.uuid=")) {                        if (in_initrd()) {                                if (strv_extend(arg_proc_cmdline_disks, word + 13) < 0)                                        return log_oom();                        }                } else if (startswith(word, "luks.options=")) {                        if (strv_extend(arg_proc_cmdline_options, word + 13) < 0)                                return log_oom();                } else if (startswith(word, "rd.luks.options=")) {                        if (in_initrd()) {                                if (strv_extend(arg_proc_cmdline_options, word + 16) < 0)                                        return log_oom();                        }                } else if (startswith(word, "luks.key=")) {                        if (*arg_proc_cmdline_keyfile)                                free(*arg_proc_cmdline_keyfile);                        *arg_proc_cmdline_keyfile = strdup(word + 9);                        if (!*arg_proc_cmdline_keyfile)                                return log_oom();                } else if (startswith(word, "rd.luks.key=")) {                        if (in_initrd()) {                                if (*arg_proc_cmdline_keyfile)                                        free(*arg_proc_cmdline_keyfile);                                *arg_proc_cmdline_keyfile = strdup(word + 12);                                if (!*arg_proc_cmdline_keyfile)                                        return log_oom();                        }                } else if (startswith(word, "luks.") ||                           (in_initrd() && startswith(word, "rd.luks."))) {                        log_warning("Unknown kernel switch %s. Ignoring.", word);                }//.........这里部分代码省略.........
开发者ID:prodigeni,项目名称:systemd,代码行数:101,


示例29: parse_nsec

int parse_nsec(const char *t, nsec_t *nsec) {        static const struct {                const char *suffix;                nsec_t nsec;        } table[] = {                { "seconds", NSEC_PER_SEC },                { "second", NSEC_PER_SEC },                { "sec", NSEC_PER_SEC },                { "s", NSEC_PER_SEC },                { "minutes", NSEC_PER_MINUTE },                { "minute", NSEC_PER_MINUTE },                { "min", NSEC_PER_MINUTE },                { "months", NSEC_PER_MONTH },                { "month", NSEC_PER_MONTH },                { "msec", NSEC_PER_MSEC },                { "ms", NSEC_PER_MSEC },                { "m", NSEC_PER_MINUTE },                { "hours", NSEC_PER_HOUR },                { "hour", NSEC_PER_HOUR },                { "hr", NSEC_PER_HOUR },                { "h", NSEC_PER_HOUR },                { "days", NSEC_PER_DAY },                { "day", NSEC_PER_DAY },                { "d", NSEC_PER_DAY },                { "weeks", NSEC_PER_WEEK },                { "week", NSEC_PER_WEEK },                { "w", NSEC_PER_WEEK },                { "years", NSEC_PER_YEAR },                { "year", NSEC_PER_YEAR },                { "y", NSEC_PER_YEAR },                { "usec", NSEC_PER_USEC },                { "us", NSEC_PER_USEC },                { "nsec", 1ULL },                { "ns", 1ULL },                { "", 1ULL }, /* default is nsec */        };        const char *p, *s;        nsec_t r = 0;        bool something = false;        assert(t);        assert(nsec);        p = t;        p += strspn(p, WHITESPACE);        s = startswith(p, "infinity");        if (s) {                s += strspn(s, WHITESPACE);                if (*s != 0)                        return -EINVAL;                *nsec = NSEC_INFINITY;                return 0;        }        for (;;) {                long long l, z = 0;                char *e;                unsigned i, n = 0;                p += strspn(p, WHITESPACE);                if (*p == 0) {                        if (!something)                                return -EINVAL;                        break;                }                errno = 0;                l = strtoll(p, &e, 10);                if (errno > 0)                        return -errno;                if (l < 0)                        return -ERANGE;                if (*e == '.') {                        char *b = e + 1;                        errno = 0;                        z = strtoll(b, &e, 10);                        if (errno > 0)                                return -errno;                        if (z < 0)                                return -ERANGE;                        if (e == b)                                return -EINVAL;                        n = e - b;                } else if (e == p)                        return -EINVAL;                e += strspn(e, WHITESPACE);//.........这里部分代码省略.........
开发者ID:atulhjp,项目名称:NetworkManager,代码行数:101,


示例30: gnuv3_rtti_type

static struct type *gnuv3_rtti_type (struct value *value,                 int *full_p, int *top_p, int *using_enc_p){  struct gdbarch *gdbarch;  struct type *values_type = check_typedef (value_type (value));  struct value *vtable;  struct minimal_symbol *vtable_symbol;  const char *vtable_symbol_name;  const char *class_name;  struct type *run_time_type;  LONGEST offset_to_top;  char *atsign;  /* We only have RTTI for class objects.  */  if (TYPE_CODE (values_type) != TYPE_CODE_STRUCT)    return NULL;  /* Java doesn't have RTTI following the C++ ABI.  */  if (TYPE_CPLUS_REALLY_JAVA (values_type))    return NULL;  /* Determine architecture.  */  gdbarch = get_type_arch (values_type);  if (using_enc_p)    *using_enc_p = 0;  vtable = gnuv3_get_vtable (gdbarch, values_type,			     value_as_address (value_addr (value)));  if (vtable == NULL)    return NULL;  /* Find the linker symbol for this vtable.  */  vtable_symbol    = lookup_minimal_symbol_by_pc (value_address (vtable)                                   + value_embedded_offset (vtable)).minsym;  if (! vtable_symbol)    return NULL;    /* The symbol's demangled name should be something like "vtable for     CLASS", where CLASS is the name of the run-time type of VALUE.     If we didn't like this approach, we could instead look in the     type_info object itself to get the class name.  But this way     should work just as well, and doesn't read target memory.  */  vtable_symbol_name = MSYMBOL_DEMANGLED_NAME (vtable_symbol);  if (vtable_symbol_name == NULL      || !startswith (vtable_symbol_name, "vtable for "))    {      warning (_("can't find linker symbol for virtual table for `%s' value"),	       TYPE_SAFE_NAME (values_type));      if (vtable_symbol_name)	warning (_("  found `%s' instead"), vtable_symbol_name);      return NULL;    }  class_name = vtable_symbol_name + 11;  /* Strip off @plt and version suffixes.  */  atsign = strchr (class_name, '@');  if (atsign != NULL)    {      char *copy;      copy = alloca (atsign - class_name + 1);      memcpy (copy, class_name, atsign - class_name);      copy[atsign - class_name] = '/0';      class_name = copy;    }  /* Try to look up the class name as a type name.  */  /* FIXME: chastain/2003-11-26: block=NULL is bogus.  See pr gdb/1465.  */  run_time_type = cp_lookup_rtti_type (class_name, NULL);  if (run_time_type == NULL)    return NULL;  /* Get the offset from VALUE to the top of the complete object.     NOTE: this is the reverse of the meaning of *TOP_P.  */  offset_to_top    = value_as_long (value_field (vtable, vtable_field_offset_to_top));  if (full_p)    *full_p = (- offset_to_top == value_embedded_offset (value)               && (TYPE_LENGTH (value_enclosing_type (value))                   >= TYPE_LENGTH (run_time_type)));  if (top_p)    *top_p = - offset_to_top;  return run_time_type;}
开发者ID:Jactry,项目名称:binutils-gdb,代码行数:88,



注:本文中的startswith函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ startup函数代码示例
C++ starts_with函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。