~ubuntu-branches/ubuntu/trusty/grub2/trusty

« back to all changes in this revision

Viewing changes to util/editenv.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-01-16 15:18:04 UTC
  • mfrom: (17.6.38 experimental)
  • Revision ID: package-import@ubuntu.com-20140116151804-3foouk7fpqcq3sxx
Tags: 2.02~beta2-2
* Convert patch handling to git-dpm.
* Add bi-endian support to ELF parser (Tomohiro B Berry).
* Adjust restore_mkdevicemap.patch to mark get_kfreebsd_version as static,
  to appease "gcc -Werror=missing-prototypes".
* Cherry-pick from upstream:
  - Change grub-macbless' manual page section to 8.
* Install grub-glue-efi, grub-macbless, grub-render-label, and
  grub-syslinux2cfg.
* grub-shell: Pass -no-pad to xorriso when building floppy images.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* editenv.c - tool to edit environment block.  */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2008,2009,2010,2013 Free Software Foundation, Inc.
 
5
 *
 
6
 *  GRUB is free software: you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation, either version 3 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  GRUB is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include <config.h>
 
21
#include <grub/types.h>
 
22
#include <grub/emu/misc.h>
 
23
#include <grub/util/misc.h>
 
24
#include <grub/util/install.h>
 
25
#include <grub/lib/envblk.h>
 
26
#include <grub/i18n.h>
 
27
#include <grub/emu/hostfile.h>
 
28
 
 
29
#include <errno.h>
 
30
#include <string.h>
 
31
 
 
32
#define DEFAULT_ENVBLK_SIZE     1024
 
33
 
 
34
void
 
35
grub_util_create_envblk_file (const char *name)
 
36
{
 
37
  FILE *fp;
 
38
  char *buf;
 
39
  char *namenew;
 
40
 
 
41
  buf = xmalloc (DEFAULT_ENVBLK_SIZE);
 
42
 
 
43
  namenew = xasprintf ("%s.new", name);
 
44
  fp = grub_util_fopen (namenew, "wb");
 
45
  if (! fp)
 
46
    grub_util_error (_("cannot open `%s': %s"), namenew,
 
47
                     strerror (errno));
 
48
 
 
49
  memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
 
50
  memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#',
 
51
          DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) + 1);
 
52
 
 
53
  if (fwrite (buf, 1, DEFAULT_ENVBLK_SIZE, fp) != DEFAULT_ENVBLK_SIZE)
 
54
    grub_util_error (_("cannot write to `%s': %s"), namenew,
 
55
                     strerror (errno));
 
56
 
 
57
 
 
58
  grub_util_file_sync (fp);
 
59
  free (buf);
 
60
  fclose (fp);
 
61
 
 
62
  if (grub_util_rename (namenew, name) < 0)
 
63
    grub_util_error (_("cannot rename the file %s to %s"), namenew, name);
 
64
  free (namenew);
 
65
}