home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 03dos / setmydir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  734 b   |  34 lines

  1. /*
  2.  *    setmydir -- try to change the DOS environment
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <local\std.h>
  8.  
  9. main(argc, argv)
  10. int argc;
  11. char **argv;
  12. {
  13.     register char **p;
  14.     static char var[] = { "MYDIR" };
  15.     static char pgm[MAXNAME + 1] = { "setmydir" };
  16.     extern void fatal(char *, char *, int);
  17.     extern void getpname(char *, char *);
  18.  
  19.     /* use an alias if one is given to this program */
  20.     if (_osmajor >= 3)
  21.         getpname(*argv, pgm);
  22.  
  23.     /* try to add the MYDIR variable to the environment */
  24.     if (putenv("MYDIR=c:\\mydir") == -1)
  25.         fatal(pgm, "Error changing environment", 1);
  26.  
  27.     /* display the environment for this process */
  28.     for (p = environ; *p; p++) {
  29.         printf("%s\n", *p);
  30.     }
  31.     
  32.     exit(0);
  33. }
  34.