1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-06 09:26:44 +02:00

No longer require quotes to enclose paths

This commit is contained in:
jfreegman
2018-10-08 00:47:51 -04:00
parent b6c746b5f5
commit 56e03a3f8b
12 changed files with 111 additions and 97 deletions

View File

@ -481,6 +481,25 @@ bool file_exists(const char *path)
return stat(path, &s) == 0;
}
/* Returns 0 if path points to a directory.
* Returns 1 if path points to a regular file.
* Returns -1 on any other result.
*/
int file_type(const char *path)
{
struct stat s;
stat(path, &s);
switch (s.st_mode & S_IFMT) {
case S_IFDIR:
return 0;
case S_IFREG:
return 1;
default:
return -1;
}
}
/* returns file size. If file doesn't exist returns 0. */
off_t file_size(const char *path)
{