delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/11/20/12:57:52

Message-Id: <199711201757.MAA10438@delorie.com>
From: Oberhumer Markus <k3040e4 AT c210 DOT edvz DOT uni-linz DOT ac DOT at>
Subject: Re: 971114: misc notes
To: eliz AT is DOT elta DOT co DOT il (Eli Zaretskii)
Date: Thu, 20 Nov 1997 18:49:02 +0100 (MET)
Cc: k3040e4 AT c210 DOT edvz DOT uni-linz DOT ac DOT at, djgpp-workers AT delorie DOT com,
dj AT delorie DOT com
In-Reply-To: <Pine.SUN.3.91.971119191941.9972C-100000@is> from "Eli Zaretskii" at Nov 19, 97 07:24:53 pm
Return-Read-To: markus DOT oberhumer AT jk DOT uni-linz DOT ac DOT at
Mime-Version: 1.0

/*
> > - long time ago, when the MiNT kernel was adding UNIX support
> >   to TOS (on the Atari ST) they introduced /dev/a/ as a 
> >   synonym for a:\ - this really worked fine.
> >   IMHO it is much better than those //A/ or \\A\ suggestions.
> 
> Can you suggest a clean change that will implement this?  The problem is 
> that the /dev/ hack in `putpath' causes grief to people who create a 
> directory by that name (``dev'' for ``development'', get it?) and then 
> come back crying that many of the DJGPP programs don't work with files in 
> that directory.
> 
> It might be that the way I changed the original DJ's code is stupid and 
> can be made better, so everybody is happy.  If so, please suggest a 
> change.
> 
> But if there's no simple solution that will allow people to have a 
> directory called /dev/ *and* support /dev/c/ -> c:/ translation, I don't 
> think we should make a bad situation any worse.

Currently all access to /dev/ is prohibited anyway.

What do you think about the version below ?

It reserves the virtual directories /dev/a/.../dev/z/ (we are also
reserving /dev/{null|tty}) and makes all other files in /dev/ available.
Single letter files like /dev/a also remain accessible.

We still need some minor changes in dosexec.c, but then it should
be working.

Markus
*/


/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <libc/dosio.h>
#include <libc/farptrgs.h>
#include <go32.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

void
_put_path(const char *path)
{
  _put_path2(path, 0);
}

void
_put_path2(const char *path, int offset)
{
  int o = __tb + offset;
  int space = _go32_info_block.size_of_transfer_buffer - offset;
  const char *p = path;

  if (path == 0 || space <= 8)
  {
    errno = EFAULT;
    abort();
  }

  _farsetsel(_dos_ds);

  if (p[0] && p[1] == ':')
    p += 2;
  if (strcmp(p, "/dev/null") == 0)
    path = "nul";
  else if (strcmp(p, "/dev/tty") == 0)
    path = "con";
  else if (strncmp(p, "/dev/", 5) == 0)
  {
    /* new code: map /dev/a/ to a:/ (lowercase directories only) */
    if (p[5] >= 'a' && p[5] <= 'z' && p[6] == '/')
    {
      _farnspokeb(o++, p[5]);
      _farnspokeb(o++, ':');
      path = p + 6;
      space -= 2;
    }
#if 0
    /* disabled code from 971114 which just removes '/dev/' */
    else if (p[5] != 0)
      path = p + 5;
#endif
  }

  /* collapse multiple slashes to a single slash */
  for ( ; *path; path++)
  {
    if (path[0] != '/' || path[1] != '/')
    {
      if (--space < 2) /* safety check */
	break;
      _farnspokeb(o++, *path);
    }
  }

  /* remove trailing slash if it doesn't
     represent the root directory */
  if (o-2 >= __tb+offset
      && _farnspeekb(o-1) == '/'
      && _farnspeekb(o-2) != ':')
    o--;

  /* null terminate it */
  _farnspokeb(o, 0);
}


#ifdef TEST
#include <stdio.h>

void test(const char *p)
{
  int o = __tb, i, c;
  char buf[1024];
  _put_path(p);
  for (i = 0; i < 1023 && ((c = _farpeekb(_dos_ds,o++)) != 0); i++)
    buf[i] = c;
  buf[i] = 0;
  printf("%-30s %s\n", p, buf);
}

int main()
{
  test("c:");
  test("c:/");
  test("c://");
  test("c://");
  test("\\\\NET\\\\CDROM\\");
  test("//NET/CDROM/");
  test("c:/dev/djgpp");
  test("/dev/djgpp");
  test("/dev/null");
  test("/dev/tty");
  test("/dev/zero");
  test("/dev/null/");
  test("/dev/c");
  test("/dev/c/");
  test("/dev/c//");
  test("/dev/c/dos/");
  return 0;
}
#endif

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019