source: grub-pc/trunk/fuentes/grub-core/kern/emu/misc.c @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 2.9 KB
Line 
1/*
2 *  GRUB  --  GRand Unified Bootloader
3 *  Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010  Free Software Foundation, Inc.
4 *
5 *  GRUB is free software: you can redistribute it and/or modify
6 *  it under the terms of the GNU General Public License as published by
7 *  the Free Software Foundation, either version 3 of the License, or
8 *  (at your option) any later version.
9 *
10 *  GRUB is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 *  GNU General Public License for more details.
14 *
15 *  You should have received a copy of the GNU General Public License
16 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <config-util.h>
20#include <config.h>
21
22#include <errno.h>
23#include <error.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <stdint.h>
27#include <string.h>
28#include <sys/time.h>
29#include <sys/types.h>
30
31#include <grub/mm.h>
32#include <grub/err.h>
33#include <grub/env.h>
34#include <grub/types.h>
35#include <grub/misc.h>
36#include <grub/i18n.h>
37#include <grub/time.h>
38#include <grub/emu/misc.h>
39
40int verbosity;
41
42void
43grub_util_warn (const char *fmt, ...)
44{
45  va_list ap;
46
47  fprintf (stderr, _("%s: warning:"), program_name);
48  fprintf (stderr, " ");
49  va_start (ap, fmt);
50  vfprintf (stderr, fmt, ap);
51  va_end (ap);
52  fprintf (stderr, ".\n");
53  fflush (stderr);
54}
55
56void
57grub_util_info (const char *fmt, ...)
58{
59  if (verbosity > 0)
60    {
61      va_list ap;
62
63      fprintf (stderr, _("%s: info:"), program_name);
64      fprintf (stderr, " ");
65      va_start (ap, fmt);
66      vfprintf (stderr, fmt, ap);
67      va_end (ap);
68      fprintf (stderr, ".\n");
69      fflush (stderr);
70    }
71}
72
73void
74grub_util_error (const char *fmt, ...)
75{
76  va_list ap;
77
78  fprintf (stderr, _("%s: error:"), program_name);
79  fprintf (stderr, " ");
80  va_start (ap, fmt);
81  vfprintf (stderr, fmt, ap);
82  va_end (ap);
83  fprintf (stderr, ".\n");
84  exit (1);
85}
86
87void *
88xmalloc (grub_size_t size)
89{
90  void *p;
91
92  p = malloc (size);
93  if (! p)
94    grub_util_error ("%s", _("out of memory"));
95
96  return p;
97}
98
99void *
100xrealloc (void *ptr, grub_size_t size)
101{
102  ptr = realloc (ptr, size);
103  if (! ptr)
104    grub_util_error ("%s", _("out of memory"));
105
106  return ptr;
107}
108
109char *
110xstrdup (const char *str)
111{
112  size_t len;
113  char *newstr;
114
115  len = strlen (str);
116  newstr = (char *) xmalloc (len + 1);
117  memcpy (newstr, str, len + 1);
118
119  return newstr;
120}
121
122#if !defined (GRUB_MKFONT) && !defined (GRUB_BUILD)
123char *
124xasprintf (const char *fmt, ...)
125{ 
126  va_list ap;
127  char *result;
128 
129  va_start (ap, fmt);
130  result = grub_xvasprintf (fmt, ap);
131  if (!result)
132    grub_util_error ("%s", _("out of memory"));
133 
134  return result;
135}
136#endif
137
138void
139grub_exit (void)
140{
141  exit (1);
142}
143
144grub_uint64_t
145grub_get_time_ms (void)
146{
147  struct timeval tv;
148
149  gettimeofday (&tv, 0);
150
151  return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
152}
Note: See TracBrowser for help on using the repository browser.