当前位置: 首页>>代码示例>>C++>>正文


C++ str::cstr方法代码示例

本文整理汇总了C++中str::cstr方法的典型用法代码示例。如果您正苦于以下问题:C++ str::cstr方法的具体用法?C++ str::cstr怎么用?C++ str::cstr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在str的用法示例。


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

示例1: m

str
trunc_at_first_null (const str &s)
{
  assert (s);

  const char *cp;
  size_t len = s.len ();
  size_t l;
  const char nullc = '\0';

  // Figure out if a '\0' or the end-of-string comes first.
  for (cp = s.cstr (), l = 0; *cp != nullc && l < len; cp++, l++);

  str ret;

  if (*cp == nullc) {
    
    // The most likely outcome
    if (l == len) ret = s;

    // There was a '\0' inside the string
    else ret = s.cstr ();

  } else {
   
    // String is not null terminated!
    mstr m (len + 1);
    memcpy (m.cstr (), s.cstr (), len);
    m[len] = nullc;
    ret = m;
  }

  return ret;
}
开发者ID:Y317608039,项目名称:okws,代码行数:34,代码来源:pubutil.C

示例2: wrap

void
dhblock_keyhash_srv::real_store (chordID key, str od, str nd, u_int32_t exp, cb_dhstat cb)
{
  u_int32_t v1 = dhblock_keyhash::version (nd.cstr (), nd.len ());
  if (od.len ()) {
    u_int32_t v0 = dhblock_keyhash::version (od.cstr (), od.len ());
    if (v0 > v1) {
      chordID p = node->my_pred ()->id ();
      chordID m = node->my_ID ();
      if (betweenrightincl (p, m, key))
	cb (DHASH_STALE);
      else
	cb (DHASH_RETRY);
    } else {
      info << "db delete: " << key << "\n";
      db->remove (key, v0, 
		  wrap (this, &dhblock_keyhash_srv::delete_cb, key, 
			nd, v1, exp, cb));
    }
  } else {
    info << "db write: " << node->my_ID ()
	 << " N " << key << " " << nd.len () << "\n";
    db_store (key, nd, v1, exp, cb);
  }
}
开发者ID:Amit-DU,项目名称:dht,代码行数:25,代码来源:dhblock_keyhash_srv.C

示例3: memset

wide_str_t::wide_str_t (str utf8_in)
{
  if (utf8_in) {
    _init (utf8_in.len ());
    mbstate_t state;
    memset (&state, 0, sizeof (state));
    const char *src = utf8_in.cstr ();
    setlocale (LC_CTYPE, "en_US.UTF-8");
    ssize_t ret = mbstowcs (_buf->base (), src, _buf->size ());
    if (ret < 0) {
      _err = true;
      _buf = NULL;
      _len = 0;
    } else {
      _len = ret;
      if (0 && src) {
	warn << "XX failed to completely convert string ('" 
	     << utf8_in << "'): " 
	     << "expected " << _len << " bytes, but only converted "
	     << (src - utf8_in.cstr ()) << "\n";
	_err = true;
      } else {
	_err = false;
      }
    }
  }
}
开发者ID:Sidnicious,项目名称:sfslite,代码行数:27,代码来源:wide_str.C

示例4: return

bool
can_read (const str &f)
{
  struct stat sb;
  return  (f && stat(f.cstr (), &sb) == 0 && S_ISREG (sb.st_mode)
	   && access (f.cstr(), R_OK) == 0);
}
开发者ID:Y317608039,项目名称:okws,代码行数:7,代码来源:pubutil.C

示例5: assert

/* If the directory specified by path does not exist, create it with
 * the given mode. If we fail for any reason, terminate with error.  */
void
mksfsdir (str path, mode_t mode, struct stat *sbp, uid_t uid)
{
  assert (path[0] == '/');

  mode_t m = umask (0);
  struct stat sb;
  if (stat (path, &sb) < 0) {
    if (errno != ENOENT || (mkdir (path, mode) < 0 && errno != EEXIST))
      fatal ("%s: %m\n", path.cstr ());
    if (chown (path, uid, sfs_gid) < 0) {
      int saved_errno = errno;
      rmdir (path);
      fatal ("chown (%s): %s\n", path.cstr (), strerror (saved_errno));
    }
    if (stat (path, &sb) < 0)
      fatal ("stat (%s): %m\n", path.cstr ());
  }
  umask (m);

  if (!S_ISDIR (sb.st_mode))
    fatal ("%s: not a directory\n", path.cstr ());
  if (sb.st_uid != uid)
    fwarn << path << ": owned by uid " << sb.st_uid
	  << ", should be uid " << uid << "\n";
  if (sb.st_gid != sfs_gid)
    fwarn << path << ": has gid " << sb.st_gid
	  << ", should be gid " << sfs_gid << "\n";
  if (sb.st_mode & 07777 & ~mode)
    fwarn ("%s: mode 0%o, should be 0%o\n",
	   path.cstr (), int (sb.st_mode & 07777), int (mode));

  if (sbp)
    *sbp = sb;
}
开发者ID:okws,项目名称:sfslite,代码行数:37,代码来源:sfsconst.C

示例6: fatal

int
suidgetfd_required (str prog)
{
  int fds[2];
  if (socketpair (AF_UNIX, SOCK_STREAM, 0, fds) < 0)
    fatal ("socketpair: %m\n");
  close_on_exec (fds[0]);

  str path = fix_exec_path ("suidconnect");
  char *av[] = { "suidconnect", const_cast<char *> (prog.cstr ()), NULL };
  if (spawn (path, av, fds[1]) == -1)
    fatal << path << ": " << strerror (errno) << "\n";
  close (fds[1]);
  
  int fd = recvfd (fds[0]);
  if (fd < 0) {
    struct stat sb;
    if (!runinplace && !stat (path, &sb)
	&& (sb.st_gid != sfs_gid || !(sb.st_mode & 02000))) {
      if (struct group *gr = getgrgid (sfs_gid))
	warn << path << " should be setgid to group " << gr->gr_name << "\n";
      else
	warn << path << " should be setgid to group " << sfs_gid << "\n";
    }
    else {
      warn << "have you launched the appropriate daemon (sfscd or sfssd)?\n";
      warn << "have subsidiary daemons died (check your system logs)?\n";
    }
    fatal ("could not suidconnect for %s\n", prog.cstr ());
  }
  close (fds[0]);
  return fd;
}
开发者ID:bougyman,项目名称:sfs,代码行数:33,代码来源:suidgetfd.C

示例7: convertint

static void
idlookup (str uid, str gid)
{
  if (!uid)
    uid = "sfs";
  if (!gid)
    gid = uid;

  bool uidok = convertint (uid, &sfs_uid);
  struct passwd *pw = uidok ? getpwuid (sfs_uid) : getpwnam (uid.cstr ());
  bool gidok = convertint (gid, &sfs_gid);
  struct group *gr = gidok ? getgrgid (sfs_gid) : getgrnam (gid.cstr ());

  if (!uidok) {
    if (!pw)
      fatal << "Could not find user " << uid << "\n";
    sfs_uid = pw->pw_uid;
  }
  if (!gidok) {
    if (!gr)
      fatal << "Could not find group " << gid << "\n";
    sfs_gid = gr->gr_gid;
  }
  if (gr && gr->gr_mem[0])
    fwarn << "Group " << gid << " must not have any members\n";
  if (pw && gr && (gid_t) pw->pw_gid != (gid_t) gr->gr_gid)
    fwarn << "User " << uid << " must have login group " << gid << ".\n";

  endpwent ();
  endgrent ();
}
开发者ID:okws,项目名称:sfslite,代码行数:31,代码来源:sfsconst.C

示例8: substr

inline str
group_prefix (str s, str prefix)
{
  if (s.len () <= prefix.len () || s[prefix.len ()] != '.'
      || memcmp (s.cstr (), prefix.cstr (), prefix.len ()))
    return NULL;
  return substr (s, prefix.len () + 1);
}
开发者ID:dougc333,项目名称:sfs_eventdrivenc--templatelibrary,代码行数:8,代码来源:authclnt_update.C

示例9: if

str
can_exec (const str &p)
{
  if (access (p.cstr (), R_OK)) 
    return ("cannot read executable");
  else if (access (p.cstr (), X_OK)) 
    return ("cannot execute");
  return NULL;
}
开发者ID:Y317608039,项目名称:okws,代码行数:9,代码来源:pubutil.C

示例10: count_newlines

u_int count_newlines (str s)
{
  const char *end = s.cstr () + s.len ();
  u_int c = 0;
  for (const char *cp = s.cstr (); cp < end; cp++) {
    if (*cp == '\n')
      c++;
  }
  return c;
}
开发者ID:maxtaco,项目名称:sfslite,代码行数:10,代码来源:output.C

示例11:

void
suio_print (suio *uio, const str &s)
{
  if (s.len () <= suio::smallbufsize)
    uio->copy (s.cstr (), s.len ());
  else {
    uio->print (s.cstr (), s.len ());
    uio->iovcb (wrap (&s.b.Xplug, s.b.Xleak ()));
  }
}
开发者ID:Sidnicious,项目名称:sfslite,代码行数:10,代码来源:str.C

示例12: munmap

void
random_set_seedfile (str path)
{
  if (!path) {
    if (seed) {
      munmap (reinterpret_cast<char *> (seed), mapsize);
      seed = NULL;
    }
    return;
  }

  if (path[0] == '~' && path[1] == '/') {
    const char *home = getenv ("HOME");
    if (!home) {
      warn ("$HOME not set in environment\n");
      return;
    }
    path = strbuf () << home << (path.cstr () + 1);
  }

  int fd = open (path, O_CREAT|O_RDWR, 0600);
  if (fd < 0) {
    warn ("%s: %m\n", path.cstr ());
    return;
  }
  struct stat sb;
  char c;
  if (read (fd, &c, 1) < 0 || fstat (fd, &sb) < 0
      || lseek (fd, mapsize - 1, SEEK_SET) == -1
      || write (fd, "", 1) < 0) {
    /* The read call avoids a segfault on NFS 2.  Specifically, if we
     * are root and the random_seed file is over NFS 2, the open will
     * succeed even though read returns EACCES.  If we map the file
     * when we can't read it--bingo, segfault.  (In fact, on some OSes
     * it also seems to cause a kernel panic when you examine the
     * mmapped memory from the debugger.) */
    close (fd);
    warn ("%s: %m\n", path.cstr ());
    return;
  }
  if ((sb.st_mode & 07777) != 0600)
    warn ("%s: mode 0%o should be 0600\n", path.cstr (), sb.st_mode & 07777);

  if (seed)
    munmap (reinterpret_cast<char *> (seed), mapsize);
  seed = mmap (NULL, (size_t) mapsize, PROT_READ|PROT_WRITE,
	       MAP_FILE|MAP_SHARED, fd, 0);
  if (seed == reinterpret_cast<void *> (MAP_FAILED)) {
    warn ("mmap: %s: %m\n", path.cstr ());
    seed = NULL;
  }
  else
    rnd_input.update (seed, seedsize);
  close (fd);
}
开发者ID:maxtaco,项目名称:sfslite,代码行数:55,代码来源:rndseed.C

示例13: strdup

int
open_file (const str &nm, int flags)
{
  char *s = strdup (nm.cstr ());
  int rc = 0;

  rc = mkdir_p (s);
  if (rc == 0)
    rc = ::open (nm.cstr (), flags, 0666);

  if (s) free (s);
  return rc;
}
开发者ID:Sidnicious,项目名称:sfslite,代码行数:13,代码来源:util.C

示例14: start_log_to_file

int
start_logger (const str &priority, const str &tag, const str &line, 
	      const str &logfile, int flags, mode_t mode)
{
  str logger;
#ifdef PATH_LOGGER
  logger = PATH_LOGGER;
#endif

  if (logger) {
    const char *av[] = { NULL, "-p", NULL, "-t", NULL, NULL, NULL };
    av[0] = const_cast<char *> (logger.cstr ());
    av[2] = const_cast<char *> (priority.cstr ());
  
    if (line)
      av[5] = const_cast<char *> (line.cstr ());
    else
      av[5] = "log started";
    
    if (tag)
      av[4] = const_cast<char *> (tag.cstr ());
    else 
      av[4] = "";
    
    pid_t pid;
    int status;
    if ((pid = spawn (av[0], av, 0, 0, errfd)) < 0) {
      warn ("%s: %m\n", logger.cstr ());
      return start_log_to_file (line, logfile, flags, mode);
    } 
    if (waitpid (pid, &status, 0) <= 0 || !WIFEXITED (status) || 
	WEXITSTATUS (status)) 
      return start_log_to_file (line, logfile, flags, mode);
    
    int fds[2];
    if (socketpair (AF_UNIX, SOCK_STREAM, 0, fds) < 0)
      fatal ("socketpair: %m\n");
    close_on_exec (fds[0]);
    if (fds[1] != 0)
      close_on_exec (fds[1]);
    
    av[5] = NULL;
    if (spawn (av[0], av, fds[1], 0, 0) >= 0) {
      close (fds[1]);
      return fds[0];
    } else {
      warn ("%s: %m\n", logger.cstr ());
    }
  } 
  return start_log_to_file (line, logfile, flags, mode);
}
开发者ID:maxtaco,项目名称:sfslite,代码行数:51,代码来源:daemonize.C

示例15: strlen

static str
makehdrname (str fname)
{
  strbuf hdr;
  const char *p;

  if ((p = strrchr (fname.cstr(), '/')))
    p++;
  else p = fname.cstr();

  hdr.buf (p, strlen (p) - 1);
  hdr.cat ("h");

  return hdr;
}
开发者ID:okws,项目名称:sfslite,代码行数:15,代码来源:gencfile.C


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