Improve gettext support. Stylistic fixes and error handling fixes while
on it.
This commit is contained in:
parent
215c90cb82
commit
9c4b5c13e6
184 changed files with 1175 additions and 959 deletions
|
@ -21,8 +21,10 @@
|
|||
#include <grub/file.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/util/misc.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
|
@ -54,6 +56,12 @@ is_dir (const char *path, const char *name)
|
|||
return S_ISDIR (st.st_mode);
|
||||
}
|
||||
|
||||
struct grub_hostfs_data
|
||||
{
|
||||
char *filename;
|
||||
FILE *f;
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
grub_hostfs_dir (grub_device_t device, const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
|
@ -68,7 +76,8 @@ grub_hostfs_dir (grub_device_t device, const char *path,
|
|||
dir = opendir (path);
|
||||
if (! dir)
|
||||
return grub_error (GRUB_ERR_BAD_FILENAME,
|
||||
"can't open the hostfs directory `%s'", path);
|
||||
N_("can't open `%s': %s"), path,
|
||||
strerror (errno));
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -95,12 +104,30 @@ static grub_err_t
|
|||
grub_hostfs_open (struct grub_file *file, const char *name)
|
||||
{
|
||||
FILE *f;
|
||||
struct grub_hostfs_data *data;
|
||||
|
||||
f = fopen (name, "rb");
|
||||
if (! f)
|
||||
return grub_error (GRUB_ERR_BAD_FILENAME,
|
||||
"can't open `%s'", name);
|
||||
file->data = f;
|
||||
N_("can't open `%s': %s"), name,
|
||||
strerror (errno));
|
||||
data = grub_malloc (sizeof (*data));
|
||||
if (!data)
|
||||
{
|
||||
fclose (f);
|
||||
return grub_errno;
|
||||
}
|
||||
data->filename = grub_strdup (name);
|
||||
if (!data->filename)
|
||||
{
|
||||
grub_free (data);
|
||||
fclose (f);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
data->f = f;
|
||||
|
||||
file->data = data;
|
||||
|
||||
#ifdef __MINGW32__
|
||||
file->size = grub_util_get_disk_size (name);
|
||||
|
@ -116,18 +143,20 @@ grub_hostfs_open (struct grub_file *file, const char *name)
|
|||
static grub_ssize_t
|
||||
grub_hostfs_read (grub_file_t file, char *buf, grub_size_t len)
|
||||
{
|
||||
FILE *f;
|
||||
struct grub_hostfs_data *data;
|
||||
|
||||
f = (FILE *) file->data;
|
||||
if (fseeko (f, file->offset, SEEK_SET) != 0)
|
||||
data = file->data;
|
||||
if (fseeko (data->f, file->offset, SEEK_SET) != 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_RANGE, "fseeko: %s", strerror (errno));
|
||||
grub_error (GRUB_ERR_OUT_OF_RANGE, N_("cannot seek `%s': %s"),
|
||||
data->filename, strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned int s = fread (buf, 1, len, f);
|
||||
unsigned int s = fread (buf, 1, len, data->f);
|
||||
if (s != len)
|
||||
grub_error (GRUB_ERR_FILE_READ_ERROR, "fread: %s", strerror (errno));
|
||||
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("cannot read `%s': %s"),
|
||||
data->filename, strerror (errno));
|
||||
|
||||
return (signed) s;
|
||||
}
|
||||
|
@ -136,9 +165,12 @@ static grub_err_t
|
|||
grub_hostfs_close (grub_file_t file)
|
||||
{
|
||||
FILE *f;
|
||||
struct grub_hostfs_data *data;
|
||||
|
||||
f = (FILE *) file->data;
|
||||
fclose (f);
|
||||
data = file->data;
|
||||
fclose (data->f);
|
||||
grub_free (data->filename);
|
||||
grub_free (data);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue