home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / dos / namefromlock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  4.9 KB  |  208 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: namefromlock.c,v 1.7 1996/11/08 11:27:54 aros Exp $
  4.     $Log: namefromlock.c,v $
  5.     Revision 1.7  1996/11/08 11:27:54  aros
  6.     All OS function use now Amiga types
  7.  
  8.     Moved intuition-driver protos to intuition_intern.h
  9.  
  10.     Revision 1.6  1996/10/24 15:50:33  aros
  11.     Use the official AROS macros over the __AROS versions.
  12.  
  13.     Revision 1.5  1996/09/13 17:50:07  digulla
  14.     Use IPTR
  15.  
  16.     Revision 1.4  1996/08/13 13:52:49  digulla
  17.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  18.     Replaced AROS_LA by AROS_LHA
  19.  
  20.     Revision 1.3  1996/08/12 14:20:38  digulla
  21.     Added aliases
  22.  
  23.     Revision 1.2  1996/08/01 17:40:55  digulla
  24.     Added standard header for all files
  25.  
  26.     Desc:
  27.     Lang: english
  28. */
  29. #include <clib/exec_protos.h>
  30. #include <dos/exall.h>
  31. #include <dos/filesystem.h>
  32. #include "dos_intern.h"
  33.  
  34. /*****************************************************************************
  35.  
  36.     NAME */
  37.     #include <clib/dos_protos.h>
  38.  
  39.     AROS_LH3(BOOL, NameFromLock,
  40.  
  41. /*  SYNOPSIS */
  42.     AROS_LHA(BPTR,   lock,   D1),
  43.     AROS_LHA(STRPTR, buffer, D2),
  44.     AROS_LHA(LONG,   length, D3),
  45.  
  46. /*  LOCATION */
  47.     struct DosLibrary *, DOSBase, 67, Dos)
  48.  
  49. /*  FUNCTION
  50.     Get the full path name associated with a lock to a file or
  51.     directory into a user supplied buffer.
  52.  
  53.     INPUTS
  54.     lock   - Lock to file or directory.
  55.     buffer - Buffer to fill. Contains a NUL terminated string if
  56.          all went well.
  57.     length - Size of the buffer in bytes.
  58.  
  59.     RESULT
  60.     !=0 if all went well, 0 in case of an error. IoErr() will
  61.     give additional information in that case.
  62.  
  63.     NOTES
  64.  
  65.     EXAMPLE
  66.  
  67.     BUGS
  68.  
  69.     SEE ALSO
  70.  
  71.     INTERNALS
  72.  
  73.     HISTORY
  74.     29-10-95    digulla automatically created from
  75.                 dos_lib.fd and clib/dos_protos.h
  76.  
  77. *****************************************************************************/
  78.  
  79. /*****************************************************************************
  80.  
  81.     NAME
  82.     #include <clib/dos_protos.h>
  83.  
  84.     AROS_LH3(LONG, NameFromFH,
  85.  
  86.     SYNOPSIS
  87.     AROS_LHA(BPTR  , fh, D1),
  88.     AROS_LHA(STRPTR, buffer, D2),
  89.     AROS_LHA(LONG  , len, D3),
  90.  
  91.     LOCATION
  92.     struct DosLibrary *, DOSBase, 68, Dos)
  93.  
  94.     FUNCTION
  95.     Get the full path name associated with file-handle into a
  96.     user supplied buffer.
  97.  
  98.     INPUTS
  99.     fh     - File-handle to file or directory.
  100.     buffer - Buffer to fill. Contains a NUL terminated string if
  101.          all went well.
  102.     length - Size of the buffer in bytes.
  103.  
  104.     RESULT
  105.     !=0 if all went well, 0 in case of an error. IoErr() will
  106.     give additional information in that case.
  107.  
  108.     NOTES
  109.  
  110.     EXAMPLE
  111.  
  112.     BUGS
  113.  
  114.     SEE ALSO
  115.  
  116.     INTERNALS
  117.  
  118.     HISTORY
  119.     29-10-95    digulla automatically created from
  120.                 dos_lib.fd and clib/dos_protos.h
  121.  
  122. *****************************************************************************/
  123. /*AROS alias NameFromFH NameFromLock */
  124. {
  125.     AROS_LIBFUNC_INIT
  126.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  127.  
  128.     STRPTR s1, s2, name;
  129.     struct Unit *curlock, *oldlock=NULL;
  130.     struct ExAllData *ead=(struct ExAllData *)buffer;
  131.     LONG error;
  132.  
  133.     /* Get pointer to filehandle */
  134.     struct FileHandle *fh=(struct FileHandle *)BADDR(lock);
  135.  
  136.     /* Get pointer to process structure */
  137.     struct Process *me=(struct Process *)FindTask(NULL);
  138.  
  139.     /* Get pointer to I/O request. Use stackspace for now. */
  140.     struct IOFileSys io,*iofs=&io;
  141.  
  142.     /* Prepare I/O request. */
  143.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  144.     iofs->IOFS.io_Message.mn_ReplyPort     =&me->pr_MsgPort;
  145.     iofs->IOFS.io_Message.mn_Length     =sizeof(struct IOFileSys);
  146.     iofs->IOFS.io_Device= fh==NULL?DOSBase->dl_NulHandler:fh->fh_Device;
  147.  
  148.     /* Construct the name from top to bottom */
  149.     name=buffer+length;
  150.     *--name=0;
  151.     curlock= fh==NULL?DOSBase->dl_NulLock:fh->fh_Unit;
  152.     /* Loop over path */
  153.     do
  154.     {
  155.     /* Read name of current lock (into the user supplied buffer) */
  156.     iofs->IOFS.io_Unit=curlock;
  157.     iofs->IOFS.io_Command=FSA_EXAMINE;
  158.     iofs->io_Args[0]=(IPTR)buffer;
  159.     iofs->io_Args[1]=name-buffer;
  160.     iofs->io_Args[2]=ED_TYPE;
  161.     DoIO(&iofs->IOFS);
  162.     error=iofs->io_DosError;
  163.  
  164.     /* Move name to the top of the buffer. */
  165.     if(!error)
  166.     {
  167.         s1=s2=ead->ed_Name;
  168.         while(*s2++)
  169.         ;
  170.         if(ead->ed_Type==ST_ROOT)
  171.         *--name=':';
  172.         else if(oldlock!=NULL)
  173.         *--name='/';
  174.         s2--;
  175.         while(s2>s1)
  176.         *--name=*--s2;
  177.     }
  178.  
  179.     /* Read the parent's lock (if there is a parent) */
  180.     if(!error&&ead->ed_Type!=ST_ROOT)
  181.     {
  182.         iofs->IOFS.io_Command=FSA_OPEN;
  183.         iofs->io_Args[0]=(IPTR)"/";
  184.         iofs->io_Args[1]=0;
  185.         DoIO(&iofs->IOFS);
  186.         curlock=iofs->IOFS.io_Unit;
  187.         error=iofs->io_DosError;
  188.     }
  189.  
  190.     /* Free the old lock if it was allocated by NameFromLock(). */
  191.     if(oldlock!=NULL)
  192.     {
  193.         iofs->IOFS.io_Unit=oldlock;
  194.         iofs->IOFS.io_Command=FSA_CLOSE;
  195.         DoIO(&iofs->IOFS);
  196.     }
  197.     oldlock=curlock;
  198.     }while(!error&&ead->ed_Type!=ST_ROOT);
  199.  
  200.     /* Move the name from the top to the bottom of the buffer. */
  201.     while((*buffer++=*name++)!=0)
  202.     ;
  203.     /* All done. */
  204.     me->pr_Result2=error;
  205.     return !error;
  206.     AROS_LIBFUNC_EXIT
  207. } /* NameFromLock */
  208.