Define grub_util_is_directory/regular/special_file and
use OS-dependent versions rather than to rely on stat().
This commit is contained in:
parent
ec16e02639
commit
df1e64c98e
6 changed files with 113 additions and 31 deletions
|
@ -30,11 +30,8 @@
|
|||
#include <grub/emu/hostdisk.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
|
||||
static int
|
||||
|
@ -52,10 +49,7 @@ is_dir (const char *path, const char *name)
|
|||
|
||||
strcat (pathname, name);
|
||||
|
||||
struct stat st;
|
||||
if (stat (pathname, &st))
|
||||
return 0;
|
||||
return S_ISDIR (st.st_mode);
|
||||
return grub_util_is_directory (pathname);
|
||||
}
|
||||
|
||||
struct grub_hostfs_data
|
||||
|
|
|
@ -216,4 +216,36 @@ grub_util_fopen (const char *path, const char *mode)
|
|||
return fopen (path, mode);
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_directory (const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat (path, &st) == -1)
|
||||
return 0;
|
||||
|
||||
return S_ISDIR (st.st_mode);
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_regular (const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat (path, &st) == -1)
|
||||
return 0;
|
||||
|
||||
return S_ISREG (st.st_mode);
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_special_file (const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (lstat (path, &st) == -1)
|
||||
return 1;
|
||||
return (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -410,6 +410,39 @@ grub_util_unlink (const char *name)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_directory (const char *name)
|
||||
{
|
||||
LPTSTR name_windows;
|
||||
DWORD attr;
|
||||
|
||||
name_windows = grub_util_get_windows_path (name);
|
||||
if (!name_windows)
|
||||
return 0;
|
||||
|
||||
attr = GetFileAttributes (name_windows);
|
||||
grub_free (name_windows);
|
||||
|
||||
return !!(attr & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_regular (const char *name)
|
||||
{
|
||||
LPTSTR name_windows;
|
||||
DWORD attr;
|
||||
|
||||
name_windows = grub_util_get_windows_path (name);
|
||||
if (!name_windows)
|
||||
return 0;
|
||||
|
||||
attr = GetFileAttributes (name_windows);
|
||||
grub_free (name_windows);
|
||||
|
||||
return !(attr & FILE_ATTRIBUTE_DIRECTORY)
|
||||
&& !(attr & FILE_ATTRIBUTE_REPARSE_POINT) && attr;
|
||||
}
|
||||
|
||||
#ifdef __MINGW32__
|
||||
|
||||
FILE *
|
||||
|
@ -438,6 +471,22 @@ int fsync (int fno)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_special_file (const char *name)
|
||||
{
|
||||
LPTSTR name_windows;
|
||||
DWORD attr;
|
||||
|
||||
name_windows = grub_util_get_windows_path (name);
|
||||
if (!name_windows)
|
||||
return 1;
|
||||
|
||||
attr = GetFileAttributes (name_windows);
|
||||
grub_free (name_windows);
|
||||
|
||||
return !!(attr & FILE_ATTRIBUTE_REPARSE_POINT) || !attr;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
FILE *
|
||||
|
@ -446,4 +495,14 @@ grub_util_fopen (const char *path, const char *mode)
|
|||
return fopen (path, mode);
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_is_special_file (const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (lstat (destnew, &st) == -1)
|
||||
return 1;
|
||||
return (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue