#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <a.out.h>

read_symbol(f, sym_name)
     int f;
     char *sym_name;
{
  struct symtab fsynt;
  int c, sym_length, r_length;

  c = read(f, (char *) &fsynt, sizeof(struct symtab));
  if (c != sizeof(struct symtab))
    return(-1);
#ifdef DEBUG
  printf("Type = %d, Size = %d, Value = %d\n",
	 fsynt.sym_type, fsynt.value_size, fsynt.sym_value);
#endif
  if (fsynt.value_size == 4) {
    sym_length = fsynt.variant.other.sym_length;
    lseek(f, -6, SEEK_CUR);	/* there is a better way to do this... */ }
  else if (fsynt.value_size ==8) {
    sym_length = fsynt.variant.part.sym_length;
    lseek(f, -2, SEEK_CUR); }
  else
    return(-1);		/* somebody must have entered in the wrong place.. */
  r_length = (sym_length & 0x1 ? sym_length+1 : sym_length);
  c = read(f, sym_name, r_length);
  if (c != r_length)
    return(-1);
  sym_name[sym_length] = '\0';
  return(0);
}
