home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / dos / doname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  2.3 KB  |  107 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: doname.c,v 1.5 1997/01/27 00:36:17 ldp Exp $
  4.     $Log: doname.c,v $
  5.     Revision 1.5  1997/01/27 00:36:17  ldp
  6.     Polish
  7.  
  8.     Revision 1.4  1996/10/24 15:32:56  aros
  9.     Added missing include
  10.  
  11.     Revision 1.3  1996/09/21 14:14:23  digulla
  12.     Hand DOSBase to DoName()
  13.  
  14.     Revision 1.2  1996/09/13 17:50:06  digulla
  15.     Use IPTR
  16.  
  17.     Revision 1.1  1996/09/11 12:54:45  digulla
  18.     A couple of new DOS functions from M. Fleischer
  19.  
  20.     Desc:
  21.     Lang: english
  22. */
  23. #include <exec/memory.h>
  24. #include <proto/exec.h>
  25. #include <dos/dosextens.h>
  26. #include <dos/filesystem.h>
  27. #include <proto/dos.h>
  28. #include <proto/utility.h>
  29. #include <string.h>
  30. #include "dos_intern.h"
  31.  
  32. LONG DoName(struct IOFileSys *iofs, STRPTR name, struct DosLibrary * DOSBase)
  33. {
  34.     /* extern struct DosLibrary *DOSBase; */
  35.     STRPTR volname, pathname, s1;
  36.     BPTR cur;
  37.     struct DosList *dl;
  38.     struct Device *device;
  39.     struct Unit *unit;
  40.     struct FileHandle *fh;
  41.     struct Process *me=(struct Process *)FindTask(NULL);
  42.  
  43.     if(!Strnicmp(name,"PROGDIR:",8))
  44.     {
  45.     cur=me->pr_HomeDir;
  46.     volname=NULL;
  47.     pathname=name+8;
  48.     }else
  49.     {
  50.     /* Copy volume name */
  51.     cur=me->pr_CurrentDir;
  52.     s1=name;
  53.     pathname=name;
  54.     volname=NULL;
  55.     while(*s1)
  56.         if(*s1++==':')
  57.         {
  58.         volname=(STRPTR)AllocMem(s1-name,MEMF_ANY);
  59.         if(volname==NULL)
  60.             return me->pr_Result2=ERROR_NO_FREE_STORE;
  61.         CopyMem(name,volname,s1-name-1);
  62.         volname[s1-name-1]=0;
  63.         pathname=s1;
  64.         break;
  65.         }
  66.     }
  67.  
  68.     dl=LockDosList(LDF_ALL|LDF_READ);
  69.     if(volname!=NULL)
  70.     {
  71.     /* Find logical device */
  72.     dl=FindDosEntry(dl,volname,LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS);
  73.     if(dl==NULL)
  74.     {
  75.         UnLockDosList(LDF_ALL|LDF_READ);
  76.         FreeMem(volname,s1-name);
  77.         return me->pr_Result2=ERROR_DEVICE_NOT_MOUNTED;
  78.     }
  79.     device=dl->dol_Device;
  80.     unit  =dl->dol_Unit;
  81.     }else if(cur)
  82.     {
  83.     fh=(struct FileHandle *)BADDR(cur);
  84.     device=fh->fh_Device;
  85.     unit  =fh->fh_Unit;
  86.     }else
  87.     {
  88.     device=DOSBase->dl_NulHandler;
  89.     unit  =DOSBase->dl_NulLock;
  90.     }
  91.  
  92.     iofs->IOFS.io_Device =device;
  93.     iofs->IOFS.io_Unit     =unit;
  94.     iofs->io_Args[0]=(IPTR)pathname;
  95.  
  96.     /* Send the request. */
  97.     DoIO(&iofs->IOFS);
  98.  
  99.     if(dl!=NULL)
  100.     UnLockDosList(LDF_ALL|LDF_READ);
  101.  
  102.     if(volname!=NULL)
  103.     FreeMem(volname,s1-name);
  104.  
  105.     return me->pr_Result2=iofs->io_DosError;
  106. }
  107.