Rewrite grub-install, grub-mkrescue, grub-mkstandalone and grub-mknetdir

the function of these files exceeds what can be sanely handled in shell
	in posix-comaptible way. Also writing it in C extends the functionality
	to non-UNIX-like OS and minimal environments.
This commit is contained in:
Vladimir Serbinenko 2013-11-16 20:21:16 +01:00
parent 9ef81064a3
commit cd46aa6cef
52 changed files with 5811 additions and 2101 deletions

View file

@ -246,6 +246,17 @@ grub_util_is_regular (const char *path)
return S_ISREG (st.st_mode);
}
grub_uint32_t
grub_util_get_mtime (const char *path)
{
struct stat st;
if (stat (path, &st) == -1)
return 0;
return st.st_mtime;
}
int
grub_util_is_special_file (const char *path)
{
@ -256,4 +267,39 @@ grub_util_is_special_file (const char *path)
return (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode));
}
char *
grub_util_make_temporary_file (void)
{
const char *t = getenv ("TMPDIR");
size_t tl;
char *tmp;
if (!t)
t = "/tmp";
tl = strlen (t);
tmp = xmalloc (tl + sizeof ("/grub.XXXXXX"));
memcpy (tmp, t, tl);
memcpy (tmp + tl, "/grub.XXXXXX",
sizeof ("/grub.XXXXXX"));
mkstemp (tmp);
return tmp;
}
char *
grub_util_make_temporary_dir (void)
{
const char *t = getenv ("TMPDIR");
size_t tl;
char *tmp;
if (!t)
t = "/tmp";
tl = strlen (t);
tmp = xmalloc (tl + sizeof ("/grub.XXXXXX"));
memcpy (tmp, t, tl);
memcpy (tmp + tl, "/grub.XXXXXX",
sizeof ("/grub.XXXXXX"));
mkdtemp (tmp);
return tmp;
}
#endif