module_01.c 730 B

123456789101112131415161718192021222324252627
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <errno.h>
  5. #include <sys/stat.h>
  6. #define BOLD_GRAY "\033[1;90m"
  7. #define RED "\033[0;31m"
  8. #define WHITE "\033[0;37m"
  9. #define RESET "\033[0m"
  10. int module_01_run(const char *filename) {
  11. char log_msg[1024];
  12. struct stat st;
  13. if (stat(filename, &st) != 0) {
  14. snprintf(log_msg, sizeof(log_msg), BOLD_GRAY " Main: " RED "Cannot stat file: %s" RESET, strerror(errno));
  15. printf("%s\n", log_msg);
  16. return 1;
  17. }
  18. int is_regular = S_ISREG(st.st_mode);
  19. snprintf(log_msg, sizeof(log_msg), BOLD_GRAY " Main: " WHITE "File is %s" RESET, is_regular ? "regular file" : "not a regular file");
  20. printf("%s\n", log_msg);
  21. return 0;
  22. }