这篇教程C++ stpcpy函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中stpcpy函数的典型用法代码示例。如果您正苦于以下问题:C++ stpcpy函数的具体用法?C++ stpcpy怎么用?C++ stpcpy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了stpcpy函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: assert/** RFC-2047 encode string with given charset. Only the Q encoding * (quoted-printable) supported at this time. * WARNING: this code returns a static buffer! */char *rfc2047e(const char *string, const char *charset) { static char *out; char *t; const char *r; int count, minlen, idx, i; char **words = NULL; size_t l; assert(strlen(charset) < 40); if (out) { free(out); out = NULL; } /* phase 1: split original into words */ /* 1a: count, 1b: copy */ count = 0; r = string; while (*r) { count++; r += strcspn(r, ws); if (!*r) break; count++; r += strspn(r, ws); } words = (char **)xmalloc(sizeof(char *) * (count + 1)); idx = 0; r = string; while (*r) { l = strcspn(r, ws); words[idx] = (char *)xmalloc(l+1); memcpy(words[idx], r, l); words[idx][l] = '/0'; idx++; r += l; if (!*r) break; l = strspn(r, ws); words[idx] = (char *)xmalloc(l+1); memcpy(words[idx], r, l); words[idx][l] = '/0'; idx++; r += l; } /* phase 2: encode words */ /* a: find ranges of adjacent words to need encoding */ /* b: encode ranges */ idx = 0; while (idx < count) { int end; char *tmp; if (!needs_enc(words[idx])) { idx += 2; continue; } for (end = idx + 2; end < count; end += 2) { if (!needs_enc(words[end])) break; } end -= 2; tmp = encode_words(&words[idx], end - idx + 1, charset); free(words[idx]); words[idx] = tmp; for (i = idx + 1; i <= end; i++) words[i][0] = '/0'; idx = end + 2; } l = 0; for (idx = 0; idx < count; idx++) { l += strlen(words[idx]); } /* phase 3: limit lengths */ minlen = strlen(charset) + 7; /* allocate ample memory */ out = (char *)xmalloc(l + (l / (72 - minlen) + 1) * (minlen + 2) + 1); if (count) t = stpcpy(out, words[0]); else t = out, *out = 0; l = strlen(out); for (i = 1; i < count; i+=2) { size_t m; char *tmp; m = strlen(words[i]); if (i + 1 < count) m += strcspn(words[i+1], "/r/n"); if (l + m > 74) t = stpcpy(t, "/r/n");//.........这里部分代码省略.........
开发者ID:aosm,项目名称:fetchmail,代码行数:101,
示例2: modify_description/* Modify a Key description, replacing certain special format characters. List of currently supported replacements: %% - Replaced by a single % %c - Replaced by the content of COMMENT. %F - Replaced by an ssh style fingerprint computed from KEY. The functions returns 0 on success or an error code. On success a newly allocated string is stored at the address of RESULT. */static gpg_error_tmodify_description (const char *in, const char *comment, const gcry_sexp_t key, char **result){ size_t comment_length; size_t in_len; size_t out_len; char *out; size_t i; int special, pass; char *ssh_fpr = NULL; comment_length = strlen (comment); in_len = strlen (in); /* First pass calculates the length, second pass does the actual copying. */ out = NULL; out_len = 0; for (pass=0; pass < 2; pass++) { special = 0; for (i = 0; i < in_len; i++) { if (special) { special = 0; switch (in[i]) { case '%': if (out) *out++ = '%'; else out_len++; break; case 'c': /* Comment. */ if (out) { memcpy (out, comment, comment_length); out += comment_length; } else out_len += comment_length; break; case 'F': /* SSH style fingerprint. */ if (!ssh_fpr && key) ssh_get_fingerprint_string (key, &ssh_fpr); if (ssh_fpr) { if (out) out = stpcpy (out, ssh_fpr); else out_len += strlen (ssh_fpr); } break; default: /* Invalid special sequences are kept as they are. */ if (out) { *out++ = '%'; *out++ = in[i]; } else out_len+=2; break; } } else if (in[i] == '%') special = 1; else { if (out) *out++ = in[i]; else out_len++; } } if (!pass) { *result = out = xtrymalloc (out_len + 1); if (!out) { xfree (ssh_fpr); return gpg_error_from_syserror (); } } }//.........这里部分代码省略.........
开发者ID:wertarbyte,项目名称:gnupg,代码行数:101,
示例3: xheader_format_namechar *xheader_format_name (struct tar_stat_info *st, const char *fmt, size_t n){ char *buf; size_t len = strlen (fmt); char *q; const char *p; char *dirp = NULL; char *dir = NULL; char *base = NULL; char pidbuf[UINTMAX_STRSIZE_BOUND]; char const *pptr = NULL; char nbuf[UINTMAX_STRSIZE_BOUND]; char const *nptr = NULL; for (p = fmt; *p && (p = strchr (p, '%')); ) { switch (p[1]) { case '%': len--; break; case 'd': if (st) { if (!dirp) dirp = dir_name (st->orig_file_name); dir = safer_name_suffix (dirp, false, absolute_names_option); len += strlen (dir) - 2; } break; case 'f': if (st) { base = last_component (st->orig_file_name); len += strlen (base) - 2; } break; case 'p': pptr = umaxtostr (getpid (), pidbuf); len += pidbuf + sizeof pidbuf - 1 - pptr - 2; break; case 'n': nptr = umaxtostr (n, nbuf); len += nbuf + sizeof nbuf - 1 - nptr - 2; break; } p++; } buf = xmalloc (len + 1); for (q = buf, p = fmt; *p; ) { if (*p == '%') { switch (p[1]) { case '%': *q++ = *p++; p++; break; case 'd': if (dir) q = stpcpy (q, dir); p += 2; break; case 'f': if (base) q = stpcpy (q, base); p += 2; break; case 'p': q = stpcpy (q, pptr); p += 2; break; case 'n': q = stpcpy (q, nptr); p += 2; break; default: *q++ = *p++; if (*p) *q++ = *p++; } } else *q++ = *p++; } free (dirp);//.........这里部分代码省略.........
开发者ID:GrayKing,项目名称:LeakFix-on-Tar,代码行数:101,
示例4: uiserver_signstatic gpgme_error_tuiserver_sign (void *engine, gpgme_data_t in, gpgme_data_t out, gpgme_sig_mode_t mode, int use_armor, int use_textmode, int include_certs, gpgme_ctx_t ctx /* FIXME */){ engine_uiserver_t uiserver = engine; gpgme_error_t err = 0; const char *protocol; char *cmd; gpgme_key_t key; if (!uiserver || !in || !out) return gpg_error (GPG_ERR_INV_VALUE); if (uiserver->protocol == GPGME_PROTOCOL_DEFAULT) protocol = ""; else if (uiserver->protocol == GPGME_PROTOCOL_OpenPGP) protocol = " --protocol=OpenPGP"; else if (uiserver->protocol == GPGME_PROTOCOL_CMS) protocol = " --protocol=CMS"; else return gpgme_error (GPG_ERR_UNSUPPORTED_PROTOCOL); if (asprintf (&cmd, "SIGN%s%s", protocol, (mode == GPGME_SIG_MODE_DETACH) ? " --detached" : "") < 0) return gpg_error_from_errno (errno); key = gpgme_signers_enum (ctx, 0); if (key) { const char *s = NULL; if (key && key->uids) s = key->uids->email; if (s && strlen (s) < 80) { char buf[100]; strcpy (stpcpy (buf, "SENDER --info "), s); err = uiserver_assuan_simple_command (uiserver->assuan_ctx, buf, uiserver->status.fnc, uiserver->status.fnc_value); } else err = gpg_error (GPG_ERR_INV_VALUE); gpgme_key_unref (key); if (err) { free (cmd); return err; } } uiserver->input_cb.data = in; err = uiserver_set_fd (uiserver, INPUT_FD, map_data_enc (uiserver->input_cb.data)); if (err) { free (cmd); return err; } uiserver->output_cb.data = out; err = uiserver_set_fd (uiserver, OUTPUT_FD, use_armor ? "--armor" : map_data_enc (uiserver->output_cb.data)); if (err) { free (cmd); return err; } uiserver->inline_data = NULL; err = start (uiserver, cmd); free (cmd); return err;}
开发者ID:bilalnurhusien,项目名称:gpgme,代码行数:75,
示例5: nis_print_group_entryvoidnis_print_group_entry (const_nis_name group){ if (group != NULL && group[0] != '/0') { size_t grouplen = strlen (group); char buf[grouplen + 50]; char leafbuf[grouplen + 3]; char domainbuf[grouplen + 3]; nis_result *res; char *cp, *cp2; u_int i; cp = stpcpy (buf, nis_leaf_of_r (group, leafbuf, sizeof (leafbuf) - 1)); cp = stpcpy (cp, ".groups_dir"); cp2 = nis_domain_of_r (group, domainbuf, sizeof (domainbuf) - 1); if (cp2 != NULL && cp2[0] != '/0') { *cp++ = '.'; stpcpy (cp, cp2); } res = nis_lookup (buf, FOLLOW_LINKS | EXPAND_NAME); if (res == NULL) return; if (NIS_RES_STATUS (res) != NIS_SUCCESS || NIS_RES_NUMOBJ (res) != 1 || __type_of (NIS_RES_OBJECT (res)) != NIS_GROUP_OBJ) { nis_freeresult (res); return; } char *mem_exp[NIS_RES_NUMOBJ (res)]; char *mem_imp[NIS_RES_NUMOBJ (res)]; char *mem_rec[NIS_RES_NUMOBJ (res)]; char *nomem_exp[NIS_RES_NUMOBJ (res)]; char *nomem_imp[NIS_RES_NUMOBJ (res)]; char *nomem_rec[NIS_RES_NUMOBJ (res)]; unsigned long mem_exp_cnt = 0, mem_imp_cnt = 0, mem_rec_cnt = 0; unsigned long nomem_exp_cnt = 0, nomem_imp_cnt = 0, nomem_rec_cnt = 0; for (i = 0; i < NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_len; ++i) { char *grmem = NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val[i]; int neg = grmem[0] == '-'; switch (grmem[neg]) { case '*': if (neg) { nomem_imp[nomem_imp_cnt] = grmem; ++nomem_imp_cnt; } else { mem_imp[mem_imp_cnt] = grmem; ++mem_imp_cnt; } break; case '@': if (neg) { nomem_rec[nomem_rec_cnt] = grmem; ++nomem_rec_cnt; } else { mem_rec[mem_rec_cnt] = grmem; ++mem_rec_cnt; } break; default: if (neg) { nomem_exp[nomem_exp_cnt] = grmem; ++nomem_exp_cnt; } else { mem_exp[mem_exp_cnt] = grmem; ++mem_exp_cnt; } break; } } { char buf[strlen (NIS_RES_OBJECT (res)->zo_domain) + 10]; printf (_("Group entry for /"%s.%s/" group:/n"), NIS_RES_OBJECT (res)->zo_name, nis_domain_of_r (NIS_RES_OBJECT (res)->zo_domain, buf, strlen (NIS_RES_OBJECT (res)->zo_domain) + 10)); } if (mem_exp_cnt) {//.........这里部分代码省略.........
开发者ID:mbref,项目名称:eglibc-microblaze,代码行数:101,
示例6: assuan_inquire/** * assuan_inquire: * @ctx: An assuan context * @keyword: The keyword used for the inquire * @r_buffer: Returns an allocated buffer * @r_length: Returns the length of this buffer * @maxlen: If not 0, the size limit of the inquired data. * * A Server may use this to Send an inquire. r_buffer, r_length and * maxlen may all be NULL/0 to indicate that no real data is expected. * * Return value: 0 on success or an ASSUAN error code **/gpg_error_tassuan_inquire (assuan_context_t ctx, const char *keyword, unsigned char **r_buffer, size_t *r_length, size_t maxlen){ gpg_error_t rc; struct membuf mb; char cmdbuf[LINELENGTH-10]; /* (10 = strlen ("INQUIRE ")+CR,LF) */ unsigned char *line, *p; int linelen; int nodataexpected; if (!ctx || !keyword || (10 + strlen (keyword) >= sizeof (cmdbuf))) return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE); nodataexpected = !r_buffer && !r_length && !maxlen; if (!nodataexpected && (!r_buffer || !r_length)) return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE); if (!ctx->is_server) return _assuan_error (ctx, GPG_ERR_ASS_NOT_A_SERVER); if (ctx->in_inquire) return _assuan_error (ctx, GPG_ERR_ASS_NESTED_COMMANDS); ctx->in_inquire = 1; if (nodataexpected) memset (&mb, 0, sizeof mb); /* avoid compiler warnings */ else init_membuf (ctx, &mb, maxlen? maxlen:1024, maxlen); strcpy (stpcpy (cmdbuf, "INQUIRE "), keyword); rc = assuan_write_line (ctx, cmdbuf); if (rc) goto out; for (;;) { do { do rc = _assuan_read_line (ctx); while (_assuan_error_is_eagain (ctx, rc)); if (rc) goto out; line = (unsigned char *) ctx->inbound.line; linelen = ctx->inbound.linelen; } while (*line == '#' || !linelen); /* Note: As a convenience for manual testing we allow case insensitive keywords. */ if ((line[0] == 'E'||line[0] == 'e') && (line[1] == 'N' || line[1] == 'n') && (line[2] == 'D' || line[2] == 'd') && (!line[3] || line[3] == ' ')) break; /* END command received*/ if ((line[0] == 'C' || line[0] == 'c') && (line[1] == 'A' || line[1] == 'a') && (line[2] == 'N' || line[2] == 'n')) { rc = _assuan_error (ctx, GPG_ERR_ASS_CANCELED); goto out; } if ((line[0] != 'D' && line[0] != 'd') || line[1] != ' ' || nodataexpected) { rc = _assuan_error (ctx, GPG_ERR_ASS_UNEXPECTED_CMD); goto out; } if (linelen < 3) continue; line += 2; linelen -= 2; p = line; while (linelen) { for (;linelen && *p != '%'; linelen--, p++) ; put_membuf (ctx, &mb, line, p-line); if (linelen > 2) { /* handle escaping */ unsigned char tmp[1]; p++; *tmp = xtoi_2 (p); p += 2; linelen -= 3; put_membuf (ctx, &mb, tmp, 1); } line = p;//.........这里部分代码省略.........
开发者ID:GroovIM,项目名称:transport,代码行数:101,
示例7: process_root_passwordstatic int process_root_password(void) { static const char table[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "./"; struct spwd item = { .sp_namp = (char*) "root", .sp_min = -1, .sp_max = -1, .sp_warn = -1, .sp_inact = -1, .sp_expire = -1, .sp_flag = (unsigned long) -1, /* this appears to be what everybody does ... */ }; _cleanup_close_ int lock = -1; char salt[3+16+1+1]; uint8_t raw[16]; unsigned i; char *j; const char *etc_shadow; int r; etc_shadow = prefix_roota(arg_root, "/etc/shadow"); if (faccessat(AT_FDCWD, etc_shadow, F_OK, AT_SYMLINK_NOFOLLOW) >= 0) return 0; mkdir_parents(etc_shadow, 0755); lock = take_password_lock(arg_root); if (lock < 0) return lock; if (arg_copy_root_password && arg_root) { struct spwd *p; errno = 0; p = getspnam("root"); if (p || errno != ENOENT) { if (!p) { if (!errno) errno = EIO; log_error_errno(errno, "Failed to find shadow entry for root: %m"); return -errno; } r = write_root_shadow(etc_shadow, p); if (r < 0) return log_error_errno(r, "Failed to write %s: %m", etc_shadow); log_info("%s copied.", etc_shadow); return 0; } } r = prompt_root_password(); if (r < 0) return r; if (!arg_root_password) return 0; r = dev_urandom(raw, 16); if (r < 0) return log_error_errno(r, "Failed to get salt: %m"); /* We only bother with SHA512 hashed passwords, the rest is legacy, and we don't do legacy. */ assert_cc(sizeof(table) == 64 + 1); j = stpcpy(salt, "$6$"); for (i = 0; i < 16; i++) j[i] = table[raw[i] & 63]; j[i++] = '$'; j[i] = 0; errno = 0; item.sp_pwdp = crypt(arg_root_password, salt); if (!item.sp_pwdp) { if (!errno) errno = -EINVAL; log_error_errno(errno, "Failed to encrypt password: %m"); return -errno; } item.sp_lstchg = (long) (now(CLOCK_REALTIME) / USEC_PER_DAY); r = write_root_shadow(etc_shadow, &item); if (r < 0) return log_error_errno(r, "Failed to write %s: %m", etc_shadow); log_info("%s written.", etc_shadow); return 0;}static void help(void) {//.........这里部分代码省略.........
开发者ID:josephgbr,项目名称:systemd,代码行数:101,
示例8: mainint main(int argc, char* argv[]) { struct option longopts[] = { { "force", no_argument, 0, 'f' }, { "interactive", no_argument, 0, 'i' }, { "recursive", no_argument, 0, 'R' }, { "help", no_argument, 0, 0 }, { "version", no_argument, 0, 1 }, { 0, 0, 0, 0 } }; bool force = false; bool prompt = false; bool recursive = false; int c; while ((c = getopt_long(argc, argv, "fiRr", longopts, NULL)) != -1) { switch (c) { case 0: return help(argv[0], "[OPTIONS] SOURCE... DESTINATION/n" " -f, --force force copy/n" " -i, --interactive prompt before overwrite/n" " -R, -r, --recursive recursively copy directories/n" " --help display this help/n" " --version display version info"); case 1: return version(argv[0]); case 'f': force = true; prompt = false; break; case 'i': force = false; prompt = true; break; case 'r': case 'R': recursive = true; break; case '?': return 1; } } if (optind >= argc) errx(1, "missing source operand"); if (optind == argc - 1) errx(1, "missing destination operand"); const char* destination = argv[argc - 1]; if (optind == argc - 2) { struct stat destSt; int statResult = stat(destination, &destSt); if (statResult < 0 && errno != ENOENT) { err(1, "stat: '%s'", destination); } else if ((statResult < 0 && errno == ENOENT) || !S_ISDIR(destSt.st_mode)) { copy(AT_FDCWD, argv[optind], argv[optind], AT_FDCWD, destination, destination, force, prompt, recursive); return status; } } int destFd = open(destination, O_SEARCH | O_DIRECTORY); if (destFd < 0) err(1, "open: '%s'", destination); for (int i = optind; i < argc - 1; i++) { const char* source = argv[i]; char* sourceCopy = strdup(source); if (!sourceCopy) err(1, "strdup"); char* destName = basename(sourceCopy); if (strcmp(destName, "/") == 0) { destName = "."; } char* destPath = malloc(strlen(destination) + strlen(destName) + 2); if (!destPath) err(1, "malloc"); stpcpy(stpcpy(stpcpy(destPath, destination), "/"), destName); copy(AT_FDCWD, source, source, destFd, destName, destPath, force, prompt, recursive); free(sourceCopy); free(destPath); }}
开发者ID:dennis95,项目名称:dennix,代码行数:78,
示例9: do_teststatic intdo_test (void){ struct sigaction sa; sa.sa_handler = handler; sa.sa_flags = 0; sigemptyset (&sa.sa_mask); sigaction (SIGABRT, &sa, NULL); /* Avoid all the buffer overflow messages on stderr. */ int fd = open (_PATH_DEVNULL, O_WRONLY); if (fd == -1) close (STDERR_FILENO); else { dup2 (fd, STDERR_FILENO); close (fd); } setenv ("LIBC_FATAL_STDERR_", "1", 1); struct A { char buf1[9]; char buf2[1]; } a; struct wA { wchar_t buf1[9]; wchar_t buf2[1]; } wa; printf ("Test checking routines at fortify level %d/n",#ifdef __USE_FORTIFY_LEVEL (int) __USE_FORTIFY_LEVEL#else 0#endif ); /* These ops can be done without runtime checking of object size. */ memcpy (buf, "abcdefghij", 10); memmove (buf + 1, buf, 9); if (memcmp (buf, "aabcdefghi", 10)) FAIL (); if (mempcpy (buf + 5, "abcde", 5) != buf + 10 || memcmp (buf, "aabcdabcde", 10)) FAIL (); memset (buf + 8, 'j', 2); if (memcmp (buf, "aabcdabcjj", 10)) FAIL (); strcpy (buf + 4, "EDCBA"); if (memcmp (buf, "aabcEDCBA", 10)) FAIL (); if (stpcpy (buf + 8, "F") != buf + 9 || memcmp (buf, "aabcEDCBF", 10)) FAIL (); strncpy (buf + 6, "X", 4); if (memcmp (buf, "aabcEDX/0/0", 10)) FAIL (); if (sprintf (buf + 7, "%s", "67") != 2 || memcmp (buf, "aabcEDX67", 10)) FAIL (); if (snprintf (buf + 7, 3, "%s", "987654") != 6 || memcmp (buf, "aabcEDX98", 10)) FAIL (); /* These ops need runtime checking, but shouldn't __chk_fail. */ memcpy (buf, "abcdefghij", l0 + 10); memmove (buf + 1, buf, l0 + 9); if (memcmp (buf, "aabcdefghi", 10)) FAIL (); if (mempcpy (buf + 5, "abcde", l0 + 5) != buf + 10 || memcmp (buf, "aabcdabcde", 10)) FAIL (); memset (buf + 8, 'j', l0 + 2); if (memcmp (buf, "aabcdabcjj", 10)) FAIL (); strcpy (buf + 4, str1 + 5); if (memcmp (buf, "aabcEDCBA", 10)) FAIL (); if (stpcpy (buf + 8, str2) != buf + 9 || memcmp (buf, "aabcEDCBF", 10)) FAIL (); strncpy (buf + 6, "X", l0 + 4); if (memcmp (buf, "aabcEDX/0/0", 10)) FAIL (); if (stpncpy (buf + 5, "cd", l0 + 5) != buf + 7 || memcmp (buf, "aabcEcd/0/0", 10)) FAIL (); if (sprintf (buf + 7, "%d", num1) != 2 || memcmp (buf, "aabcEcd67", 10)) FAIL (); if (snprintf (buf + 7, 3, "%d", num2) != 6 || memcmp (buf, "aabcEcd98", 10)) FAIL (); buf[l0 + 8] = '/0';//.........这里部分代码省略.........
开发者ID:KrisChaplin,项目名称:octeon_toolchain-4.1,代码行数:101,
示例10: singleOptionHelp/** * Display help text for an option. * @param fp output file handle * @param columns output display width control * @param opt option(s) * @param translation_domain translation domain */static void singleOptionHelp(FILE * fp, columns_t columns, const struct poptOption * opt, /*@[email C++ str函数代码示例 C++ storedProcErrorLookup函数代码示例
|