コード例 #1
0
ファイル: stream_public.c プロジェクト: viso89/public
static void clear_lost_client(int sindex)
{
	int cli ;
	for (cli = 0; cli < RH_MAX_CLIENTS; cli++)
	{
		if (!is_used(sindex, cli) && is_sock(sindex, cli))
		{
			close(get_sock(sindex, cli));
			set_sock(sindex, cli, INVALID_SOCKET);
		}
	}
}
コード例 #2
0
ファイル: wardrobe_question.cpp プロジェクト: DavieV/judge
int main(){
	std::map<std::string, int> clothes;
	std::string s;
	while(getline(std::cin, s)){
		if(clothes.find(s) == clothes.end())
			clothes[s] = 0;
		clothes[s]++;
	}
	for(auto i : clothes){
		if(is_sock(i.first)){
			int socks = i.second;
			std::cout << i.first << "|" << socks / 2 << std::endl;
			
		}
	}
	return 0;
}
コード例 #3
0
ファイル: ls.c プロジェクト: DanLipsitt/libguestfs
/* This is the function which is called to display all files and
 * directories, and it's where the magic happens.  We are called with
 * full stat and extended attributes for each file, so there is no
 * penalty for displaying anything in those structures.  However if we
 * need other things (eg. checksum) we may have to go back to the
 * appliance and then there can be a very large penalty.
 */
static int
show_file (const char *dir, const char *name,
           const struct guestfs_stat *stat,
           const struct guestfs_xattr_list *xattrs,
           void *unused)
{
  const char *filetype;
  CLEANUP_FREE char *path = NULL, *csum = NULL, *link = NULL;

  /* Display the basic fields. */
  output_start_line ();

  if (is_reg (stat->mode))
    filetype = "-";
  else if (is_dir (stat->mode))
    filetype = "d";
  else if (is_chr (stat->mode))
    filetype = "c";
  else if (is_blk (stat->mode))
    filetype = "b";
  else if (is_fifo (stat->mode))
    filetype = "p";
  else if (is_lnk (stat->mode))
    filetype = "l";
  else if (is_sock (stat->mode))
    filetype = "s";
  else
    filetype = "u";
  output_string (filetype);
  output_int64_perms (stat->mode & 07777);

  output_int64_size (stat->size);

  /* Display extra fields when enabled. */
  if (enable_uids) {
    output_int64_uid (stat->uid);
    output_int64_uid (stat->gid);
  }

  if (enable_times) {
    output_int64_time (stat->atime);
    output_int64_time (stat->mtime);
    output_int64_time (stat->ctime);
  }

  if (enable_extra_stats) {
    output_int64_dev (stat->dev);
    output_int64 (stat->ino);
    output_int64 (stat->nlink);
    output_int64_dev (stat->rdev);
    output_int64 (stat->blocks);
  }

  /* Disabled for now -- user would definitely want these to be interpreted.
  if (enable_xattrs)
    output_xattrs (xattrs);
  */

  path = full_path (dir, name);

  if (checksum && is_reg (stat->mode)) {
    csum = guestfs_checksum (g, checksum, path);
    if (!csum)
      exit (EXIT_FAILURE);

    output_string (csum);
  }

  output_string (path);

  if (is_lnk (stat->mode))
    /* XXX Fix this for NTFS. */
    link = guestfs_readlink (g, path);
  if (link)
    output_string_link (link);

  output_end_line ();

  return 0;
}
コード例 #4
0
ファイル: diff.c プロジェクト: kelledge/libguestfs
static void
output_file (guestfs_h *g, struct file *file)
{
    const char *filetype;
    size_t i;
    CLEANUP_FREE char *link = NULL;

    if (is_reg (file->stat->st_mode))
        filetype = "-";
    else if (is_dir (file->stat->st_mode))
        filetype = "d";
    else if (is_chr (file->stat->st_mode))
        filetype = "c";
    else if (is_blk (file->stat->st_mode))
        filetype = "b";
    else if (is_fifo (file->stat->st_mode))
        filetype = "p";
    else if (is_lnk (file->stat->st_mode))
        filetype = "l";
    else if (is_sock (file->stat->st_mode))
        filetype = "s";
    else
        filetype = "u";

    output_string (filetype);
    output_int64_perms (file->stat->st_mode & 07777);

    output_int64_size (file->stat->st_size);

    /* Display extra fields when enabled. */
    if (enable_uids) {
        output_int64_uid (file->stat->st_uid);
        output_int64_uid (file->stat->st_gid);
    }

    if (enable_times) {
        if (atime)
            output_int64_time (file->stat->st_atime_sec, file->stat->st_atime_nsec);
        output_int64_time (file->stat->st_mtime_sec, file->stat->st_mtime_nsec);
        output_int64_time (file->stat->st_ctime_sec, file->stat->st_ctime_nsec);
    }

    if (enable_extra_stats) {
        output_int64_dev (file->stat->st_dev);
        output_int64 (file->stat->st_ino);
        output_int64 (file->stat->st_nlink);
        output_int64_dev (file->stat->st_rdev);
        output_int64 (file->stat->st_blocks);
    }

    if (file->csum)
        output_string (file->csum);

    output_string (file->path);

    if (is_lnk (file->stat->st_mode)) {
        /* XXX Fix this for NTFS. */
        link = guestfs_readlink (g, file->path);
        if (link)
            output_string_link (link);
    }

    if (enable_xattrs) {
        for (i = 0; i < file->xattrs->len; ++i) {
            output_string (file->xattrs->val[i].attrname);
            output_binary (file->xattrs->val[i].attrval,
                           file->xattrs->val[i].attrval_len);
        }
    }
}