69,368
社区成员
发帖
与我相关
我的任务
分享
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#define ERR_EXIT(m) \
do \
{ \
perror(m); \
exit(EXIT_FAILURE); \
}while(0)
#define MAJOR(a) (int)((unsigned short)a >> 8)
#define MINOR(a) (int)((unsigned short)a & 0xFF)
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr, "Usage %s file\n", argv[0]);
exit(EXIT_FAILURE);
}
struct stat sbuf;
printf("File name: %s\n", argv[1]);
if (stat(argv[1], &sbuf) == -1)
ERR_EXIT("stat error");
printf("File number:major %d,minor %d\n", MAJOR(sbuf.st_dev), MINOR(sbuf.st_dev));
return 0;
}