home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 May / pcp151c.iso / misc / src / install / otherinsmod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-07  |  1.0 KB  |  55 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <unistd.h>
  4. #include <zlib.h>
  5.  
  6. #include "cpio.h"
  7.  
  8. /* hack */
  9. int insmod_main(int argc, char ** argv);
  10.  
  11. /* librpm.a provides this */
  12. int cpioInstallArchive(gzFile stream, void * mappings,
  13.                int numMappings, void * cb, void * cbData,
  14.                char ** failedFile);
  15.  
  16.  
  17. int ourInsmodCommand(int argc, char ** argv) {
  18.     char * file;
  19.     char finalName[100];
  20.     char * chptr;
  21.     gzFile stream; 
  22.     int rc, rmObj = 0;
  23.  
  24.     if (argc < 2) {
  25.     fprintf(stderr, "usage: insmod <module>.o [params]\n");
  26.     return 1;
  27.     }
  28.  
  29.     file = argv[1];
  30.     if (access(file, R_OK)) {
  31.     /* it might be having a ball */
  32.     stream = gzopen("/modules/modules.cgz", "r");
  33.     if (!stream) {
  34.         return 1;
  35.     }
  36.  
  37.     chptr = strrchr(file, '/');
  38.     if (chptr) file = chptr + 1;
  39.     sprintf(finalName, "/tmp/%s", file);
  40.  
  41.     if (installCpioFile(stream, file, finalName, 0))
  42.         return 1;
  43.  
  44.     rmObj = 1;
  45.     file = finalName;
  46.     }
  47.  
  48.     argv[1] = file;
  49.     rc = insmod_main(argc, argv);
  50.     if (rmObj) unlink(file);
  51.  
  52.     return rc;
  53. }
  54.  
  55.