%% options copyright owner = Dirk Krause copyright year = 2015-xxxx license = bsd %% header /** @file File statistics (retrieve information from stat() and lstat() results). Note: The stat() and lstat() functions are sufficient for non-Windows systems. On Windows systems the st_dev and st_ino components may contain dummy contents, the stat structure does not contain information about symbolic links. For a portable (both Windows and non-Windows) check whether a file is a symbolic link, reparse point... use the dk4_file_info_t data type from dk4fileit.h and the functions from dk4filei.h. CRT on Windows: Required. */ #include "dk4statt.h" #ifndef DK4ERROR_H_INCLUDED #include "dk4error.h" #endif #ifdef __cplusplus extern "C" { #endif /** Check whether the file information is about a regular file. @param stb Stat buffer filled previously. @param erp Error report, may be NULL. @return 1 for regular file, 0 otherwise. */ int dk4stat_is_regular(const dk4_stat_t *stb, dk4_er_t *erp); /** Check whether the file information is about a directory. @param stb Stat buffer filled previously. @param erp Error report, may be NULL. @return 1 for regular file, 0 otherwise. */ int dk4stat_is_directory(const dk4_stat_t *stb, dk4_er_t *erp); /** Check whether the file information is about a symbolic link. @param stb Stat buffer filled previously. @param erp Error report, may be NULL. @return 1 for regular file, 0 otherwise. */ int dk4stat_is_symlink(const dk4_stat_t *stb, dk4_er_t *erp); /** Check whether the file information is about UNIX domain socket. @param stb Stat buffer filled previously. @param erp Error report, may be NULL. @return 1 for regular file, 0 otherwise. */ int dk4stat_is_unix_domain_socket(const dk4_stat_t *stb, dk4_er_t *erp); #ifdef __cplusplus } #endif %% module #include "dk4stat.h" #if DK4_CHAR_SIZE > 1 #include "dk4statw.h" #else #include "dk4stat8.h" #endif $!trace-include int dk4stat_is_regular(const dk4_stat_t *stb, dk4_er_t *erp) { int back = 0; if (NULL != stb) { #if DK4_ON_WINDOWS if (((stb->st_mode) & _S_IFMT) == _S_IFREG) { back = 1; } #else if (((stb->st_mode) & S_IFMT) == S_IFREG) { back = 1; } #endif } else { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } return back; } int dk4stat_is_directory(const dk4_stat_t *stb, dk4_er_t *erp) { int back = 0; if (NULL != stb) { #if DK4_ON_WINDOWS if (((stb->st_mode) & _S_IFMT) == _S_IFDIR) { back = 1; } #else if (((stb->st_mode) & S_IFMT) == S_IFDIR) { back = 1; } #endif } else { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } return back; } int dk4stat_is_symlink(const dk4_stat_t *stb, dk4_er_t *erp) { int back = 0; if (NULL != stb) { #if DK4_ON_WINDOWS #else #if defined(S_IFMT) && defined(S_IFLNK) if (S_IFLNK == ((stb->st_mode) & S_IFMT)) { back = 1; } #endif #endif } else { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } return back; } int dk4stat_is_unix_domain_socket(const dk4_stat_t *stb, dk4_er_t *erp) { int back = 0; if (NULL != stb) { #if DK4_ON_WINDOWS #else #if defined(S_IFMT) && defined(S_IFSOCK) if (S_IFSOCK == ((stb->st_mode) & S_IFMT)) { back = 1; } #endif #endif } else { dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); } return back; }