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

C++ perrorf函数代码示例

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

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



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

示例1: do_fusermount

static int
do_fusermount (guestfs_h *g, const char *localmountpoint, int error_fd)
{
  pid_t pid;
  int status;

  pid = fork ();
  if (pid == -1) {
    perrorf (g, "fork");
    return -1;
  }

  if (pid == 0) {               /* child */
    /* Ensure stdout and stderr point to the error_fd. */
    dup2 (error_fd, STDOUT_FILENO);
    dup2 (error_fd, STDERR_FILENO);
    close (error_fd);
    execlp ("fusermount", "fusermount", "-u", localmountpoint, NULL);
    perror ("exec: fusermount");
    _exit (EXIT_FAILURE);
  }

  /* Parent. */
  if (waitpid (pid, &status, 0) == -1) {
    perrorf (g, "waitpid");
    return -1;
  }

  if (!WIFEXITED (status) || WEXITSTATUS (status) != EXIT_SUCCESS)
    return 0;                   /* it failed to unmount the mountpoint */

  return 1;                     /* unmount was successful */
}
开发者ID:msmhrt,项目名称:libguestfs,代码行数:33,代码来源:fuse.c


示例2: rlc_insert

static int
rlc_insert (guestfs_h *g,
            const char *path, const char *name, time_t now,
            char *link)
{
  struct rlc_entry *entry;
  size_t len;

  entry = malloc (sizeof *entry);
  if (entry == NULL) {
    perrorf (g, "malloc");
    return -1;
  }

  len = strlen (path) + strlen (name) + 2;
  entry->c.pathname = malloc (len);
  if (entry->c.pathname == NULL) {
    perrorf (g, "malloc");
    free (entry);
    return -1;
  }
  if (STREQ (path, "/"))
    snprintf (entry->c.pathname, len, "/%s", name);
  else
    snprintf (entry->c.pathname, len, "%s/%s", path, name);

  entry->link = link;

  entry->c.timeout = now + g->ml_dir_cache_timeout;

  return gen_replace (g, g->rlc_ht, (struct entry_common *) entry, rlc_free);
}
开发者ID:noxdafox,项目名称:libguestfs,代码行数:32,代码来源:fuse.c


示例3: filecopy

int filecopy(FILE *in, FILE *out, char *outname, size_t insiz)
{
	char buffer[BSIZ];
	size_t nread, total = 0;
	int ret = 0, lastprogress = 0;

	while((nread = fread(buffer, sizeof buffer[0], BSIZ, in)) > 0){
		if(fwrite(buffer, sizeof buffer[0], nread, out) <= 0){
			perrorf("fwrite()");
			ret = 1;
			goto bail;
		}
		if(++lastprogress > PROGRESS_COUNT){
			progress(outname, total += nread, insiz);
			lastprogress = 0;
		}
	}

	progressdone(outname, insiz);

	if(ferror(in)){
		perrorf("fread()");
		ret = 1;
	}
bail:
	return ret;
}
开发者ID:bobrippling,项目名称:cbin,代码行数:27,代码来源:pcp.c


示例4: guestfs_impl_read_file

char *
guestfs_impl_read_file (guestfs_h *g, const char *path, size_t *size_r)
{
  int fd = -1;
  size_t size;
  CLEANUP_UNLINK_FREE char *tmpfile = NULL;
  char *ret = NULL;
  struct stat statbuf;

  tmpfile = guestfs_int_make_temp_path (g, "cat", NULL);
  if (tmpfile == NULL)
    goto err;

  if (guestfs_download (g, path, tmpfile) == -1)
    goto err;

  fd = open (tmpfile, O_RDONLY|O_CLOEXEC);
  if (fd == -1) {
    perrorf (g, "open: %s", tmpfile);
    goto err;
  }

  /* Read the whole file into memory. */
  if (fstat (fd, &statbuf) == -1) {
    perrorf (g, "stat: %s", tmpfile);
    goto err;
  }

  /* Don't use safe_malloc, because we want to return an errno to the caller. */
  size = statbuf.st_size;
  ret = malloc (size + 1);
  if (!ret) {
    perrorf (g, "malloc: %zu bytes", size + 1);
    goto err;
  }

  if (full_read (fd, ret, size) != size) {
    perrorf (g, "full-read: %s: %zu bytes", tmpfile, size + 1);
    goto err;
  }

  ret[size] = '\0';

  if (close (fd) == -1) {
    perrorf (g, "close: %s", tmpfile);
    goto err;
  }

  /* Mustn't touch *size_r until we are sure that we won't return any
   * error (RHBZ#589039).
   */
  *size_r = size;
  return ret;

 err:
  free (ret);
  if (fd >= 0)
    close (fd);
  return NULL;
}
开发者ID:libguestfs,项目名称:libguestfs,代码行数:60,代码来源:file.c


示例5: set_abs_path

/* We need to make all tmpdir paths absolute because lots of places in
 * the code assume this.  Do it at the time we set the path or read
 * the environment variable (RHBZ#882417).
 */
static int
set_abs_path (guestfs_h *g, const char *tmpdir, char **tmpdir_ret)
{
  char *ret;
  struct stat statbuf;

  /* Free the old path, and set it to NULL so that if we fail below
   * we don't end up with a pointer to freed memory.
   */
  free (*tmpdir_ret);
  *tmpdir_ret = NULL;

  if (tmpdir == NULL)
    return 0;

  ret = realpath (tmpdir, NULL);
  if (ret == NULL) {
    perrorf (g, _("failed to set temporary directory: %s"), tmpdir);
    return -1;
  }

  if (stat (ret, &statbuf) == -1) {
    perrorf (g, _("failed to set temporary directory: %s"), tmpdir);
    return -1;
  }

  if (!S_ISDIR (statbuf.st_mode)) {
    error (g, _("temporary directory '%s' is not a directory"), tmpdir);
    return -1;
  }

  *tmpdir_ret = ret;
  return 0;
}
开发者ID:will-Do,项目名称:libguestfs,代码行数:38,代码来源:tmpdirs.c


示例6: copy_xattr_list

static struct guestfs_xattr_list *
copy_xattr_list (guestfs_h *g, const struct guestfs_xattr *first, size_t num)
{
  struct guestfs_xattr_list *xattrs;
  size_t i;

  xattrs = malloc (sizeof *xattrs);
  if (xattrs == NULL) {
    perrorf (g, "malloc");
    return NULL;
  }

  xattrs->len = num;
  xattrs->val = malloc (num * sizeof (struct guestfs_xattr));
  if (xattrs->val == NULL) {
    perrorf (g, "malloc");
    free (xattrs);
    return NULL;
  }

  for (i = 0; i < num; ++i) {
    xattrs->val[i].attrname = strdup (first[i].attrname);
    xattrs->val[i].attrval_len = first[i].attrval_len;
    xattrs->val[i].attrval = malloc (first[i].attrval_len);
    memcpy (xattrs->val[i].attrval, first[i].attrval, first[i].attrval_len);
  }

  return xattrs;
}
开发者ID:noxdafox,项目名称:libguestfs,代码行数:29,代码来源:fuse.c


示例7: lazy_make_tmpdir

static int
lazy_make_tmpdir (guestfs_h *g, char *(*getdir) (guestfs_h *g), char **dest)
{
  if (!*dest) {
    CLEANUP_FREE char *tmpdir = getdir (g);
    char *tmppath = safe_asprintf (g, "%s/libguestfsXXXXXX", tmpdir);
    if (mkdtemp (tmppath) == NULL) {
      perrorf (g, _("%s: cannot create temporary directory"), tmppath);
      free (tmppath);
      return -1;
    }
    /* Allow qemu (which may be running as qemu.qemu) to read in this
     * temporary directory; we are storing either sockets, or temporary
     * disks which qemu needs to access to.  (RHBZ#610880).
     * We do this only for root, as for normal users qemu will be run
     * under the same user.
     */
    if (geteuid () == 0 && chmod (tmppath, 0755) == -1) {
      perrorf (g, "chmod: %s", tmppath);
      free (tmppath);
      return -1;
    }
    *dest = tmppath;
  }
  return 0;
}
开发者ID:AlphaStaxLLC,项目名称:libguestfs,代码行数:26,代码来源:tmpdirs.c


示例8: guestfs_int_new_conn_socket_connected

/* Create a new socket connection, connected.
 *
 * As above, but the caller passes us a connected daemon_sock
 * and promises not to call accept_connection.
 */
struct connection *
guestfs_int_new_conn_socket_connected (guestfs_h *g,
                                     int daemon_sock,
                                     int console_sock)
{
  struct connection_socket *conn;

  assert (daemon_sock >= 0);

  if (fcntl (daemon_sock, F_SETFL, O_NONBLOCK) == -1) {
    perrorf (g, "new_conn_socket_connected: fcntl");
    return NULL;
  }

  if (console_sock >= 0) {
    if (fcntl (console_sock, F_SETFL, O_NONBLOCK) == -1) {
      perrorf (g, "new_conn_socket_connected: fcntl");
      return NULL;
    }
  }

  conn = safe_malloc (g, sizeof *conn);

  /* Set the operations. */
  conn->ops = &ops;

  /* Set the internal state. */
  conn->console_sock = console_sock;
  conn->daemon_sock = daemon_sock;
  conn->daemon_accept_sock = -1;

  return (struct connection *) conn;
}
开发者ID:FengYang,项目名称:libguestfs,代码行数:38,代码来源:conn-socket.c


示例9: write_or_append

static int
write_or_append (guestfs_h *g, const char *path,
                 const char *content, size_t size,
                 int append)
{
  CLEANUP_UNLINK_FREE char *tmpfile = NULL;
  int fd = -1;
  int64_t filesize;

  /* If the content is small enough, use guestfs_internal_write{,_append}
   * since that call is more efficient.
   */
  if (size <= 2*1024*1024)
    return
      (!append ? guestfs_internal_write : guestfs_internal_write_append)
      (g, path, content, size);

  if (guestfs_int_lazy_make_tmpdir (g) == -1)
    goto err;

  /* Write the content out to a temporary file. */
  tmpfile = safe_asprintf (g, "%s/write%d", g->tmpdir, ++g->unique);

  fd = open (tmpfile, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0600);
  if (fd == -1) {
    perrorf (g, "open: %s", tmpfile);
    goto err;
  }

  if (full_write (fd, content, size) != size) {
    perrorf (g, "write: %s", tmpfile);
    goto err;
  }

  if (close (fd) == -1) {
    perrorf (g, "close: %s", tmpfile);
    goto err;
  }
  fd = -1;

  if (!append) {
    if (guestfs_upload (g, tmpfile, path) == -1)
      goto err;
  }
  else {
    /* XXX Should have an 'upload-append' call to make this atomic. */
    filesize = guestfs_filesize (g, path);
    if (filesize == -1)
      goto err;
    if (guestfs_upload_offset (g, tmpfile, path, filesize) == -1)
      goto err;
  }

  return 0;

 err:
  if (fd >= 0)
    close (fd);
  return -1;
}
开发者ID:rbuj,项目名称:libguestfs,代码行数:60,代码来源:file.c


示例10: guestfs___download_to_tmp

/* Download a guest file to a local temporary file.  The file is
 * cached in the temporary directory, and is not downloaded again.
 *
 * The name of the temporary (downloaded) file is returned.  The
 * caller must free the pointer, but does *not* need to delete the
 * temporary file.  It will be deleted when the handle is closed.
 *
 * Refuse to download the guest file if it is larger than max_size.
 * On this and other errors, NULL is returned.
 *
 * There is actually one cache per 'struct inspect_fs *' in order
 * to handle the case of multiple roots.
 */
char *
guestfs___download_to_tmp (guestfs_h *g, struct inspect_fs *fs,
                           const char *filename,
                           const char *basename, uint64_t max_size)
{
    char *r;
    int fd;
    char devfd[32];
    int64_t size;

    /* Make the basename unique by prefixing it with the fs number.
     * This also ensures there is one cache per filesystem.
     */
    if (asprintf (&r, "%s/%td-%s", g->tmpdir, fs - g->fses, basename) == -1) {
        perrorf (g, "asprintf");
        return NULL;
    }

    /* If the file has already been downloaded, return. */
    if (access (r, R_OK) == 0)
        return r;

    /* Check size of remote file. */
    size = guestfs_filesize (g, filename);
    if (size == -1)
        /* guestfs_filesize failed and has already set error in handle */
        goto error;
    if ((uint64_t) size > max_size) {
        error (g, _("size of %s is unreasonably large (%" PRIi64 " bytes)"),
               filename, size);
        goto error;
    }

    fd = open (r, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0600);
    if (fd == -1) {
        perrorf (g, "open: %s", r);
        goto error;
    }

    snprintf (devfd, sizeof devfd, "/dev/fd/%d", fd);

    if (guestfs_download (g, filename, devfd) == -1) {
        unlink (r);
        close (fd);
        goto error;
    }

    if (close (fd) == -1) {
        perrorf (g, "close: %s", r);
        unlink (r);
        goto error;
    }

    return r;

error:
    free (r);
    return NULL;
}
开发者ID:hacxman,项目名称:libguestfs,代码行数:72,代码来源:inspect.c


示例11: guestfs___send_file

/* Send a file.
 * Returns:
 *   0 OK
 *   -1 error
 *   -2 daemon cancelled (we must read the error message)
 */
int
guestfs___send_file (guestfs_h *g, const char *filename)
{
  char buf[GUESTFS_MAX_CHUNK_SIZE];
  int fd, r = 0, err;

  g->user_cancel = 0;

  fd = open (filename, O_RDONLY|O_CLOEXEC);
  if (fd == -1) {
    perrorf (g, "open: %s", filename);
    send_file_cancellation (g);
    return -1;
  }

  fadvise_sequential (fd);

  /* Send file in chunked encoding. */
  while (!g->user_cancel) {
    r = read (fd, buf, sizeof buf);
    if (r == -1 && (errno == EINTR || errno == EAGAIN))
      continue;
    if (r <= 0) break;
    err = send_file_data (g, buf, r);
    if (err < 0) {
      if (err == -2)		/* daemon sent cancellation */
        send_file_cancellation (g);
      close (fd);
      return err;
    }
  }

  if (r == -1) {
    perrorf (g, "read: %s", filename);
    send_file_cancellation (g);
    close (fd);
    return -1;
  }

  if (g->user_cancel) {
    error (g, _("operation cancelled by user"));
    g->last_errnum = EINTR;
    send_file_cancellation (g);
    close (fd);
    return -1;
  }

  /* End of file, but before we send that, we need to close
   * the file and check for errors.
   */
  if (close (fd) == -1) {
    perrorf (g, "close: %s", filename);
    send_file_cancellation (g);
    return -1;
  }

  return send_file_complete (g);
}
开发者ID:msmhrt,项目名称:libguestfs,代码行数:64,代码来源:proto.c


示例12: get_umask_from_fork

/**
 * Fallback method of getting the umask using fork.
 */
static int
get_umask_from_fork (guestfs_h *g)
{
  pid_t pid;
  int fd[2], r;
  int mask;
  int status;

  r = pipe2 (fd, O_CLOEXEC);
  if (r == -1) {
    perrorf (g, "pipe2");
    return -1;
  }

  pid = fork ();
  if (pid == -1) {
    perrorf (g, "fork");
    close (fd[0]);
    close (fd[1]);
    return -1;
  }
  if (pid == 0) {
    /* The child process must ONLY call async-safe functions. */
    close (fd[0]);

    /* umask can't fail. */
    mask = umask (0);

    if (write (fd[1], &mask, sizeof mask) != sizeof mask)
      _exit (EXIT_FAILURE);
    if (close (fd[1]) == -1)
      _exit (EXIT_FAILURE);

    _exit (EXIT_SUCCESS);
  }

  /* Parent. */
  close (fd[1]);

  /* Read the umask. */
  if (read (fd[0], &mask, sizeof mask) != sizeof mask) {
    perrorf (g, "read");
    close (fd[0]);
    guestfs_int_waitpid_noerror (pid);
    return -1;
  }
  close (fd[0]);

  if (guestfs_int_waitpid (g, pid, &status, "umask") == -1)
    return -1;
  else if (!WIFEXITED (status) || WEXITSTATUS (status) != 0) {
    guestfs_int_external_command_failed (g, status, "umask", NULL);
    return -1;
  }

  return mask;
}
开发者ID:Nemati,项目名称:libguestfs,代码行数:60,代码来源:umask.c


示例13: copy

int copy(char *dest, char *src)
{
	FILE *in, *out;
	int ret;
	char *actualdest = dest;

	if(samefile(dest, src)){
		eprintf("`%s' and `%s' are the same file", dest, src);
		return 1;
	}

	if(!(in = fopen(src, "r"))){
		perrorf("open (for read): `%s'", src);
		return 1;
	}

	/* TODO: make dir if it doesn't exist */
	if(!(out = fopen(dest, "w"))){
		if(errno == EISDIR){
			char *srcbase = strrchr(src, '/');

			if(!srcbase)
				srcbase = src;

			actualdest = alloca(strlen(dest) + strlen(srcbase) + 2);
			sprintf(actualdest, "%s/%s", dest, srcbase);

			if(samefile(actualdest, src)){
				eprintf("`%s' and `%s' are the same file", actualdest, src);
				fclose(in);
				return 1;
			}

			out = fopen(actualdest, "w");
			if(!out){
				perrorf("open (for write): `%s'", actualdest);
				fclose(in);
				return 1;
			}
		}else{
			perrorf("open (for write): `%s'", dest);
			fclose(in);
			return 1;
		}
	}

	ret = filecopy(in, out, actualdest, filelen(src));

	fclose(in);
	fclose(out);

	if(!i_am_cp && remove(src))
		perrorf("non-fatal: remove: `%s'", src);

	return ret;
}
开发者ID:bobrippling,项目名称:cbin,代码行数:56,代码来源:pcp.c


示例14: read_osinfo_db_three_levels

static int
read_osinfo_db_three_levels (guestfs_h *g, const char *directory)
{
  DIR *dir;
  int r;

  dir = opendir (directory);
  if (!dir) {
    debug (g, "osinfo: %s: %s", directory, strerror (errno));
    return 0; /* This is not an error: RHBZ#948324. */
  }

  debug (g, "osinfo: loading 3-level-directories database from %s", directory);

  for (;;) {
    struct dirent *d;
    CLEANUP_FREE char *pathname = NULL;
    struct stat sb;

    errno = 0;
    d = readdir (dir);
    if (!d) break;

    pathname = safe_asprintf (g, "%s/%s", directory, d->d_name);

    /* Iterate only on directories. */
    if (stat (pathname, &sb) == 0 && S_ISDIR (sb.st_mode)) {
      r = read_osinfo_db_directory (g, pathname);
      if (r == -1)
        goto error;
    }
  }

  /* Check for failure in readdir. */
  if (errno != 0) {
    perrorf (g, "readdir: %s", directory);
    goto error;
  }

  /* Close the directory handle. */
  r = closedir (dir);
  dir = NULL;
  if (r == -1) {
    perrorf (g, "closedir: %s", directory);
    goto error;
  }

  return 1;

 error:
  if (dir)
    closedir (dir);

  return -1;
}
开发者ID:noxdafox,项目名称:libguestfs,代码行数:55,代码来源:osinfo.c


示例15: read_whole_file

/* Read the whole file into a memory buffer and return it.  The file
 * should be a regular, local, trusted file.
 */
static int
read_whole_file (guestfs_h *g, const char *filename,
                 char **data_r, size_t *size_r)
{
  int fd;
  char *data;
  off_t size;
  off_t n;
  ssize_t r;
  struct stat statbuf;

  fd = open (filename, O_RDONLY|O_CLOEXEC);
  if (fd == -1) {
    perrorf (g, "open: %s", filename);
    return -1;
  }

  if (fstat (fd, &statbuf) == -1) {
    perrorf (g, "stat: %s", filename);
    close (fd);
    return -1;
  }

  size = statbuf.st_size;
  data = safe_malloc (g, size);

  n = 0;
  while (n < size) {
    r = read (fd, &data[n], size - n);
    if (r == -1) {
      perrorf (g, "read: %s", filename);
      free (data);
      close (fd);
      return -1;
    }
    if (r == 0) {
      error (g, _("read: %s: unexpected end of file"), filename);
      free (data);
      close (fd);
      return -1;
    }
    n += r;
  }

  if (close (fd) == -1) {
    perrorf (g, "close: %s", filename);
    free (data);
    return -1;
  }

  *data_r = data;
  *size_r = size;

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


示例16: read_osinfo_db_directory

static int
read_osinfo_db_directory (guestfs_h *g, const char *directory)
{
  DIR *dir;
  int r;

  dir = opendir (directory);
  if (!dir) {
    debug (g, "osinfo: %s: %s", directory, strerror (errno));
    return 0; /* This is not an error: RHBZ#948324. */
  }

  for (;;) {
    struct dirent *d;

    errno = 0;
    d = readdir (dir);
    if (!d) break;

    if (STRSUFFIX (d->d_name, ".xml")) {
      CLEANUP_FREE char *pathname = NULL;

      pathname = safe_asprintf (g, "%s/%s", directory, d->d_name);
      r = read_osinfo_db_xml (g, pathname);
      if (r == -1)
        goto error;
    }
  }

  /* Check for failure in readdir. */
  if (errno != 0) {
    perrorf (g, "readdir: %s", directory);
    goto error;
  }

  /* Close the directory handle. */
  r = closedir (dir);
  dir = NULL;
  if (r == -1) {
    perrorf (g, "closedir: %s", directory);
    goto error;
  }

  return 1;

 error:
  if (dir)
    closedir (dir);

  return -1;
}
开发者ID:noxdafox,项目名称:libguestfs,代码行数:51,代码来源:osinfo.c


示例17: run_qemu_img_info

static int
run_qemu_img_info (guestfs_h *g, const char *filename,
                   cmd_stdout_callback fn, void *data)
{
  char *abs_filename = NULL;
  char *safe_filename = NULL;
  struct command *cmd;
  int r;

  if (guestfs___lazy_make_tmpdir (g) == -1)
    return -1;

  safe_filename = safe_asprintf (g, "%s/format.%d", g->tmpdir, ++g->unique);

  /* 'filename' must be an absolute path so we can link to it. */
  abs_filename = realpath (filename, NULL);
  if (abs_filename == NULL) {
    perrorf (g, "realpath");
    goto error;
  }

  if (symlink (abs_filename, safe_filename) == -1) {
    perrorf (g, "symlink");
    goto error;
  }

  cmd = guestfs___new_command (g);
  guestfs___cmd_add_arg (cmd, "qemu-img");
  guestfs___cmd_add_arg (cmd, "info");
  guestfs___cmd_add_arg (cmd, safe_filename);
  guestfs___cmd_set_stdout_callback (cmd, fn, data, 0);
  r = guestfs___cmd_run (cmd);
  guestfs___cmd_close (cmd);
  if (r == -1)
    goto error;
  if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) {
    error (g, _("qemu-img: %s: child process failed"), filename);
    goto error;
  }

  free (safe_filename);
  free (abs_filename);
  return 0;

 error:
  free (safe_filename);
  free (abs_filename);

  return -1;
}
开发者ID:yumingfei,项目名称:libguestfs,代码行数:50,代码来源:info.c


示例18: set_nonblocking

void set_nonblocking(int fd) {
  int flags = 0;

  flags = fcntl(fd, F_GETFL, 0);
  if (flags == -1) {
    perrorf("fcntl(fd=%d)", fd);
    abort();
  }

  if (-1 == fcntl(fd, F_SETFL, flags | O_NONBLOCK)) {
    perrorf("fcntl(fd=%d)", fd);
    abort();
  }
}
开发者ID:mpage,项目名称:swarm,代码行数:14,代码来源:util.c


示例19: init_files

int init_files()
{
	snprintf(dir, PATH_LEN, "%s:%s", host, port);
	if(mkdir(dir, 0700)){
		if(errno == EEXIST){
			fprintf(stderr, "not overwriting %s\n", dir);
			return 2;
		}else{
			perror("mkdir()");
			return 1;
		}
		/* unreachable */
	}

	snprintf(file_input,   PATH_LEN, "%s/%s", dir, "in");
	snprintf(file_cmd,     PATH_LEN, "%s/%s", dir, "cmd");

	snprintf(file_output,  PATH_LEN, "%s/%s", dir, "out");
	snprintf(file_info,    PATH_LEN, "%s/%s", dir, "server");
	snprintf(file_clients, PATH_LEN, "%s/%s", dir, "clients");
	snprintf(file_err,     PATH_LEN, "%s/%s", dir, "err");


	if(mkfifo(file_input, 0600) == -1 && errno != EEXIST){
		perrorf("mkfifo(): %s: ", file_input);
		return 1; /* ya */
	}
	if(mkfifo(file_cmd, 0600) == -1 && errno != EEXIST){
		perrorf("mkfifo(): %s: ", file_cmd);
		goto bail;
	}

	if((fd_input = open(file_input, O_RDONLY | O_NONBLOCK, 0600)) == -1){
		perrorf("open(): %s: ", file_input);
		goto bail;
	}
	if((fd_cmd = open(file_cmd, O_RDONLY | O_NONBLOCK, 0600)) == -1){
		perrorf("open(): %s: ", file_cmd);
		close(fd_input);
		goto bail;
	}

	return 0;
bail:
	remove(file_input);
	remove(file_cmd);
	return 1;
}
开发者ID:bobrippling,项目名称:comm,代码行数:48,代码来源:fifo.c


示例20: nand_info

int nand_info(struct cmd_param *params)
{
	struct chip_param_io chip_params;
	int fd = -1, ret = 0;
	int block_size;
	off_t chip_size, media_size;
	const char *dev;

	if ((dev = param_get_string(params, "dev")) == NULL) {
		fprintf(stderr, "Please supply 'dev' parameter, eg. "
		    "'dev=/dev/gnand0'\n");
		return (1);
	}

	if ((fd = g_open(dev, 1)) == -1) {
		perrorf("Cannot open %s", dev);
		return (1);
	}

	if (ioctl(fd, NAND_IO_GET_CHIP_PARAM, &chip_params) == -1) {
		perrorf("Cannot ioctl(NAND_IO_GET_CHIP_PARAM)");
		ret = 1;
		goto out;
	}

	if (ioctl(fd, DIOCGMEDIASIZE, &media_size) == -1) {
		perrorf("Cannot ioctl(DIOCGMEDIASIZE)");
		ret = 1;
		goto out;
	}

	block_size = chip_params.page_size * chip_params.pages_per_block;
	chip_size = block_size * chip_params.blocks;

	printf("Device:\t\t\t%s\n", dev);
	printf("Page size:\t\t%d bytes\n", chip_params.page_size);
	printf("Block size:\t\t%d bytes (%d KB)\n", block_size,
	    block_size / 1024);
	printf("OOB size per page:\t%d bytes\n", chip_params.oob_size);
	printf("Chip size:\t\t%jd MB\n", (uintmax_t)(chip_size / 1024 / 1024));
	printf("Slice size:\t\t%jd MB\n",
	    (uintmax_t)(media_size / 1024 / 1024));

out:
	g_close(fd);

	return (ret);
}
开发者ID:2asoft,项目名称:freebsd,代码行数:48,代码来源:nand_info.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ persist_exists函数代码示例发布时间:2022-05-30
下一篇:
C++ perror_with_name函数代码示例发布时间: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