• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ reply_with_perror函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: is_chown_supported

/* Detect if chown(2) is supported on the target directory. */
static int
is_chown_supported (const char *dir)
{
  CLEANUP_FREE char *buf = NULL;
  int fd, r, err, saved_errno;

  /* Create a randomly named file. */
  if (asprintf (&buf, "%s%s/XXXXXXXX.XXX", sysroot, dir) == -1) {
    err = errno;
    r = cancel_receive ();
    errno = err;
    reply_with_perror ("asprintf");
    return -1;
  }
  if (random_name (buf) == -1) {
    err = errno;
    r = cancel_receive ();
    errno = err;
    reply_with_perror ("random_name");
    return -1;
  }

  /* Maybe 'dir' is not a directory or filesystem not writable? */
  fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0666);
  if (fd == -1) {
    err = errno;
    r = cancel_receive ();
    errno = err;
    reply_with_perror ("%s", dir);
    return -1;
  }

  /* This is the test. */
  r = fchown (fd, 1000, 1000);
  saved_errno = errno;

  /* Make sure the test file is removed. */
  close (fd);
  unlink (buf);

  if (r == -1 && saved_errno == EPERM) {
    /* This means chown is not supported by the filesystem. */
    return 0;
  }

  if (r == -1) {
    /* Some other error? */
    err = errno;
    r = cancel_receive ();
    errno = err;
    reply_with_perror_errno (saved_errno, "unexpected error in fchown");
    return -1;
  }

  /* Else chown is supported. */
  return 1;
}
开发者ID:AlphaStaxLLC,项目名称:libguestfs,代码行数:58,代码来源:tar.c


示例2: pread_fd

static char *
pread_fd (int fd, int count, int64_t offset, size_t *size_r,
          const char *display_path)
{
    ssize_t r;
    char *buf;

    if (count < 0) {
        reply_with_error ("count is negative");
        close (fd);
        return NULL;
    }

    if (offset < 0) {
        reply_with_error ("offset is negative");
        close (fd);
        return NULL;
    }

    /* The actual limit on messages is smaller than this.  This check
     * just limits the amount of memory we'll try and allocate in the
     * function.  If the message is larger than the real limit, that
     * will be caught later when we try to serialize the message.
     */
    if (count >= GUESTFS_MESSAGE_MAX) {
        reply_with_error ("%s: count is too large for the protocol, use smaller reads", display_path);
        close (fd);
        return NULL;
    }

    buf = malloc (count);
    if (buf == NULL) {
        reply_with_perror ("malloc");
        close (fd);
        return NULL;
    }

    r = pread (fd, buf, count, offset);
    if (r == -1) {
        reply_with_perror ("pread: %s", display_path);
        close (fd);
        free (buf);
        return NULL;
    }

    if (close (fd) == -1) {
        reply_with_perror ("close: %s", display_path);
        free (buf);
        return NULL;
    }

    /* Mustn't touch *size_r until we are sure that we won't return any
     * error (RHBZ#589039).
     */
    *size_r = r;
    return buf;
}
开发者ID:yumingfei,项目名称:libguestfs,代码行数:57,代码来源:file.c


示例3: do_base64_in

/* Has one FileIn parameter. */
int
do_base64_in (const char *file)
{
  int err, r;
  FILE *fp;
  CLEANUP_FREE char *cmd = NULL;
  int fd;

  if (asprintf_nowarn (&cmd, "%s -d -i > %R", str_base64, file) == -1) {
    err = errno;
    cancel_receive ();
    errno = err;
    reply_with_perror ("asprintf");
    return -1;
  }

  if (verbose)
    fprintf (stderr, "%s\n", cmd);

  fp = popen (cmd, "w");
  if (fp == NULL) {
    err = errno;
    cancel_receive ();
    errno = err;
    reply_with_perror ("%s", cmd);
    return -1;
  }

  /* The semantics of fwrite are too undefined, so write to the
   * file descriptor directly instead.
   */
  fd = fileno (fp);

  r = receive_file (write_cb, &fd);
  if (r == -1) {		/* write error */
    cancel_receive ();
    reply_with_error ("write error on file: %s", file);
    pclose (fp);
    return -1;
  }
  if (r == -2) {		/* cancellation from library */
    /* This error is ignored by the library since it initiated the
     * cancel.  Nevertheless we must send an error reply here.
     */
    reply_with_error ("file upload cancelled");
    pclose (fp);
    return -1;
  }

  if (pclose (fp) != 0) {
    reply_with_error ("base64 subcommand failed on file: %s", file);
    return -1;
  }

  return 0;
}
开发者ID:FengYang,项目名称:libguestfs,代码行数:57,代码来源:base64.c


示例4: do_touch

int
do_touch (const char *path)
{
    int fd;
    int r;
    struct stat buf;

    /* RHBZ#582484: Restrict touch to regular files.  It's also OK
     * here if the file does not exist, since we will create it.
     *
     * XXX Coverity flags this as a time-of-check to time-of-use race
     * condition, particularly in the libguestfs live case.  Not clear
     * how to fix this yet, since unconditionally opening the file can
     * cause a hang, so you have to somehow check it first before you
     * open it.
     */
    CHROOT_IN;
    r = lstat (path, &buf);
    CHROOT_OUT;

    if (r == -1) {
        if (errno != ENOENT) {
            reply_with_perror ("lstat: %s", path);
            return -1;
        }
    } else {
        if (! S_ISREG (buf.st_mode)) {
            reply_with_error ("%s: touch can only be used on a regular files", path);
            return -1;
        }
    }

    CHROOT_IN;
    fd = open (path, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0666);
    CHROOT_OUT;

    if (fd == -1) {
        reply_with_perror ("open: %s", path);
        return -1;
    }

    r = futimens (fd, NULL);
    if (r == -1) {
        reply_with_perror ("futimens: %s", path);
        close (fd);
        return -1;
    }

    if (close (fd) == -1) {
        reply_with_perror ("close: %s", path);
        return -1;
    }

    return 0;
}
开发者ID:yumingfei,项目名称:libguestfs,代码行数:55,代码来源:file.c


示例5: do_inotify_init

int
do_inotify_init (int max_events)
{
  FILE *fp;

  NEED_ROOT (, return -1);

  if (max_events < 0) {
    reply_with_error ("max_events < 0");
    return -1;
  }

  if (max_events > 0) {
    fp = fopen (MQE_PATH, "w");
    if (fp == NULL) {
      reply_with_perror (MQE_PATH);
      return -1;
    }
    fprintf (fp, "%d\n", max_events);
    fclose (fp);
  }

  if (inotify_fd >= 0)
    if (do_inotify_close () == -1)
      return -1;

#ifdef HAVE_INOTIFY_INIT1
  inotify_fd = inotify_init1 (IN_NONBLOCK | IN_CLOEXEC);
  if (inotify_fd == -1) {
    reply_with_perror ("inotify_init1");
    return -1;
  }
#else
  inotify_fd = inotify_init ();
  if (inotify_fd == -1) {
    reply_with_perror ("inotify_init");
    return -1;
  }
  if (fcntl (inotify_fd, F_SETFL, O_NONBLOCK) == -1) {
    reply_with_perror ("fcntl: O_NONBLOCK");
    close (inotify_fd);
    inotify_fd = -1;
    return -1;
  }
  if (fcntl (inotify_fd, F_SETFD, FD_CLOEXEC) == -1) {
    reply_with_perror ("fcntl: FD_CLOEXEC");
    close (inotify_fd);
    inotify_fd = -1;
    return -1;
  }
#endif

  return 0;
}
开发者ID:will-Do,项目名称:libguestfs,代码行数:54,代码来源:inotify.c


示例6: do_internal_lstatnslist

guestfs_int_statns_list *
do_internal_lstatnslist (const char *path, char *const *names)
{
  int path_fd;
  guestfs_int_statns_list *ret;
  size_t i, nr_names;

  nr_names = count_strings (names);

  ret = malloc (sizeof *ret);
  if (!ret) {
    reply_with_perror ("malloc");
    return NULL;
  }
  ret->guestfs_int_statns_list_len = nr_names;
  ret->guestfs_int_statns_list_val =
    calloc (nr_names, sizeof (guestfs_int_statns));
  if (ret->guestfs_int_statns_list_val == NULL) {
    reply_with_perror ("calloc");
    free (ret);
    return NULL;
  }

  CHROOT_IN;
  path_fd = open (path, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
  CHROOT_OUT;

  if (path_fd == -1) {
    reply_with_perror ("%s", path);
    free (ret->guestfs_int_statns_list_val);
    free (ret);
    return NULL;
  }

  for (i = 0; names[i] != NULL; ++i) {
    int r;
    struct stat statbuf;

    r = fstatat (path_fd, names[i], &statbuf, AT_SYMLINK_NOFOLLOW);
    if (r == -1)
      ret->guestfs_int_statns_list_val[i].st_ino = -1;
    else
      stat_to_statns (&ret->guestfs_int_statns_list_val[i], &statbuf);
  }

  if (close (path_fd) == -1) {
    reply_with_perror ("close: %s", path);
    free (ret->guestfs_int_statns_list_val);
    free (ret);
    return NULL;
  }

  return ret;
}
开发者ID:AlphaStaxLLC,项目名称:libguestfs,代码行数:54,代码来源:stat.c


示例7: do_zfile

/* zcat | file */
char *
do_zfile (const char *method, const char *path)
{
  int len;
  const char *zcat;
  char *cmd;
  FILE *fp;
  char line[256];

  if (STREQ (method, "gzip") || STREQ (method, "compress"))
    zcat = "zcat";
  else if (STREQ (method, "bzip2"))
    zcat = "bzcat";
  else {
    reply_with_error ("unknown method");
    return NULL;
  }

  if (asprintf_nowarn (&cmd, "%s %R | file -bsL -", zcat, path) == -1) {
    reply_with_perror ("asprintf");
    return NULL;
  }

  if (verbose)
    fprintf (stderr, "%s\n", cmd);

  fp = popen (cmd, "r");
  if (fp == NULL) {
    reply_with_perror ("%s", cmd);
    free (cmd);
    return NULL;
  }

  free (cmd);

  if (fgets (line, sizeof line, fp) == NULL) {
    reply_with_perror ("fgets");
    fclose (fp);
    return NULL;
  }

  if (fclose (fp) == -1) {
    reply_with_perror ("fclose");
    return NULL;
  }

  len = strlen (line);
  if (len > 0 && line[len-1] == '\n')
    line[len-1] = '\0';

  return strdup (line);
}
开发者ID:gaowanlong,项目名称:libguestfs,代码行数:53,代码来源:file.c


示例8: do_md_stat

extern guestfs_int_mdstat_list *
do_md_stat (const char *md)
{
  size_t mdlen;
  FILE *fp;
  CLEANUP_FREE char *line = NULL;
  size_t allocsize = 0;
  ssize_t n;
  guestfs_int_mdstat_list *ret = NULL;

  if (STRPREFIX (md, "/dev/"))
    md += 5;
  mdlen = strlen (md);

  fp = fopen ("/proc/mdstat", "r");
  if (fp == NULL) {
    reply_with_perror ("fopen: %s", "/proc/mdstat");
    return NULL;
  }

  /* Search for a line which begins with "<md> : ". */
  while ((n = getline (&line, &allocsize, fp)) != -1) {
    if (STRPREFIX (line, md) &&
        line[mdlen] == ' ' && line[mdlen+1] == ':' && line[mdlen+2] == ' ') {
      /* Found it. */
      ret = parse_md_stat_line (&line[mdlen+3]);
      if (!ret) {
        fclose (fp);
        return NULL;
      }

      /* Stop parsing the mdstat file after we've found the line
       * we are interested in.
       */
      break;
    }
  }

  if (fclose (fp) == EOF) {
    reply_with_perror ("fclose: %s", "/proc/mdstat");
    xdr_free ((xdrproc_t) xdr_guestfs_int_mdstat_list, (char *) ret);
    return NULL;
  }

  /* Did we find the line? */
  if (!ret) {
    reply_with_error ("%s: MD device not found", md);
    return NULL;
  }

  return ret;
}
开发者ID:VladimirTyrin,项目名称:libguestfs,代码行数:52,代码来源:md.c


示例9: do_write_file

int
do_write_file (const char *path, const char *content, int size)
{
  int fd;

  /* This call is deprecated, and it has a broken interface.  New code
   * should use the 'guestfs_write' call instead.  Because we used an
   * XDR string type, 'content' cannot contain ASCII NUL and 'size'
   * must never be longer than the string.  We must check this to
   * ensure random stuff from XDR or daemon memory isn't written to
   * the file (RHBZ#597135).
   */
  if (size < 0) {
    reply_with_error ("size cannot be negative");
    return -1;
  }

  /* Note content_len must be small because of the limits on protocol
   * message size.
   */
  int content_len = (int) strlen (content);

  if (size == 0)
    size = content_len;
  else if (size > content_len) {
    reply_with_error ("size parameter is larger than string content");
    return -1;
  }

  CHROOT_IN;
  fd = open (path, O_WRONLY | O_TRUNC | O_CREAT | O_NOCTTY, 0666);
  CHROOT_OUT;

  if (fd == -1) {
    reply_with_perror ("open: %s", path);
    return -1;
  }

  if (xwrite (fd, content, size) == -1) {
    reply_with_perror ("write");
    close (fd);
    return -1;
  }

  if (close (fd) == -1) {
    reply_with_perror ("close: %s", path);
    return -1;
  }

  return 0;
}
开发者ID:gaowanlong,项目名称:libguestfs,代码行数:51,代码来源:file.c


示例10: add_partitions

static int
add_partitions(const char *device,
               char ***const r, int *const size, int *const alloc)
{
  char devdir[256];

  /* Open the device's directory under /sys/block */
  snprintf (devdir, sizeof devdir, "/sys/block/%s", device);

  DIR *dir = opendir (devdir);
  if (!dir) {
    reply_with_perror ("opendir: %s", devdir);
    free_stringslen (*r, *size);
    return -1;
  }

  /* Look in /sys/block/<device>/ for entries starting with <device>
   * e.g. /sys/block/sda/sda1
   */
  errno = 0;
  struct dirent *d;
  while ((d = readdir (dir)) != NULL) {
    if (STREQLEN (d->d_name, device, strlen (device))) {
      char part[256];
      snprintf (part, sizeof part, "/dev/%s", d->d_name);

      if (add_string (r, size, alloc, part) == -1) {
        closedir (dir);
        return -1;
      }
    }
  }

  /* Check if readdir failed */
  if(0 != errno) {
      reply_with_perror ("readdir: %s", devdir);
      free_stringslen(*r, *size);
      closedir (dir);
      return -1;
  }

  /* Close the directory handle */
  if (closedir (dir) == -1) {
    reply_with_perror ("closedir: /sys/block/%s", device);
    free_stringslen (*r, *size);
    return -1;
  }

  return 0;
}
开发者ID:gaowanlong,项目名称:libguestfs,代码行数:50,代码来源:devsparts.c


示例11: do_touch

int
do_touch (const char *path)
{
  int fd;
  int r;
  struct stat buf;

  /* RHBZ#582484: Restrict touch to regular files.  It's also OK
   * here if the file does not exist, since we will create it.
   */
  CHROOT_IN;
  r = lstat (path, &buf);
  CHROOT_OUT;

  if (r == -1) {
    if (errno != ENOENT) {
      reply_with_perror ("lstat: %s", path);
      return -1;
    }
  } else {
    if (! S_ISREG (buf.st_mode)) {
      reply_with_error ("%s: touch can only be used on a regular files", path);
      return -1;
    }
  }

  CHROOT_IN;
  fd = open (path, O_WRONLY | O_CREAT | O_NOCTTY, 0666);
  CHROOT_OUT;

  if (fd == -1) {
    reply_with_perror ("open: %s", path);
    return -1;
  }

  r = futimens (fd, NULL);
  if (r == -1) {
    reply_with_perror ("futimens: %s", path);
    close (fd);
    return -1;
  }

  if (close (fd) == -1) {
    reply_with_perror ("close: %s", path);
    return -1;
  }

  return 0;
}
开发者ID:gaowanlong,项目名称:libguestfs,代码行数:49,代码来源:file.c


示例12: do_fill

int
do_fill (int c, int len, const char *path)
{
  int fd;
  ssize_t r;
  size_t len_sz;
  size_t n;
  char buf[BUFSIZ];

  if (c < 0 || c > 255) {
    reply_with_error ("%d: byte number must be in range 0..255", c);
    return -1;
  }
  memset (buf, c, BUFSIZ);
  if (len < 0) {
    reply_with_error ("%d: length is < 0", len);
    return -1;
  }
  len_sz = (size_t) len;

  CHROOT_IN;
  fd = open (path, O_WRONLY | O_CREAT | O_NOCTTY, 0666);
  CHROOT_OUT;

  if (fd == -1) {
    reply_with_perror ("open: %s", path);
    return -1;
  }

  n = 0;
  while (n < len_sz) {
    r = write (fd, buf, len_sz - n < BUFSIZ ? len_sz - n : BUFSIZ);
    if (r == -1) {
      reply_with_perror ("write: %s", path);
      close (fd);
      return -1;
    }
    n += r;
    notify_progress ((uint64_t) n, (uint64_t) len_sz);
  }

  if (close (fd) == -1) {
    reply_with_perror ("close: %s", path);
    return -1;
  }

  return 0;
}
开发者ID:ArikaChen,项目名称:libguestfs,代码行数:48,代码来源:fill.c


示例13: debug_ll

/* List files in the appliance. */
static char *
debug_ll (const char *subcmd, size_t argc, char *const *const argv)
{
  const size_t len = guestfs_int_count_strings (argv);
  CLEANUP_FREE const char **cargv = NULL;
  size_t i;
  int r;
  char *out;
  CLEANUP_FREE char *err = NULL;

  cargv = malloc (sizeof (char *) * (len+3));
  if (cargv == NULL) {
    reply_with_perror ("malloc");
    return NULL;
  }

  cargv[0] = "ls";
  cargv[1] = "-la";
  for (i = 0; i < len; ++i)
    cargv[2+i] = argv[i];
  cargv[2+len] = NULL;

  r = commandv (&out, &err, (void *) cargv);
  if (r == -1) {
    reply_with_error ("ll: %s", err);
    free (out);
    return NULL;
  }

  return out;
}
开发者ID:libguestfs,项目名称:libguestfs,代码行数:32,代码来源:debug.c


示例14: do_aug_init

/* We need to rewrite the root path so it is based at /sysroot. */
int
do_aug_init (const char *root, int flags)
{
#ifdef HAVE_AUGEAS
  char *buf;

  if (aug) {
    aug_close (aug);
    aug = NULL;
  }

  buf = sysroot_path (root);
  if (!buf) {
    reply_with_perror ("malloc");
    return -1;
  }

  aug = aug_init (buf, NULL, flags);
  free (buf);

  if (!aug) {
    reply_with_error ("Augeas initialization failed");
    return -1;
  }

  return 0;
#else
  NOT_AVAILABLE (-1);
#endif
}
开发者ID:gaowanlong,项目名称:libguestfs,代码行数:31,代码来源:augeas.c


示例15: debug_spew

/* Generate lots of debug messages.  Each line of output is 72
 * characters long (plus '\n'), so the total size of the output in
 * bytes is n*73.
 */
static char *
debug_spew (const char *subcmd, size_t argc, char *const *const argv)
{
  size_t i, n;
  char *ret;

  if (argc != 1) {
    reply_with_error ("spew: expecting number of lines <n>");
    return NULL;
  }

  if (sscanf (argv[0], "%zu", &n) != 1) {
    reply_with_error ("spew: could not parse number of lines '%s'", argv[0]);
    return NULL;
  }

  for (i = 0; i < n; ++i)
    fprintf (stderr,
             "abcdefghijklmnopqrstuvwxyz" /* 26 */
             "ABCDEFGHIJKLMNOPQRSTUVWXYZ" /* 52 */
             "01234567890123456789" /* 72 */
             "\n");

  ret = strdup ("ok");
  if (!ret) {
    reply_with_perror ("strdup");
    return NULL;
  }

  return ret;
}
开发者ID:carriercomm,项目名称:libguestfs,代码行数:35,代码来源:debug.c


示例16: do_rm_rf

/* This implementation is quick and dirty, and allows people to try
 * to remove parts of the initramfs (eg. "rm -r /..") but if people
 * do stupid stuff, who are we to try to stop them?
 */
int
do_rm_rf (const char *path)
{
  int r;
  char *buf, *err;

  if (STREQ (path, "/")) {
    reply_with_error ("cannot remove root directory");
    return -1;
  }

  buf = sysroot_path (path);
  if (buf == NULL) {
    reply_with_perror ("malloc");
    return -1;
  }

  r = command (NULL, &err, str_rm, "-rf", buf, NULL);
  free (buf);

  /* rm -rf is never supposed to fail.  I/O errors perhaps? */
  if (r == -1) {
    reply_with_error ("%s: %s", path, err);
    free (err);
    return -1;
  }

  free (err);

  return 0;
}
开发者ID:yumingfei,项目名称:libguestfs,代码行数:35,代码来源:dir.c


示例17: do_vgcreate

int
do_vgcreate (const char *volgroup, char *const *physvols)
{
  char *err;
  int r, argc, i;
  const char **argv;

  argc = count_strings (physvols) + 3;
  argv = malloc (sizeof (char *) * (argc + 1));
  if (argv == NULL) {
    reply_with_perror ("malloc");
    return -1;
  }
  argv[0] = "lvm";
  argv[1] = "vgcreate";
  argv[2] = volgroup;
  for (i = 3; i <= argc; ++i)
    argv[i] = physvols[i-3];

  r = commandv (NULL, &err, (const char * const*) argv);
  if (r == -1) {
    reply_with_error ("%s", err);
    free (err);
    free (argv);
    return -1;
  }

  free (err);
  free (argv);

  udev_settle ();

  return 0;
}
开发者ID:limohua,项目名称:libguestfs,代码行数:34,代码来源:lvm.c


示例18: do_part_set_gpt_guid

int
do_part_set_gpt_guid (const char *device, int partnum, const char *guid)
{
  if (partnum <= 0) {
    reply_with_error ("partition number must be >= 1");
    return -1;
  }

  CLEANUP_FREE char *typecode = NULL;
  if (asprintf (&typecode, "%i:%s", partnum, guid) == -1) {
    reply_with_perror ("asprintf");
    return -1;
  }

  CLEANUP_FREE char *err = NULL;
  int r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
                    "sgdisk", device, "-u", typecode, NULL);

  if (r == -1) {
    reply_with_error ("%s %s -u %s: %s", "sgdisk", device, typecode, err);
    return -1;
  }

  return 0;
}
开发者ID:libguestfs,项目名称:libguestfs,代码行数:25,代码来源:parted.c


示例19: do_xfs_info

guestfs_int_xfsinfo *
do_xfs_info (const char *pathordevice)
{
  int r;
  CLEANUP_FREE char *buf = NULL;
  CLEANUP_FREE char *out = NULL, *err = NULL;
  CLEANUP_FREE_STRING_LIST char **lines = NULL;
  int is_dev;

  is_dev = STREQLEN (pathordevice, "/dev/", 5);
  buf = is_dev ? strdup (pathordevice)
               : sysroot_path (pathordevice);
  if (buf == NULL) {
    reply_with_perror ("malloc");
    return NULL;
  }

  r = command (&out, &err, str_xfs_info, buf, NULL);
  if (r == -1) {
    reply_with_error ("%s", err);
    return NULL;
  }

  lines = split_lines (out);
  if (lines == NULL)
    return NULL;

  return parse_xfs_info (lines);
}
开发者ID:will-Do,项目名称:libguestfs,代码行数:29,代码来源:xfs.c


示例20: get_table_field

/* Return the nth field from a string of ':'/';'-delimited strings.
 * Useful for parsing the return value from 'parted -m'.
 */
static char *
get_table_field (const char *line, int n)
{
  const char *p = line;

  while (*p && n > 0) {
    p += strcspn (p, ":;") + 1;
    n--;
  }

  if (n > 0) {
    reply_with_error ("not enough fields in output of parted print command: %s",
                      line);
    return NULL;
  }

  size_t len = strcspn (p, ":;");
  char *q = strndup (p, len);
  if (q == NULL) {
    reply_with_perror ("strndup");
    return NULL;
  }

  return q;
}
开发者ID:mdbooth,项目名称:libguestfs,代码行数:28,代码来源:parted.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ reportAttributeParsingError函数代码示例发布时间:2022-05-30
下一篇:
C++ reply_with_error函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap