Cześć,
mam taki kod:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <pwd.h>
#include <grp.h>
void show_stat_info(char *fname, struct stat *buf);
void show_nice_stat_info(char *fname, struct stat *buf);
void mode_translator(mode_t mode, char* str);
int main(int argc, char *argv[]) {
struct stat info;
if (argc > 1) {
if (stat(argv[1], &info) != -1) {
show_nice_stat_info(argv[1], &info);
return 0;
} else {
printf("Nie znaleziono pliku %s\n", argv[1]);
}
} else {
printf("Uzycie: %s nazwa_pliku\n", argv[0]);
}
return 1;
}
void show_stat_info(char *fname, struct stat *buf) {
printf(" mode: %o\n", buf->st_mode); /* type + mode */
printf(" links: %d\n", buf->st_nlink); /* # links */
printf(" user: %d\n", buf->st_uid); /* user id */
printf(" group: %d\n", buf->st_gid); /* group id */
printf(" size: %ld\n", buf->st_size); /* file size */
printf("accesst: %ld\n", buf->st_atim); /* actualized */
printf("modtime: %ld\n", buf->st_mtim); /* modified */
printf("changed: %ld\n", buf->st_ctim); /* changed */
}
void show_nice_stat_info(char *fname, struct stat *buf) {
printf("File name: %s\n", fname);
if (S_ISDIR(buf->st_mode)) {
printf("File type: directory\n");
} else if (S_ISLNK(buf->st_mode)) {
printf("File type: link\n");
} else if (S_ISREG(buf->st_mode)) {
printf("File type: normal\n");
} else {
printf("File type: unknow\n");
}
char mode[9];
mode_translator(buf->st_mode, mode);
printf("Mode: %s (%o)\n", mode, buf->st_mode);
printf("Links: %d\n", buf->st_nlink); /* # links */
struct passwd *user_info = getpwuid(buf->st_uid);
printf("UID: %s (%d)\n", user_info->pw_name, buf->st_uid); /* user id */
struct group *group_info = getgrgid(buf->st_gid);
printf("GID: %s (%d)\n", group_info->gr_name, buf->st_gid); /* group id */
printf("Size: %ld\n", buf->st_size); /* file size */
printf("Accesed: %ld\n", buf->st_atim); /* actualized */
printf("Modified: %ld\n", buf->st_mtim); /* modified */
printf("Changed: %ld\n", buf->st_ctim); /* changed */
}
void mode_translator(mode_t mode, char* str) {
strcpy(str, "--------");
if (mode & S_IRUSR) str[0] = 'r';
if (mode & S_IWUSR) str[1] = 'w';
if (mode & S_IXUSR) str[2] = 'x';
if (mode & S_IRGRP) str[3] = 'r';
if (mode & S_IWGRP) str[4] = 'w';
if (mode & S_IXGRP) str[5] = 'x';
if (mode & S_IROTH) str[6] = 'r';
if (mode & S_IWOTH) str[7] = 'w';
if (mode & S_IXOTH) str[8] = 'x';
}
I gdy kompiluję to z -Wallem to dostaję:
@ubuntu:~/Lab3/Zad2$ gcc -Wall Zad2.c -o Zad2
Zad2.c: In function ‘show_stat_info’:
Zad2.c:34:5: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘struct timespec’ [-Wformat=]
printf("accesst: %ld\n", buf->st_atim); /* actualized */
^
Zad2.c:35:5: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘struct timespec’ [-Wformat=]
printf("modtime: %ld\n", buf->st_mtim); /* modified */
^
Zad2.c:36:5: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘struct timespec’ [-Wformat=]
printf("changed: %ld\n", buf->st_ctim); /* changed */
^
Zad2.c: In function ‘show_nice_stat_info’:
Zad2.c:65:5: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘struct timespec’ [-Wformat=]
printf("Accesed: %ld\n", buf->st_atim); /* actualized */
^
Zad2.c:66:5: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘struct timespec’ [-Wformat=]
printf("Modified: %ld\n", buf->st_mtim); /* modified */
^
Zad2.c:67:5: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘struct timespec’ [-Wformat=]
printf("Changed: %ld\n", buf->st_ctim); /* changed */
^
Pomoże ktoś usunąć te warningi? :(