38
39
# define ATTRIBUTE_ERROR(msg) \
39
40
__attribute__ ((__error__ (msg)))
41
# define ATTRIBUTE_ERROR(msg)
42
# define ATTRIBUTE_ERROR(msg) __attribute__ ((noreturn))
44
45
#define ALIGN_UP(addr, align) \
45
46
((addr + (typeof (addr)) align - 1) & ~((typeof (addr)) align - 1))
47
#define ALIGN_UP_OVERHEAD(addr, align) ((-(addr)) & ((typeof (addr)) (align) - 1))
46
48
#define ALIGN_DOWN(addr, align) \
47
49
((addr) & ~((typeof (addr)) align - 1))
48
50
#define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0]))
49
51
#define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; }
51
53
#define grub_dprintf(condition, fmt, args...) grub_real_dprintf(GRUB_FILE, __LINE__, condition, fmt, ## args)
52
/* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */
53
#define grub_memcpy(d,s,n) grub_memmove ((d), (s), (n))
55
55
void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n);
56
56
char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src);
57
57
char *EXPORT_FUNC(grub_strncpy) (char *dest, const char *src, int c);
58
char *EXPORT_FUNC(grub_stpcpy) (char *dest, const char *src);
59
grub_stpcpy (char *dest, const char *src)
71
/* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */
73
grub_memcpy (void *dest, const void *src, grub_size_t n)
75
return grub_memmove (dest, src, n);
60
78
static inline char *
61
79
grub_strcat (char *dest, const char *src)
96
114
/* Prototypes for aliases. */
117
int __attribute__ ((regparm(0))) EXPORT_FUNC(memcmp) (const void *s1, const void *s2, grub_size_t n);
118
void *__attribute__ ((regparm(0))) EXPORT_FUNC(memmove) (void *dest, const void *src, grub_size_t n);
119
void *__attribute__ ((regparm(0))) EXPORT_FUNC(memcpy) (void *dest, const void *src, grub_size_t n);
120
void *__attribute__ ((regparm(0))) EXPORT_FUNC(memset) (void *s, int c, grub_size_t n);
98
122
int EXPORT_FUNC(memcmp) (const void *s1, const void *s2, grub_size_t n);
99
123
void *EXPORT_FUNC(memmove) (void *dest, const void *src, grub_size_t n);
100
124
void *EXPORT_FUNC(memcpy) (void *dest, const void *src, grub_size_t n);
101
125
void *EXPORT_FUNC(memset) (void *s, int c, grub_size_t n);
104
129
int EXPORT_FUNC(grub_memcmp) (const void *s1, const void *s2, grub_size_t n);
105
130
int EXPORT_FUNC(grub_strcmp) (const char *s1, const char *s2);
108
133
char *EXPORT_FUNC(grub_strchr) (const char *s, int c);
109
134
char *EXPORT_FUNC(grub_strrchr) (const char *s, int c);
110
135
int EXPORT_FUNC(grub_strword) (const char *s, const char *w);
111
char *EXPORT_FUNC(grub_strstr) (const char *haystack, const char *needle);
137
/* Copied from gnulib.
138
Written by Bruno Haible <bruno@clisp.org>, 2005. */
140
grub_strstr (const char *haystack, const char *needle)
142
/* Be careful not to look at the entire extent of haystack or needle
143
until needed. This is useful because of these two cases:
144
- haystack may be very long, and a match of needle found early,
145
- needle may be very long, and not even a short initial segment of
146
needle may be found in haystack. */
149
/* Speed up the following searches of needle by caching its first
155
if (*haystack == '\0')
159
/* The first character matches. */
161
const char *rhaystack = haystack + 1;
162
const char *rneedle = needle;
164
for (;; rhaystack++, rneedle++)
166
if (*rneedle == '\0')
168
return (char *) haystack;
169
if (*rhaystack == '\0')
172
if (*rhaystack != *rneedle)
173
/* Nothing in this round. */
180
return (char *) haystack;
112
183
int EXPORT_FUNC(grub_isspace) (int c);
113
184
int EXPORT_FUNC(grub_isprint) (int c);
166
255
while (*s1 && *s2)
168
if (grub_tolower (*s1) != grub_tolower (*s2))
257
if (grub_tolower ((grub_uint8_t) *s1)
258
!= grub_tolower ((grub_uint8_t) *s2))
175
return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
265
return (int) grub_tolower ((grub_uint8_t) *s1)
266
- (int) grub_tolower ((grub_uint8_t) *s2);
178
269
static inline int
193
return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
196
/* Replace all `ch' characters of `input' with `with' and copy the
197
result into `output'; return EOS address of `output'. */
199
grub_strchrsub (char *output, const char *input, char ch, const char *with)
201
grub_size_t grub_strlen (const char *s);
206
grub_strcpy (output, with);
207
output += grub_strlen (with);
211
*output++ = *input++;
284
return (int) grub_tolower ((grub_uint8_t) *s1)
285
- (int) grub_tolower ((grub_uint8_t) *s2);
217
288
unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base);
238
309
if (magnitude > (unsigned long) GRUB_LONG_MAX + 1)
240
grub_error (GRUB_ERR_OUT_OF_RANGE, "negative overflow");
311
grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
241
312
return GRUB_LONG_MIN;
243
314
return -((long) magnitude);
260
331
int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
261
332
int EXPORT_FUNC(grub_printf_) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
334
/* Replace all `ch' characters of `input' with `with' and copy the
335
result into `output'; return EOS address of `output'. */
337
grub_strchrsub (char *output, const char *input, char ch, const char *with)
343
grub_strcpy (output, with);
344
output += grub_strlen (with);
348
*output++ = *input++;
263
354
extern void (*EXPORT_VAR (grub_xputs)) (const char *str);
265
356
static inline int
287
378
char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) __attribute__ ((warn_unused_result));
288
379
void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
289
380
void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn));
290
grub_uint64_t EXPORT_FUNC(grub_divmod64_full) (grub_uint64_t n,
293
static inline grub_uint64_t grub_divmod64 (grub_uint64_t n,
297
grub_uint64_t ret, rr;
299
ret = grub_divmod64_full (n, d, &rr);
381
grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
305
#if NEED_ENABLE_EXECUTE_STACK && !defined(GRUB_UTIL)
385
#if !defined(GRUB_UTIL) && NEED_ENABLE_EXECUTE_STACK
306
386
void EXPORT_FUNC(__enable_execute_stack) (void *addr);
309
#if NEED_REGISTER_FRAME_INFO && !defined(GRUB_UTIL)
389
#if !defined(GRUB_UTIL) && NEED_REGISTER_FRAME_INFO
310
390
void EXPORT_FUNC (__register_frame_info) (void);
311
391
void EXPORT_FUNC (__deregister_frame_info) (void);
314
394
/* Inline functions. */
397
grub_memchr (const void *p, int c, grub_size_t len)
400
const char *e = s + len;
316
410
static inline unsigned int
322
416
return (unsigned int) x;
326
grub_min (long x, long y)
335
grub_max (long x, long y)
343
419
/* Rounded-up division */
344
420
static inline unsigned int
345
421
grub_div_roundup (unsigned int x, unsigned int y)
350
426
/* Reboot the machine. */
351
void EXPORT_FUNC (grub_reboot) (void) __attribute__ ((noreturn));
427
#if defined (GRUB_MACHINE_EMU) || defined (GRUB_MACHINE_QEMU_MIPS)
428
void EXPORT_FUNC(grub_reboot) (void) __attribute__ ((noreturn));
430
void grub_reboot (void) __attribute__ ((noreturn));
353
433
#ifdef GRUB_MACHINE_PCBIOS
354
434
/* Halt the system, using APM if possible. If NO_APM is true, don't
355
435
* use APM even if it is available. */
356
436
void grub_halt (int no_apm) __attribute__ ((noreturn));
437
#elif defined (__mips__)
438
void EXPORT_FUNC (grub_halt) (void) __attribute__ ((noreturn));
358
440
void grub_halt (void) __attribute__ ((noreturn));
365
447
#define grub_no_autoload 0
451
grub_error_save (struct grub_error_saved *save)
453
grub_memcpy (save->errmsg, grub_errmsg, sizeof (save->errmsg));
454
save->grub_errno = grub_errno;
455
grub_errno = GRUB_ERR_NONE;
459
grub_error_load (const struct grub_error_saved *save)
461
grub_memcpy (grub_errmsg, save->errmsg, sizeof (grub_errmsg));
462
grub_errno = save->grub_errno;
368
465
#endif /* ! GRUB_MISC_HEADER */