Exemple #1
0
/**
 * \brief Print on standard out the -ls arguments: number of i-nodes,blocks, permissions,
 number of links, owner, group, last modification time and directory name.
 symlinks.
 *
 * \param file_info with all file attributes read out from operating system.
 *
 * \return void
 **/
static void combine_ls(const StatType* file_info)
{
    int written = 0;

    /* Print i-node */
    written = fprintf(stdout, "%6lu", (unsigned long) file_info->st_ino);
    if (written < 0)
    {
        print_error(strerror(errno));
    }

    /* Print number of blocks */
    /* magic number divide by 2 depends on block size of file system.
     * The st_blocks member of the stat structure returns:
     * The total number of physical blocks of size 512 bytes actually allocated on disk.
       see also http://stackoverflow.com/questions/1346807/how-does-stat-command-calculate-the-blocks-of-a-file
    */
    written = fprintf(stdout, "%5lu ", (unsigned long) file_info->st_blocks / 2);
    if (written < 0)
    {
        print_error(strerror(errno));
    }

    print_file_permissions(file_info);

    /* Print number of hard links */
    written = fprintf(stdout, "%2lu", (unsigned long) file_info->st_nlink);
    if (written < 0)
    {
        print_error(strerror(errno));
    }

    print_user_group(file_info);

    /* Print file size */
    written = fprintf(stdout, "%13lu ", (unsigned long) file_info->st_size);
    if (written < 0)
    {
        print_error(strerror(errno));
    }

    print_file_change_time(file_info);
}
Exemple #2
0
void print_file_info (const const char * filename)
{
	struct stat buf;

	//获取文件的stat结构
	stat (filename, &buf);

	//打印出文件类型
	print_file_mode (buf);
	   

	//打印储存权限
	print_file_permissions (buf);

	//打印数目
	printf (" ");
	print_file_nlink (buf);	

	//打印文件从属
	printf (" ");
	print_file_bt_user (buf);
	printf (" ");
	print_file_bt_grp (buf);

	//打印文件大小
	printf (" ");
	print_file_size (buf);

	//打印时间
	printf(" ");
	print_file_mtime (buf);
	
	//打印文件名
	printf (" ");
	
	print_file_name((char *)filename);
	printf ("\n");
}