new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
28
Task/Check-that-file-exists/C/check-that-file-exists.c
Normal file
28
Task/Check-that-file-exists/C/check-that-file-exists.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Check for regular file. */
|
||||
int check_reg(const char *path) {
|
||||
struct stat sb;
|
||||
return stat(path, &sb) == 0 && S_ISREG(sb.st_mode);
|
||||
}
|
||||
|
||||
/* Check for directory. */
|
||||
int check_dir(const char *path) {
|
||||
struct stat sb;
|
||||
return stat(path, &sb) == 0 && S_ISDIR(sb.st_mode);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("input.txt is a regular file? %s\n",
|
||||
check_reg("input.txt") ? "yes" : "no");
|
||||
printf("docs is a directory? %s\n",
|
||||
check_dir("docs") ? "yes" : "no");
|
||||
printf("/input.txt is a regular file? %s\n",
|
||||
check_reg("/input.txt") ? "yes" : "no");
|
||||
printf("/docs is a directory? %s\n",
|
||||
check_dir("/docs") ? "yes" : "no");
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue