#include "gdbcore.h" /* for bfd stuff */
#include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
#include "symfile.h"
+#include "objfiles.h"
#include "buildsym.h"
#include "aout/aout64.h"
/* Information is passed among various dbxread routines for accessing
symbol files. A pointer to this structure is kept in the sym_private
- field of the objfile struct passed in by symfile.h. */
+ field of the objfile struct. */
struct dbx_symfile_info {
asection *text_sect; /* Text section accessor */
off_t symtab_offset; /* Offset in file to symbol table */
};
+#define DBX_SYMFILE_INFO(o) ((struct dbx_symfile_info *)((o)->sym_private))
+#define DBX_TEXT_SECT(o) (DBX_SYMFILE_INFO(o)->text_sect)
+#define DBX_SYMCOUNT(o) (DBX_SYMFILE_INFO(o)->symcount)
+#define DBX_STRINGTAB(o) (DBX_SYMFILE_INFO(o)->stringtab)
+#define DBX_STRINGTAB_SIZE(o) (DBX_SYMFILE_INFO(o)->stringtab_size)
+#define DBX_SYMTAB_OFFSET(o) (DBX_SYMFILE_INFO(o)->symtab_offset)
/* Each partial symbol table entry contains a pointer to private data for the
read_symtab() function to use when expanding a partial symbol table entry
static struct objfile *our_objfile;
-/* String table for the main symbol file. It is kept in memory
- permanently, to speed up symbol reading. Other files' symbol tables
- are read in on demand. FIXME, this should be cleaner. */
-
-static char *symfile_string_table;
-static int symfile_string_table_size;
-
/* The size of each symbol in the symbol file (in external form).
This is set by dbx_symfile_read when building psymtabs, and by
dbx_psymtab_to_symtab when building symtabs. */
copy_pending PARAMS ((struct pending *, int, struct pending *));
static struct symtab *
-read_ofile_symtab PARAMS ((struct objfile *, char *, unsigned int, int, int,
- CORE_ADDR, int, int));
+read_ofile_symtab PARAMS ((struct objfile *, int, int, CORE_ADDR, int, int));
static void
dbx_psymtab_to_symtab PARAMS ((struct partial_symtab *));
static void
-psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *, int, int));
+psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, int));
static void
-read_dbx_symtab PARAMS ((CORE_ADDR, struct objfile *, char *, long, int,
- CORE_ADDR, int));
+read_dbx_symtab PARAMS ((CORE_ADDR, struct objfile *, CORE_ADDR, int));
static void
free_bincl_list PARAMS ((struct objfile *));
init_bincl_list PARAMS ((int, struct objfile *));
static void
-init_psymbol_list PARAMS ((int, struct objfile *));
+init_psymbol_list PARAMS ((struct objfile *));
static char *
dbx_next_symbol_text PARAMS ((void));
\f
/* Scan and build partial symbols for a symbol file.
We have been initialized by a call to dbx_symfile_init, which
- put all the relevant info into a "struct dbx_symfile_info"
- hung off the struct sym_fns SF.
+ put all the relevant info into a "struct dbx_symfile_info",
+ hung off the objfile structure.
ADDR is the address relative to which the symbols in it are (e.g.
the base address of the text segment).
CORE_ADDR addr;
int mainline; /* FIXME comments above */
{
- struct dbx_symfile_info *info;
bfd *sym_bfd;
int val;
sym_bfd = objfile->obfd;
- info = (struct dbx_symfile_info *) (objfile -> sym_private);
- val = bfd_seek (objfile->obfd, info->symtab_offset, L_SET);
+ val = bfd_seek (objfile->obfd, DBX_SYMTAB_OFFSET (objfile), L_SET);
if (val < 0)
perror_with_name (objfile->name);
- /* If mainline, set global string table pointers, and reinitialize global
- partial symbol list. */
- if (mainline) {
- symfile_string_table = info->stringtab;
- symfile_string_table_size = info->stringtab_size;
- }
-
/* If we are reinitializing, or if we have never loaded syms yet, init */
if (mainline || objfile->global_psymbols.size == 0 || objfile->static_psymbols.size == 0)
- init_psymbol_list (info->symcount, objfile);
+ init_psymbol_list (objfile);
/* FIXME POKING INSIDE BFD DATA STRUCTURES */
symbol_size = obj_symbol_entry_size (sym_bfd);
/* Now that the symbol table data of the executable file are all in core,
process them and define symbols accordingly. */
- read_dbx_symtab (addr - bfd_section_vma (sym_bfd, info->text_sect), /*offset*/
- objfile, info->stringtab, info->stringtab_size,
- info->symcount,
- bfd_section_vma (sym_bfd, info->text_sect),
- bfd_section_size (sym_bfd, info->text_sect));
+ addr -= bfd_section_vma (sym_bfd, DBX_TEXT_SECT (objfile)); /*offset*/
+ read_dbx_symtab (addr, objfile,
+ bfd_section_vma (sym_bfd, DBX_TEXT_SECT (objfile)),
+ bfd_section_size (sym_bfd, DBX_TEXT_SECT (objfile)));
/* Install any minimal symbols that have been collected as the current
minimal symbols for this objfile. */
install_minimal_symbols (objfile);
- /* Free up any memory we allocated for ourselves. */
-
- if (!mainline) {
- mfree (objfile->md, info->stringtab); /* Stringtab is only saved for mainline */
- }
- mfree (objfile->md, info);
- /* Zap pointer to our (now gone) info struct */
- objfile -> sym_private = NULL;
if (!have_partial_symbols ()) {
wrap_here ("");
printf_filtered ("(no debugging symbols found)...");
int val;
bfd *sym_bfd = objfile->obfd;
char *name = bfd_get_filename (sym_bfd);
- struct dbx_symfile_info *info;
unsigned char size_temp[4];
/* Allocate struct to keep track of the symfile */
- objfile-> sym_private = xmmalloc (objfile -> md, sizeof (*info));
- info = (struct dbx_symfile_info *) objfile -> sym_private;
+ DBX_SYMFILE_INFO (objfile) = (struct dbx_symfile_info *)
+ xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info));
/* FIXME POKING INSIDE BFD DATA STRUCTURES */
#define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
#define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
/* FIXME POKING INSIDE BFD DATA STRUCTURES */
- info->text_sect = bfd_get_section_by_name (sym_bfd, ".text");
- if (!info->text_sect)
+ DBX_TEXT_SECT (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
+ if (!DBX_TEXT_SECT (objfile))
abort();
- info->symcount = bfd_get_symcount (sym_bfd);
+ DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd);
+
+ /* Read the string table and stash it away in the psymbol_obstack. It is
+ only needed as long as we need to expand psymbols into full symbols,
+ so when we blow away the psymbol the string table goes away as well.
+ Note that gdb used to use the results of attempting to malloc the
+ string table, based on the size it read, as a form of sanity check
+ for botched byte swapping, on the theory that a byte swapped string
+ table size would be so totally bogus that the malloc would fail. Now
+ that we put in on the psymbol_obstack, we can't do this since gdb gets
+ a fatal error (out of virtual memory) if the size is bogus. We can
+ however at least check to see if the size is zero or some negative
+ value. */
- /* Read the string table size and check it for bogosity. */
val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
if (val < 0)
- perror_with_name (name);
+ perror_with_name (name);
val = bfd_read (size_temp, sizeof (long), 1, sym_bfd);
if (val < 0)
- perror_with_name (name);
- info->stringtab_size = bfd_h_get_32 (sym_bfd, size_temp);
-
- if (info->stringtab_size >= 0)
- {
- /* Yes, this should be malloc, not xmalloc. We check its result. */
- info->stringtab = (char *) mmalloc (objfile->md, info->stringtab_size);
- /* Caller is responsible for freeing the string table. No cleanup. */
- }
- else
- info->stringtab = NULL;
- if (info->stringtab == NULL && info->stringtab_size != 0)
- error ("ridiculous string table size: %d bytes", info->stringtab_size);
+ perror_with_name (name);
+
+ DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
+ if (DBX_STRINGTAB_SIZE (objfile) <= 0)
+ error ("ridiculous string table size (%d bytes).",
+ DBX_STRINGTAB_SIZE (objfile));
+
+ DBX_STRINGTAB (objfile) =
+ (char *) obstack_alloc (&objfile -> psymbol_obstack,
+ DBX_STRINGTAB_SIZE (objfile));
/* Now read in the string table in one big gulp. */
val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
if (val < 0)
perror_with_name (name);
- val = bfd_read (info->stringtab, info->stringtab_size, 1, sym_bfd);
- if (val != info->stringtab_size)
+ val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1,
+ sym_bfd);
+ if (val != DBX_STRINGTAB_SIZE (objfile))
perror_with_name (name);
/* Record the position of the symbol table for later use. */
- info->symtab_offset = SYMBOL_TABLE_OFFSET;
+ DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET;
}
/* Perform any local cleanups required when we are done with a particular
dbx_symfile_finish (objfile)
struct objfile *objfile;
{
- if (objfile -> sym_private != NULL)
- {
- mfree (objfile -> md, objfile -> sym_private);
- }
- if (symfile_string_table)
+ if (DBX_SYMFILE_INFO (objfile) != NULL)
{
- free (symfile_string_table);
- symfile_string_table = 0;
- symfile_string_table_size = 0;
+ mfree (objfile -> md, DBX_SYMFILE_INFO (objfile));
}
free_header_files ();
}
created by read_dbx_symtab and subsidiaries. */
static void
-init_psymbol_list (total_symbols, objfile)
- int total_symbols;
+init_psymbol_list (objfile)
struct objfile *objfile;
{
/* Free any previously allocated psymbol lists. */
/* Current best guess is that there are approximately a twentieth
of the total symbols (in a debugging file) are global or static
oriented symbols */
- objfile -> global_psymbols.size = total_symbols / 10;
- objfile -> static_psymbols.size = total_symbols / 10;
+ objfile -> global_psymbols.size = DBX_SYMCOUNT (objfile) / 10;
+ objfile -> static_psymbols.size = DBX_SYMCOUNT (objfile) / 10;
objfile -> global_psymbols.next = objfile -> global_psymbols.list = (struct partial_symbol *)
xmmalloc (objfile -> md, objfile -> global_psymbols.size * sizeof (struct partial_symbol));
objfile -> static_psymbols.next = objfile -> static_psymbols.list = (struct partial_symbol *)
/* Given pointers to an a.out symbol table in core containing dbx
style data, setup partial_symtab's describing each source file for
- which debugging information is available. NLISTLEN is the number
- of symbols in the symbol table. All symbol names are given as
- offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
- STRINGTAB. SYMFILE_NAME is the name of the file we are reading from
+ which debugging information is available.
+ SYMFILE_NAME is the name of the file we are reading from
and ADDR is its relocated address (if incremental) or 0 (if not). */
static void
-read_dbx_symtab (addr, objfile, stringtab, stringtab_size, nlistlen,
- text_addr, text_size)
+read_dbx_symtab (addr, objfile, text_addr, text_size)
CORE_ADDR addr;
struct objfile *objfile;
- register char *stringtab;
- register long stringtab_size;
- register int nlistlen;
CORE_ADDR text_addr;
int text_size;
{
struct partial_symtab **dependency_list;
int dependencies_used, dependencies_allocated;
- stringtab_global = stringtab;
+ stringtab_global = DBX_STRINGTAB (objfile);
pst = (struct partial_symtab *) 0;
symbuf_end = symbuf_idx = 0;
next_symbol_text_func = dbx_next_symbol_text;
- for (symnum = 0; symnum < nlistlen; symnum++)
+ for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
{
/* Get the symbol for this run and pull out some info */
QUIT; /* allow this to be interruptable */
give a fake name, and print a single error message per symbol file read,
rather than abort the symbol reading or flood the user with messages. */
#define SET_NAMESTRING()\
- if (((unsigned)bufp->n_strx) >= stringtab_size) { \
+ if (((unsigned)bufp->n_strx) >= DBX_STRINGTAB_SIZE (objfile)) { \
complain (&string_table_offset_complaint, (char *) symnum); \
namestring = "foo"; \
} else \
- namestring = bufp->n_strx + stringtab
+ namestring = bufp->n_strx + DBX_STRINGTAB (objfile)
#define CUR_SYMBOL_TYPE bufp->n_type
#define CUR_SYMBOL_VALUE bufp->n_value
}
/* If there's stuff to be cleaned up, clean it up. */
- if (nlistlen > 0 /* We have some syms */
- && entry_point < bufp->n_value
- && entry_point >= last_o_file_start)
+ if (DBX_SYMCOUNT (objfile) > 0 /* We have some syms */
+ && objfile -> ei.entry_point < bufp->n_value
+ && objfile -> ei.entry_point >= last_o_file_start)
{
- startup_file_start = last_o_file_start;
- startup_file_end = bufp->n_value;
+ objfile -> ei.entry_file_lowpc = last_o_file_start;
+ objfile -> ei.entry_file_highpc = bufp->n_value;
}
if (pst)
}
\f
static void
-psymtab_to_symtab_1 (pst, stringtab, stringtab_size, sym_offset)
+psymtab_to_symtab_1 (pst, sym_offset)
struct partial_symtab *pst;
- char *stringtab;
- int stringtab_size;
int sym_offset;
{
struct cleanup *old_chain;
wrap_here (""); /* Flush output */
fflush (stdout);
}
- psymtab_to_symtab_1 (pst->dependencies[i],
- stringtab, stringtab_size, sym_offset);
+ psymtab_to_symtab_1 (pst->dependencies[i], sym_offset);
}
if (LDSYMLEN(pst)) /* Otherwise it's a dummy */
/* Read in this files symbols */
bfd_seek (pst->objfile->obfd, sym_offset, L_SET);
pst->symtab =
- read_ofile_symtab (pst->objfile, stringtab, stringtab_size,
- LDSYMOFF(pst),
- LDSYMLEN(pst), pst->textlow,
- pst->texthigh - pst->textlow, pst->addr);
+ read_ofile_symtab (pst->objfile, LDSYMOFF(pst), LDSYMLEN(pst),
+ pst->textlow, pst->texthigh - pst->textlow,
+ pst->addr);
sort_symtab_syms (pst->symtab);
do_cleanups (old_chain);
dbx_psymtab_to_symtab (pst)
struct partial_symtab *pst;
{
- char *stringtab;
- int stsize, val;
+ int val;
bfd *sym_bfd;
long st_temp;
sym_bfd = pst->objfile->obfd;
- /* We keep the string table for the main symfile resident in memory, but
- not the string table for any other symbol files. */
- if (symfile_objfile != pst->objfile)
- {
- /* Read in the string table */
-
- /* FIXME, this uses internal BFD variables. See above in
- dbx_symbol_file_open where the macro is defined! */
- bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
-
- val = bfd_read (&st_temp, sizeof st_temp, 1, sym_bfd);
- if (val < 0)
- perror_with_name (pst->objfile->name);
- stsize = bfd_h_get_32 (sym_bfd, (unsigned char *)&st_temp);
-#if 0
- /* BFD doesn't provide a way to know the total file size, sigh */
- struct stat statbuf;
- if (fstat (desc, &statbuf) < 0)
- perror_with_name (pst->objfile->name);
-
- if (stsize >= 0 && stsize < statbuf.st_size)
-#else
- if (stsize >= 0)
-#endif
- {
-#ifdef BROKEN_LARGE_ALLOCA
- stringtab = (char *) xmalloc (stsize);
- make_cleanup (free, stringtab);
-#else
- stringtab = (char *) alloca (stsize);
-#endif
- }
- else
- stringtab = NULL;
- if (stringtab == NULL && stsize != 0)
- error ("ridiculous string table size: %d bytes", stsize);
-
- /* FIXME, this uses internal BFD variables. See above in
- dbx_symbol_file_open where the macro is defined! */
- val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
- if (val < 0)
- perror_with_name (pst->objfile->name);
- val = bfd_read (stringtab, stsize, 1, sym_bfd);
- if (val < 0)
- perror_with_name (pst->objfile->name);
- }
- else
- {
- stringtab = symfile_string_table;
- stsize = symfile_string_table_size;
- }
-
/* FIXME POKING INSIDE BFD DATA STRUCTURES */
symbol_size = obj_symbol_entry_size (sym_bfd);
/* FIXME, this uses internal BFD variables. See above in
dbx_symbol_file_open where the macro is defined! */
- psymtab_to_symtab_1 (pst, stringtab, stsize,
- SYMBOL_TABLE_OFFSET);
+ psymtab_to_symtab_1 (pst, SYMBOL_TABLE_OFFSET);
/* Match with global symbols. This only needs to be done once,
after all of the symtabs and dependencies have been read in. */
*
* DESC is the file descriptor for the file, positioned at the
* beginning of the symtab
- * STRINGTAB is a pointer to the files string
- * table, already read in
* SYM_OFFSET is the offset within the file of
- * the beginning of the symbols we want to read, NUM_SUMBOLS is the
- * number of symbols to read
+ * the beginning of the symbols we want to read
+ * SYM_SIZE is the size of the symbol info to read in.
* TEXT_OFFSET is the beginning of the text segment we are reading symbols for
* TEXT_SIZE is the size of the text segment read in.
* OFFSET is a relocation offset which gets added to each symbol
*/
static struct symtab *
-read_ofile_symtab (objfile, stringtab, stringtab_size, sym_offset,
- sym_size, text_offset, text_size, offset)
+read_ofile_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
+ offset)
struct objfile *objfile;
- register char *stringtab;
- unsigned int stringtab_size;
int sym_offset;
int sym_size;
CORE_ADDR text_offset;
current_objfile = objfile;
subfile_stack = 0;
- stringtab_global = stringtab;
+ stringtab_global = DBX_STRINGTAB (objfile);
last_source_file = 0;
abfd = objfile->obfd;
/* Prototypes for local functions */
#if !defined (NO_MALLOC_CHECK)
+
static void
malloc_botch PARAMS ((void));
+
#endif /* NO_MALLOC_CHECK */
static void
/* String to be printed before error messages, if any. */
char *error_pre_print;
-char *warning_pre_print;
+char *warning_pre_print = "\nwarning: ";
\f
/* Add a new cleanup to the cleanup_chain,
and return the previous chain pointer
va_start (args);
string = va_arg (args, char *);
- fprintf (stderr, "gdb: ");
+ fprintf (stderr, "\ngdb: ");
vfprintf (stderr, string, args);
fprintf (stderr, "\n");
va_end (args);
string = va_arg (args, char *);
/* "internal error" is always correct, since GDB should never dump
core, no matter what the input. */
- fprintf (stderr, "gdb internal error: ");
+ fprintf (stderr, "\ngdb internal error: ");
vfprintf (stderr, string, args);
fprintf (stderr, "\n");
va_end (args);
exit (1);
}
-\f
-/* Memory management stuff (malloc friends). */
-
-#if defined (NO_MALLOC_CHECK)
-void
-init_malloc ()
-{}
-#else /* Have mcheck(). */
-static void
-malloc_botch ()
-{
- fatal_dump_core ("Memory corruption");
-}
-
-void
-init_malloc ()
-{
- extern PTR (*__morecore) PARAMS ((long));
-
- mcheck (malloc_botch);
- mtrace ();
-}
-#endif /* Have mcheck(). */
-
-/* Like malloc but get error if no storage available. */
-
-PTR
-xmalloc (size)
- long size;
-{
- register char *val;
-
- /* Protect against gdb wanting to allocate zero bytes. */
- if (size == 0)
- return NULL;
-
- val = (char *) malloc (size);
- if (!val)
- fatal ("virtual memory exhausted.", 0);
- return val;
-}
-
-/* Like realloc but get error if no storage available. */
-
-PTR
-xrealloc (ptr, size)
- char *ptr;
- long size;
-{
- register char *val =
- ptr ? (char *) realloc (ptr, size) : (char*) malloc (size);
- if (!val)
- fatal ("virtual memory exhausted.", 0);
- return val;
-}
-
/* Print the system error message for errno, and also mention STRING
as the file name for which the error was encountered.
Then return to command level. */
if (immediate_quit)
quit ();
}
+
+\f
+/* Memory management stuff (malloc friends). */
+
+#if defined (NO_MMALLOC)
+
+PTR
+mmalloc (md, size)
+ PTR md;
+ long size;
+{
+ return (malloc (size));
+}
+
+PTR
+mrealloc (md, ptr, size)
+ PTR md;
+ PTR ptr;
+ long size;
+{
+ return (realloc (ptr, size));
+}
+
+void
+mfree (md, ptr)
+ PTR md;
+ PTR ptr;
+{
+ free (ptr);
+}
+
+#endif /* NO_MMALLOC */
+
+#if defined (NO_MMALLOC) || defined (NO_MMALLOC_CHECK)
+
+void
+init_malloc (md)
+ PTR md;
+{
+}
+
+#else /* have mmalloc and want corruption checking */
+
+static void
+malloc_botch ()
+{
+ fatal_dump_core ("Memory corruption");
+}
+
+/* Attempt to install hooks in mmalloc/mrealloc/mfree for the heap specified
+ by MD, to detect memory corruption. Note that MD may be NULL to specify
+ the default heap that grows via sbrk.
+
+ Note that for freshly created regions, we must call mmcheck prior to any
+ mallocs in the region. Otherwise, any region which was allocated prior to
+ installing the checking hooks, which is later reallocated or freed, will
+ fail the checks! The mmcheck function only allows initial hooks to be
+ installed before the first mmalloc. However, anytime after we have called
+ mmcheck the first time to install the checking hooks, we can call it again
+ to update the function pointer to the memory corruption handler.
+
+ Returns zero on failure, non-zero on success. */
+
+void
+init_malloc (md)
+ PTR md;
+{
+ if (!mmcheck (md, malloc_botch))
+ {
+ warning ("internal error: failed to install memory consistency checks");
+ }
+
+ (void) mmtrace ();
+}
+
+#endif /* Have mmalloc and want corruption checking */
+
+/* Called when a memory allocation fails, with the number of bytes of
+ memory requested in SIZE. */
+
+NORETURN void
+nomem (size)
+ long size;
+{
+ if (size > 0)
+ {
+ fatal ("virtual memory exhausted: can't allocate %ld bytes.", size);
+ }
+ else
+ {
+ fatal ("virtual memory exhausted.");
+ }
+}
+
+/* Like mmalloc but get error if no storage available, and protect against
+ the caller wanting to allocate zero bytes. Whether to return NULL for
+ a zero byte request, or translate the request into a request for one
+ byte of zero'd storage, is a religious issue. */
+
+PTR
+xmmalloc (md, size)
+ PTR md;
+ long size;
+{
+ register PTR val;
+
+ if (size == 0)
+ {
+ val = NULL;
+ }
+ else if ((val = mmalloc (md, size)) == NULL)
+ {
+ nomem (size);
+ }
+ return (val);
+}
+
+/* Like mrealloc but get error if no storage available. */
+
+PTR
+xmrealloc (md, ptr, size)
+ PTR md;
+ PTR ptr;
+ long size;
+{
+ register PTR val;
+
+ if (ptr != NULL)
+ {
+ val = mrealloc (md, ptr, size);
+ }
+ else
+ {
+ val = mmalloc (md, size);
+ }
+ if (val == NULL)
+ {
+ nomem (size);
+ }
+ return (val);
+}
+
+/* Like malloc but get error if no storage available, and protect against
+ the caller wanting to allocate zero bytes. */
+
+PTR
+xmalloc (size)
+ long size;
+{
+ return (xmmalloc ((void *) NULL, size));
+}
+
+/* Like mrealloc but get error if no storage available. */
+
+PTR
+xrealloc (ptr, size)
+ PTR ptr;
+ long size;
+{
+ return (xmrealloc ((void *) NULL, ptr, size));
+}
+
\f
/* My replacement for the read system call.
Used like `read' but keeps going if `read' returns too soon. */
return p;
}
+char *
+msavestring (md, ptr, size)
+ void *md;
+ const char *ptr;
+ int size;
+{
+ register char *p = (char *) xmmalloc (md, size + 1);
+ bcopy (ptr, p, size);
+ p[size] = 0;
+ return p;
+}
+
/* The "const" is so it compiles under DGUX (which prototypes strsave
in <string.h>. FIXME: This should be named "xstrsave", shouldn't it?
Doesn't real strsave return NULL if out of memory? */
return savestring (ptr, strlen (ptr));
}
+char *
+mstrsave (md, ptr)
+ void *md;
+ const char *ptr;
+{
+ return (msavestring (md, ptr, strlen (ptr)));
+}
+
void
print_spaces (n, file)
register int n;
{
if (spaces)
free (spaces);
- spaces = (char *) malloc (n+1);
+ spaces = (char *) xmalloc (n+1);
for (t = spaces+n; t != spaces;)
*--t = ' ';
spaces[n] = '\0';