
Założenia: programowi podajemy jako parametr nazwę katalogu. Program po stwierdzeniu czy to naprawdę katalog robi "coś" (w tym momencie nieważne co), jeśli nie - wypisuje komunikat błędu i kończy pracę sygnalizując błąd.
Błąd należy znaleźć wyłącznie czytając kod ew. kompilując program, bez jego uruchamiania.
Kod: Zaznacz cały
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int test_dir(char *path)
{
struct stat st;
if (stat(path,&st) || !S_ISDIR(st.st_mode)) {
return 0;
}
return -1;
}
int main(int argc,char *argv[])
{
if (argc != 2) {
fprintf(stderr,"%s: %s\n",argv[0],strerror(EINVAL));
exit(1);
}
if (!test_dir(argv[1])) {
perror(argv[1]);
exit(1);
}
printf("Dobra, to jest katalog\n");
/* i tu reszta kodu */
return 0;
}
