home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / dos / io / putpath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-25  |  1.1 KB  |  55 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/dosio.h>
  3. #include <libc/farptrgs.h>
  4. #include <go32.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <errno.h>
  8.  
  9. void
  10. _put_path(const char *path)
  11. {
  12.   _put_path2(path, 0);
  13. }
  14.  
  15. void
  16. _put_path2(const char *path, int offset)
  17. {
  18.   int o, space = _go32_info_block.size_of_transfer_buffer - offset;
  19.  
  20.   if (path == 0)
  21.   {
  22.     errno = EFAULT;
  23.     abort();
  24.   }
  25.  
  26.   if (strcmp(path, "/dev/null") == 0)
  27.     path = "nul";
  28.   if (strcmp(path, "/dev/tty") == 0)
  29.     path = "con";
  30.  
  31.   _farsetsel(_dos_ds);
  32.  
  33.   /* collapse multiple slashes to a single slash */
  34.   for (o=__tb+offset; *path; path++)
  35.   {
  36.     if (path[0] != '/' || path[1] != '/')
  37.     {
  38.       _farnspokeb(o, *path);
  39.       o++;
  40.       if (--space < 2) /* safety check */
  41.     break;
  42.     }
  43.   }
  44.  
  45.   /* remove trailing slash if it doesn't
  46.      represent the root directory */
  47.   if (o-2 >= __tb+offset
  48.       && _farnspeekb(o-1) == '/'
  49.       && _farnspeekb(o-2) != ':')
  50.     o--;
  51.  
  52.   /* null terminate it */
  53.   _farnspokeb(o, 0);
  54. }
  55.