home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / dxe / dxeload.c next >
Encoding:
C/C++ Source or Header  |  1996-04-26  |  971 b   |  49 lines

  1. /* Copyright (C) 1995 Charles Sandmann (sandmann@clio.rice.edu)
  2.    This software may be freely distributed with above copyright, no warranty.
  3.    Based on code by DJ Delorie, it's really his, enhanced, bugs fixed. */
  4.  
  5. #include <io.h>
  6. #include <stdlib.h>
  7. #include <errno.h>
  8. #include <sys/dxe.h>
  9.  
  10. void *_dxe_load(char *name)
  11. {
  12.   dxe_header dh;
  13.   char *data;
  14.   int h;
  15.  
  16.   h = _open(name, 0);
  17.   if (h < 0)
  18.     return 0;
  19.   _read(h, &dh, sizeof(dh));
  20.   if (dh.magic != DXE_MAGIC)
  21.   {
  22.     _close(h);
  23.     errno = ENOEXEC;
  24.     return 0;
  25.   }
  26.  
  27.   data = (char *)malloc(dh.element_size);
  28.   if (data == 0)
  29.   {
  30.     _close(h);
  31.     errno = ENOMEM;
  32.     return 0;
  33.   }
  34.  
  35.   _read(h, data, dh.element_size);
  36.  
  37.   {
  38.     long relocs[dh.nrelocs];
  39.     int i;
  40.     _read(h, relocs, sizeof(long)*dh.nrelocs);
  41.     _close(h);
  42.  
  43.     for (i=0; i<dh.nrelocs; i++)
  44.       *(long *)(data + relocs[i]) += (int)data;
  45.   }
  46.  
  47.   return (void *)(data + dh.symbol_offset);
  48. }
  49.