home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJLSR200.ZIP / src / libc / dxe / dxeload.c next >
Encoding:
C/C++ Source or Header  |  1995-04-22  |  889 b   |  42 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.   _read(h, data, dh.element_size);
  29.  
  30.   {
  31.     long relocs[dh.nrelocs];
  32.     int i;
  33.     _read(h, relocs, sizeof(long)*dh.nrelocs);
  34.     _close(h);
  35.  
  36.     for (i=0; i<dh.nrelocs; i++)
  37.       *(long *)(data + relocs[i]) += (int)data;
  38.   }
  39.  
  40.   return (void *)(data + dh.symbol_offset);
  41. }
  42.