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
|
@ -372,7 +372,8 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
|
||||
fd = open (map[drive].device, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot open `%s' while attempting to get disk size", map[drive].device);
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("cannot open `%s': %s"),
|
||||
map[drive].device, strerror (errno));
|
||||
|
||||
disk->total_sectors = grub_util_get_fd_sectors (fd, map[drive].device,
|
||||
&disk->log_sector_size);
|
||||
|
@ -428,13 +429,19 @@ grub_util_follow_gpart_up (const char *name, grub_disk_addr_t *off_out, char **n
|
|||
|
||||
error = geom_gettree (&mesh);
|
||||
if (error != 0)
|
||||
/* TRANSLATORS: geom is the name of (k)FreeBSD device framework.
|
||||
Usually left untranslated.
|
||||
*/
|
||||
grub_util_error (_("couldn't open geom"));
|
||||
|
||||
LIST_FOREACH (class, &mesh.lg_class, lg_class)
|
||||
if (strcasecmp (class->lg_name, "part") == 0)
|
||||
break;
|
||||
if (!class)
|
||||
grub_util_error (_("couldn't open geom part"));
|
||||
/* TRANSLATORS: geom is the name of (k)FreeBSD device framework.
|
||||
Usually left untranslated.
|
||||
*/
|
||||
grub_util_error (_("couldn't find geom `part' class"));
|
||||
|
||||
LIST_FOREACH (geom, &class->lg_geom, lg_geom)
|
||||
{
|
||||
|
@ -563,12 +570,8 @@ devmapper_fail:
|
|||
fd = open (dev, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
# if !defined(HAVE_DIOCGDINFO)
|
||||
"cannot open `%s' while attempting to get disk geometry", dev);
|
||||
# else /* defined(HAVE_DIOCGDINFO) */
|
||||
"cannot open `%s' while attempting to get disk label", dev);
|
||||
# endif /* !defined(HAVE_DIOCGDINFO) */
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot open `%s': %s"),
|
||||
dev, strerror (errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -736,9 +739,8 @@ grub_util_fd_seek (int fd, const char *name, grub_uint64_t off)
|
|||
|
||||
offset = (loff_t) off;
|
||||
if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET))
|
||||
{
|
||||
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", name);
|
||||
}
|
||||
return grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot seek `%s': %s"),
|
||||
name, strerror (errno));
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
#else
|
||||
|
@ -748,7 +750,8 @@ grub_util_fd_seek (int fd, const char *name, grub_uint64_t off)
|
|||
off_t offset = (off_t) off;
|
||||
|
||||
if (lseek (fd, offset, SEEK_SET) != offset)
|
||||
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", name);
|
||||
return grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot seek `%s': %s"),
|
||||
name, strerror (errno));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -842,7 +845,8 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
|
|||
fd = open (dev, flags);
|
||||
if (fd < 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", dev);
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot open `%s': %s"),
|
||||
dev, strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -922,7 +926,8 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
|
|||
|
||||
if (fd < 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s' in open_device()", map[disk->id].device);
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot open `%s': %s"),
|
||||
map[disk->id].device, strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
#endif /* ! __linux__ */
|
||||
|
@ -1030,7 +1035,8 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
if (grub_util_fd_read (fd, buf, (1 << disk->log_sector_size))
|
||||
!= (1 << disk->log_sector_size))
|
||||
{
|
||||
grub_error (GRUB_ERR_READ_ERROR, "cannot read `%s'", map[disk->id].device);
|
||||
grub_error (GRUB_ERR_READ_ERROR, N_("cannot read `%s': %s"),
|
||||
map[disk->id].device, strerror (errno));
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
|
@ -1041,7 +1047,8 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
|
||||
if (grub_util_fd_read (fd, buf, size << disk->log_sector_size)
|
||||
!= (ssize_t) (size << disk->log_sector_size))
|
||||
grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id].device);
|
||||
grub_error (GRUB_ERR_READ_ERROR, N_("cannot read `%s': %s"),
|
||||
map[disk->id].device, strerror (errno));
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
@ -1075,7 +1082,8 @@ grub_util_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
|
||||
if (grub_util_fd_write (fd, buf, size << disk->log_sector_size)
|
||||
!= (ssize_t) (size << disk->log_sector_size))
|
||||
grub_error (GRUB_ERR_WRITE_ERROR, "cannot write to `%s'", map[disk->id].device);
|
||||
grub_error (GRUB_ERR_WRITE_ERROR, N_("cannot write to `%s': %s"),
|
||||
map[disk->id].device, strerror (errno));
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
@ -1172,7 +1180,11 @@ read_device_map (const char *dev_map)
|
|||
continue;
|
||||
|
||||
if (*p != '(')
|
||||
show_error (_("No open parenthesis found"));
|
||||
{
|
||||
char *tmp;
|
||||
tmp = xasprintf (_("missing `%c' symbol"), '(');
|
||||
show_error (tmp);
|
||||
}
|
||||
|
||||
p++;
|
||||
/* Find a free slot. */
|
||||
|
@ -1183,7 +1195,11 @@ read_device_map (const char *dev_map)
|
|||
e = p;
|
||||
p = strchr (p, ')');
|
||||
if (! p)
|
||||
show_error (_("No close parenthesis found"));
|
||||
{
|
||||
char *tmp;
|
||||
tmp = xasprintf (_("missing `%c' symbol"), ')');
|
||||
show_error (tmp);
|
||||
}
|
||||
|
||||
map[drive].drive = xmalloc (p - e + sizeof ('\0'));
|
||||
strncpy (map[drive].drive, e, p - e + sizeof ('\0'));
|
||||
|
@ -1196,7 +1212,7 @@ read_device_map (const char *dev_map)
|
|||
p++;
|
||||
|
||||
if (*p == '\0')
|
||||
show_error (_("No filename found"));
|
||||
show_error (_("filename expected"));
|
||||
|
||||
/* NUL-terminate the filename. */
|
||||
e = p;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <grub/mm.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
void *
|
||||
grub_malloc (grub_size_t size)
|
||||
|
@ -30,7 +31,7 @@ grub_malloc (grub_size_t size)
|
|||
void *ret;
|
||||
ret = malloc (size);
|
||||
if (!ret)
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -58,7 +59,7 @@ grub_realloc (void *ptr, grub_size_t size)
|
|||
void *ret;
|
||||
ret = realloc (ptr, size);
|
||||
if (!ret)
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -77,11 +78,11 @@ grub_memalign (grub_size_t align, grub_size_t size)
|
|||
#else
|
||||
(void) align;
|
||||
(void) size;
|
||||
grub_util_error (_("grub_memalign is not supported"));
|
||||
grub_util_error (_("grub_memalign is not supported on your system"));
|
||||
#endif
|
||||
|
||||
if (!p)
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
|
||||
return p;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue