home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / posix / unistd / chdir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-31  |  1010 b   |  56 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <unistd.h>
  4. #include <errno.h>
  5. #include <fcntl.h>
  6. #include <go32.h>
  7. #include <ctype.h>
  8. #include <dpmi.h>
  9. #include <libc/dosio.h>
  10.  
  11. int
  12. __chdir (const char *dirname)
  13. {
  14.   __dpmi_regs r;
  15.  
  16.   if (dirname == 0)
  17.   {
  18.     errno = EINVAL;
  19.     return -1;
  20.   }
  21.  
  22.   if (dirname[0] == 0)
  23.   {
  24.     errno = ENOENT;
  25.     return -1;
  26.   }
  27.  
  28.   if (dirname[1] != ':' || dirname[2])
  29.   {
  30.     if(_USE_LFN)
  31.       r.x.ax = 0x713b;
  32.     else
  33.       r.h.ah = 0x3b;
  34.     r.x.dx = __tb_offset;
  35.     r.x.ds = __tb_segment;
  36.     _put_path(dirname);
  37.     __dpmi_int(0x21, &r);
  38.     if(r.x.flags & 1)
  39.     {
  40.       errno = __doserr_to_errno(r.x.ax);
  41.       return -1;
  42.     }
  43.   }
  44.  
  45.   if (dirname[1] == ':')
  46.   {
  47.     /* Change current drive also.  This *will* work if
  48.        the directory change above worked. */
  49.     r.h.ah = 0x0e;
  50.     r.h.dl = (dirname[0] & 0x1f) - 1;
  51.     __dpmi_int(0x21, &r);
  52.   }
  53.  
  54.   return 0;
  55. }
  56.