Change bcopy, bzero to memmove, memset.

This commit is contained in:
gord 1999-03-27 23:35:37 +00:00
parent 8a1b524d47
commit 08ca05f500
11 changed files with 84 additions and 72 deletions

View file

@ -1,5 +1,11 @@
1999-03-27 Gordon Matzigkeit <gord@trick.fig.org> 1999-03-27 Gordon Matzigkeit <gord@trick.fig.org>
* Change everything to use memset and memmove instead of bzero and
bcopy. GNB's Not BSD.
* shared_src/shared.h (grub_memset): Adapted from grub_bzero.
(grub_memmove): Adapted from grub_bcopy.
* grub/asmstub.c (checkkey): Fix unterminated comment. * grub/asmstub.c (checkkey): Fix unterminated comment.
* shared_src/char_io.c (grub_printf): Renamed from printf. * shared_src/char_io.c (grub_printf): Renamed from printf.

View file

@ -198,14 +198,14 @@ load_image (void)
if (mbi.mem_lower >= 608) if (mbi.mem_lower >= 608)
{ {
bcopy (buffer, (char *) LINUX_SETUP, data_len + SECTOR_SIZE); memmove ((char *) LINUX_SETUP, buffer, data_len + SECTOR_SIZE);
/* copy command-line plus memory hack to staging area */ /* copy command-line plus memory hack to staging area */
{ {
char *src = cur_cmdline; char *src = cur_cmdline;
char *dest = (char *) (CL_MY_LOCATION + 4); char *dest = (char *) (CL_MY_LOCATION + 4);
bcopy ("mem=", (char *) CL_MY_LOCATION, 4); memmove ((char *) CL_MY_LOCATION, "mem=", 4);
*((unsigned short *) CL_OFFSET) = CL_MY_LOCATION - CL_BASE_ADDR; *((unsigned short *) CL_OFFSET) = CL_MY_LOCATION - CL_BASE_ADDR;
*((unsigned short *) CL_MAGIC_ADDR) = CL_MAGIC; *((unsigned short *) CL_MAGIC_ADDR) = CL_MAGIC;
@ -286,7 +286,7 @@ load_image (void)
if (!errnum) if (!errnum)
{ {
bzero ((char *) cur_addr, bss_len); memset ((char *) cur_addr, 0, bss_len);
cur_addr += bss_len; cur_addr += bss_len;
printf (", bss=0x%x", bss_len); printf (", bss=0x%x", bss_len);
@ -386,7 +386,7 @@ load_image (void)
&& grub_read ((char *) memaddr, filesiz) == filesiz) && grub_read ((char *) memaddr, filesiz) == filesiz)
{ {
if (memsiz > filesiz) if (memsiz > filesiz)
bzero ((char *) (memaddr + filesiz), memsiz - filesiz); memset ((char *) (memaddr + filesiz), 0, memsiz - filesiz);
} }
else else
break; break;
@ -454,7 +454,7 @@ load_initrd (void)
return 0; return 0;
moveto = ((mbi.mem_upper + 0x400) * 0x400 - len) & 0xfffff000; moveto = ((mbi.mem_upper + 0x400) * 0x400 - len) & 0xfffff000;
bcopy ((void *) cur_addr, (void *) moveto, len); memmove ((void *) moveto, (void *) cur_addr, len);
printf (" [Linux-initrd @ 0x%x, 0x%x bytes]\n", moveto, len); printf (" [Linux-initrd @ 0x%x, 0x%x bytes]\n", moveto, len);

View file

@ -586,7 +586,7 @@ int
memcheck (int start, int len) memcheck (int start, int len)
{ {
#ifdef GRUB_UTIL #ifdef GRUB_UTIL
/* FIXME: cur_part_desc is the only global variable that we bcopy /* FIXME: cur_part_desc is the only global variable that we memmove
to. We should fix this so that we don't need a special case to. We should fix this so that we don't need a special case
(i.e. so that it lives on the stack, or somewhere inside (i.e. so that it lives on the stack, or somewhere inside
grub_scratch_mem). */ grub_scratch_mem). */
@ -606,9 +606,10 @@ memcheck (int start, int len)
} }
int char *
grub_bcopy (char *from, char *to, int len) grub_memmove (char *to, char *from, int len)
{ {
char *ret = to;
if (memcheck ((int) to, len)) if (memcheck ((int) to, len))
{ {
if ((to >= from + len) || (to <= from)) if ((to >= from + len) || (to <= from))
@ -630,18 +631,20 @@ grub_bcopy (char *from, char *to, int len)
} }
} }
return (!errnum); return errnum ? NULL : ret;
} }
int void *
grub_bzero (char *start, int len) grub_memset (void *start, int c, int len)
{ {
char *p = start;
if (memcheck ((int) start, len)) if (memcheck ((int) start, len))
{ {
while (len-- > 0) while (len -- > 0)
*(start++) = 0; *p ++ = c;
} }
return (!errnum); return errnum ? NULL : start;
} }

View file

@ -213,7 +213,7 @@ returnit:
while (*(cur_entry++)); while (*(cur_entry++));
/* copy to work area */ /* copy to work area */
bcopy(old_entry, cur_heap, ((int)cur_entry) - ((int)old_entry)); memmove (cur_heap, old_entry, ((int)cur_entry) - ((int)old_entry));
printf("%s\n", old_entry); printf("%s\n", old_entry);
} }
@ -316,7 +316,8 @@ returnit:
else if (substring("kernel", cur_heap) < 1) else if (substring("kernel", cur_heap) < 1)
{ {
/* make sure it's at the beginning of the boot heap area */ /* make sure it's at the beginning of the boot heap area */
bcopy(cur_heap, heap, cmd_len + (((int)cur_cmdline) - ((int)cur_heap))); memmove (heap, cur_heap,
cmd_len + (((int)cur_cmdline) - ((int)cur_heap)));
cur_cmdline = heap + (((int)cur_cmdline) - ((int)cur_heap)); cur_cmdline = heap + (((int)cur_cmdline) - ((int)cur_heap));
cur_heap = heap; cur_heap = heap;
if ((type = load_image()) != 0) if ((type = load_image()) != 0)
@ -386,12 +387,12 @@ returnit:
#endif #endif
/* copy possible DOS BPB, 59 bytes at byte offset 3 */ /* copy possible DOS BPB, 59 bytes at byte offset 3 */
bcopy(old_sect+BOOTSEC_BPB_OFFSET, buffer+BOOTSEC_BPB_OFFSET, memmove (buffer+BOOTSEC_BPB_OFFSET, old_sect+BOOTSEC_BPB_OFFSET,
BOOTSEC_BPB_LENGTH); BOOTSEC_BPB_LENGTH);
/* if for a hard disk, copy possible MBR/extended part table */ /* if for a hard disk, copy possible MBR/extended part table */
if ((dest_drive & 0x80) && current_partition == 0xFFFFFF) if ((dest_drive & 0x80) && current_partition == 0xFFFFFF)
bcopy(old_sect+BOOTSEC_PART_OFFSET, buffer+BOOTSEC_PART_OFFSET, memmove (buffer+BOOTSEC_PART_OFFSET, old_sect+BOOTSEC_PART_OFFSET,
BOOTSEC_PART_LENGTH); BOOTSEC_PART_LENGTH);
if (*((short *)(buffer+STAGE1_VER_MAJ_OFFS)) != COMPAT_VERSION if (*((short *)(buffer+STAGE1_VER_MAJ_OFFS)) != COMPAT_VERSION
@ -408,7 +409,7 @@ returnit:
if (!new_drive) if (!new_drive)
new_drive = current_drive; new_drive = current_drive;
bcopy(buffer, (char*)BOOTSEC_LOCATION, SECTOR_SIZE); memmove ((char*)BOOTSEC_LOCATION, buffer, SECTOR_SIZE);
*((unsigned char *)(BOOTSEC_LOCATION+STAGE1_FIRSTLIST)) *((unsigned char *)(BOOTSEC_LOCATION+STAGE1_FIRSTLIST))
= new_drive; = new_drive;

View file

@ -177,7 +177,7 @@ rawread (int drive, int sector, int byte_offset, int byte_len, char *buf)
if (size > ((num_sect * SECTOR_SIZE) - byte_offset)) if (size > ((num_sect * SECTOR_SIZE) - byte_offset))
size = (num_sect * SECTOR_SIZE) - byte_offset; size = (num_sect * SECTOR_SIZE) - byte_offset;
bcopy ((char *) bufaddr, buf, size); memmove (buf, (char *) bufaddr, size);
buf += size; buf += size;
byte_len -= size; byte_len -= size;
@ -451,7 +451,7 @@ real_open_partition (int flags)
current_slice = PC_SLICE_TYPE (mbr_buf, i); current_slice = PC_SLICE_TYPE (mbr_buf, i);
part_start = part_offset + PC_SLICE_START (mbr_buf, i); part_start = part_offset + PC_SLICE_START (mbr_buf, i);
part_length = PC_SLICE_LENGTH (mbr_buf, i); part_length = PC_SLICE_LENGTH (mbr_buf, i);
bcopy (mbr_buf + PC_SLICE_OFFSET + (i << 4), cur_part_desc, 16); memmove (cur_part_desc, mbr_buf + PC_SLICE_OFFSET + (i << 4), 16);
/* /*
* Is this PC partition entry valid? * Is this PC partition entry valid?
@ -781,7 +781,7 @@ set_bootdev (int hdbias)
/* /*
* Set chainloader boot device. * Set chainloader boot device.
*/ */
bcopy (cur_part_desc, (char *) (BOOTSEC_LOCATION - 16), 16); memmove ((char *) (BOOTSEC_LOCATION - 16), cur_part_desc, 16);
/* /*
* Set BSD boot device. * Set BSD boot device.

View file

@ -581,7 +581,7 @@ ext2fs_dir (char *dirname)
#endif /* E2DEBUG */ #endif /* E2DEBUG */
/* copy inode to fixed location */ /* copy inode to fixed location */
bcopy ((void *) raw_inode, (void *) INODE, sizeof (struct ext2_inode)); memmove ((void *) INODE, (void *) raw_inode, sizeof (struct ext2_inode));
#ifdef E2DEBUG #ifdef E2DEBUG
printf ("first word=%x\n", *((int *) INODE)); printf ("first word=%x\n", *((int *) INODE));
@ -614,7 +614,7 @@ ext2fs_dir (char *dirname)
{ {
/* Copy the remaining name to the end of the symlink data. /* Copy the remaining name to the end of the symlink data.
Note that DIRNAME and LINKBUF may overlap! */ Note that DIRNAME and LINKBUF may overlap! */
bcopy (dirname, linkbuf + filemax, len); memmove (linkbuf + filemax, dirname, len);
} }
linkbuf[filemax + len] = '\0'; linkbuf[filemax + len] = '\0';
@ -631,7 +631,7 @@ ext2fs_dir (char *dirname)
{ {
/* Copy the data directly from the inode. */ /* Copy the data directly from the inode. */
len = filemax; len = filemax;
bcopy ((char *) INODE->i_block, linkbuf, len); memmove (linkbuf, (char *) INODE->i_block, len);
} }
#if E2DEBUG #if E2DEBUG

View file

@ -173,8 +173,9 @@ loop:
0, SUPERBLOCK->fs_bsize, (char *) FSYS_BUF)) 0, SUPERBLOCK->fs_bsize, (char *) FSYS_BUF))
return 0; /* XXX what return value? */ return 0; /* XXX what return value? */
bcopy ((void *) &(((struct dinode *) FSYS_BUF)[ino % (SUPERBLOCK->fs_inopb)]), memmove ((void *) INODE,
(void *) INODE, sizeof (struct dinode)); (void *) &(((struct dinode *) FSYS_BUF)[ino % (SUPERBLOCK->fs_inopb)]),
sizeof (struct dinode));
/* if we have a real file (and we're not just printing possibilities), /* if we have a real file (and we're not just printing possibilities),
then this is where we want to exit */ then this is where we want to exit */

View file

@ -537,7 +537,7 @@ huft_build (unsigned *b, /* code lengths in bits (all assumed <= BMAX) */
unsigned z; /* number of entries in current table */ unsigned z; /* number of entries in current table */
/* Generate counts for each bit length */ /* Generate counts for each bit length */
bzero ((char *) c, sizeof (c)); memset ((char *) c, 0, sizeof (c));
p = b; p = b;
i = n; i = n;
do do
@ -795,7 +795,7 @@ inflate_codes_in_window (void)
: e); : e);
if (w - d >= e) if (w - d >= e)
{ {
bcopy (slide + d, slide + w, e); memmove (slide + w, slide + d, e);
w += e; w += e;
d += e; d += e;
} }
@ -1200,7 +1200,7 @@ gunzip_read (char *buf, int len)
if (size > len) if (size > len)
size = len; size = len;
bcopy (srcaddr, buf, size); memmove (buf, srcaddr, size);
buf += size; buf += size;
len -= size; len -= size;

View file

@ -204,8 +204,9 @@ extern char *grub_scratch_mem;
/* Remap some libc-API-compatible function names so that we prevent /* Remap some libc-API-compatible function names so that we prevent
circularararity. */ circularararity. */
#ifndef WITHOUT_LIBC_STUBS #ifndef WITHOUT_LIBC_STUBS
#define bcopy grub_bcopy #define memmove grub_memmove
#define bzero grub_bzero #define memcpy grub_memmove /* we don't need a separate memcpy */
#define memset grub_memset
#define isspace grub_isspace #define isspace grub_isspace
#define printf grub_printf #define printf grub_printf
#undef putchar #undef putchar
@ -452,8 +453,8 @@ void grub_printf (char *format,...);
int grub_tolower (int c); int grub_tolower (int c);
int grub_isspace (int c); int grub_isspace (int c);
int grub_strncat (char *s1, char *s2, int n); int grub_strncat (char *s1, char *s2, int n);
int grub_bcopy (char *from, char *to, int len); char *grub_memmove (char *to, char *from, int len);
int grub_bzero (char *start, int len); void *grub_memset (void *start, int c, int len);
char *grub_strstr (char *s1, char *s2); char *grub_strstr (char *s1, char *s2);
int grub_strcmp (char *s1, char *s2); int grub_strcmp (char *s1, char *s2);

View file

@ -233,7 +233,7 @@ boot_cpu (imps_processor * proc)
/* %%%%% ESB */ /* %%%%% ESB */
extern char patch_code[]; extern char patch_code[];
bootaddr = 256 * 1024; bootaddr = 256 * 1024;
bcopy (patch_code, (char *) bootaddr, 32); memmove ((char *) bootaddr, patch_code, 32);
/* /*
* Generic CPU startup sequence starts here. * Generic CPU startup sequence starts here.
@ -319,7 +319,7 @@ add_bus (imps_bus * bus)
{ {
char str[8]; char str[8];
bcopy (bus->bus_type, str, 6); memmove (str, bus->bus_type, 6);
str[6] = 0; str[6] = 0;
KERNEL_PRINT ((" Bus id %d is %s\n", bus->id, str)); KERNEL_PRINT ((" Bus id %d is %s\n", bus->id, str));
@ -488,9 +488,9 @@ imps_read_bios (imps_fps * fps_ptr)
if (fps_ptr->cth_ptr) if (fps_ptr->cth_ptr)
{ {
char str1[16], str2[16]; char str1[16], str2[16];
bcopy (local_cth_ptr->oem_id, str1, 8); memcpy (str1, local_cth_ptr->oem_id, 8);
str1[8] = 0; str1[8] = 0;
bcopy (local_cth_ptr->prod_id, str2, 12); memcpy (str2, local_cth_ptr->prod_id, 12);
str2[12] = 0; str2[12] = 0;
KERNEL_PRINT ((" OEM id: %s Product id: %s\n", str1, str2)); KERNEL_PRINT ((" OEM id: %s Product id: %s\n", str1, str2));
cth_start = ((unsigned) local_cth_ptr) + sizeof (imps_cth); cth_start = ((unsigned) local_cth_ptr) + sizeof (imps_cth);
@ -513,12 +513,12 @@ imps_read_bios (imps_fps * fps_ptr)
if (fps_ptr->feature_info[0] == 1 if (fps_ptr->feature_info[0] == 1
|| fps_ptr->feature_info[0] == 5) || fps_ptr->feature_info[0] == 5)
{ {
bcopy ("ISA ", defconfig.bus[0].bus_type, 6); memcpy (defconfig.bus[0].bus_type, "ISA ", 6);
} }
if (fps_ptr->feature_info[0] == 4 if (fps_ptr->feature_info[0] == 4
|| fps_ptr->feature_info[0] == 7) || fps_ptr->feature_info[0] == 7)
{ {
bcopy ("MCA ", defconfig.bus[0].bus_type, 6); memcpy (defconfig.bus[0].bus_type, "MCA ", 6);
} }
if (fps_ptr->feature_info[0] > 4) if (fps_ptr->feature_info[0] > 4)
{ {

View file

@ -273,7 +273,7 @@ restart:
if (c == 'O') if (c == 'O')
{ {
bcopy(cur_entry, cur_entry+2, memmove (cur_entry + 2, cur_entry,
((int)heap) - ((int)cur_entry)); ((int)heap) - ((int)cur_entry));
cur_entry[0] = ' '; cur_entry[0] = ' ';
@ -287,7 +287,7 @@ restart:
{ {
char *ptr = get_entry(menu_entries, char *ptr = get_entry(menu_entries,
first_entry+entryno+1, 0); first_entry+entryno+1, 0);
bcopy(ptr, cur_entry, ((int)heap) - ((int)ptr)); memmove (cur_entry, ptr, ((int)heap) - ((int)ptr));
heap -= (((int)ptr) - ((int)cur_entry)); heap -= (((int)ptr) - ((int)cur_entry));
num_entries--; num_entries--;
@ -325,7 +325,7 @@ restart:
if (! strcmp (password, entered)) if (! strcmp (password, entered))
{ {
char *new_file = config_file; char *new_file = config_file;
bzero (entered, sizeof (entered)); memset (entered, 0, sizeof (entered));
while (isspace (*pptr)) while (isspace (*pptr))
pptr ++; pptr ++;
while ((*(new_file ++) = *(pptr ++)) != 0); while ((*(new_file ++) = *(pptr ++)) != 0);
@ -333,7 +333,7 @@ restart:
} }
else else
{ {
bzero (entered, sizeof (entered)); memset (entered, 0, sizeof (entered));
printf("Failed!\n Press any key to continue..."); printf("Failed!\n Press any key to continue...");
getkey (); getkey ();
goto restart; goto restart;
@ -401,11 +401,11 @@ restart:
} }
/* align rest of commands properly */ /* align rest of commands properly */
bcopy(cur_entry+i, cur_entry+j, memmove (cur_entry + j, cur_entry + i,
((int)heap) - (((int)cur_entry) + i)); ((int)heap) - (((int)cur_entry) + i));
/* copy command to correct area */ /* copy command to correct area */
bcopy(new_heap, cur_entry, j); memmove (cur_entry, new_heap, j);
heap += (j - i); heap += (j - i);
} }
@ -596,8 +596,8 @@ cmain(void)
menu_entries[menu_len++] = 0; menu_entries[menu_len++] = 0;
config_entries[config_len++] = 0; config_entries[config_len++] = 0;
bcopy(menu_entries, config_entries+config_len, menu_len); memmove (config_entries + config_len, menu_entries, menu_len);
menu_entries = config_entries+config_len; menu_entries = config_entries + config_len;
} }
/* /*