File type checking

Functions


FMC_dirExists

int FMC_dirExists(const char* restrict path); 
if (FMC_dirExists("test/main.c"))
{
    FILE *src_file = fopen("test/main.c", "rb");
    // do something with it
}
else
{

}
    // ...
char directory[128] = "C:\\Users\\YourFolder\\";
if (FMC_dirExists(directory))
{
    printf("Entering directory %s\n", directory);
    // ...
}
else
    // ...

Parameters

path : the path whose you want to check the existence. The file can either be a regular file, a directory, or any valid device, socket... Multi-byte caracters are not supported.

Return value

The function returns non-zero value if the path effectively exists, 0 otherwise.

Description

You can use this function on any POSIX-compliant system or Windows. The Windows version uses the Win32 filesystem API and thus does not require any particular compiler. The Unix version uses the usual stat function.


FMC_isDir

int FMC_isDir(const char* restrict path);
if(FMC_isDir("/home/you/random_folder/") == 0) 
{
    DIR *your_dir;
    struct dirent *entries;
    your_dir = opendir("/home/you/random_folder/");
    while((entries = readdir(your_dir)) != NULL)
    {
        printf("%s\n", entries->d_name);
    }
    closedir(your_dir);
    // ... (1)!
}
  1. This example is not that usefull by itself since you could have checked your_dir != NULL after it has been opened, but the whole interest is the fact that it's a portable and simple way to check for a dir.

Parameters

path : the path whose you want to check if it's a directory. Multi-byte caracters are not supported.

Return value

The function returns non-zero value if the path is a directory, 0 otherwise.

Description

You can use this function on any POSIX-compliant system or Windows. The Windows version uses the Win32 filesystem API and thus does not require any particular compiler. The Unix version uses the usual stat function.

FMC_isRegFile

int FMC_isRegFile(const char* restrict path);
// To be done

Parameters

path : the path whose you want to check if it's a regular file. Multi-byte characters are not supported.

Return value

The function returns non-zero value if the path is a regular file, 0 otherwise.

Description

You can use this function on any POSIX-compliant system or Windows. The Windows version uses the Win32 filesystem API and thus does not require any particular compiler. The Unix version uses the usual stat function.

FMC_isCharDevice

To be done

FMC_isSocket

int FMC_isSymLink(const char *path);
// To be done

FMC_isBlock

int FMC_isBlock(const char* path);
// To be done