home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / dnet / dshterm1_0.lha / lib / st / async_support.c next >
Encoding:
C/C++ Source or Header  |  1992-02-04  |  2.2 KB  |  75 lines

  1. /*
  2.    Async file support. Sits on top of async.c (c) Stone, The SST
  3.    Public domain. email c9107253@cs.newcastle.edu.au
  4. */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/memory.h>
  8. #include <exec/ports.h>
  9. #include <dos/dos.h>
  10. #include <dos/dosextens.h>
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13. #include <st/st_proto.h>
  14.  
  15.  
  16. /** The following routines hide the port so your program
  17.  ** never has to worry about ports at all */
  18.  
  19. /*********************************************************/
  20. void            AEasyClose(struct AFileHandle *afh)
  21. /*********************************************************
  22.         Delete port if last file in list is closed
  23.  *********************************************************/
  24. {
  25. struct APort *ap;
  26.     if(!afh) return;
  27.     ap = afh->APort;
  28.     AClose(afh);
  29.     if(!ap->First) ADeletePort(ap);
  30. }
  31.  
  32. /*********************************************************/
  33. struct AFileHandle
  34.         *AEasyOpen(struct AFileHandle *af, char *name, long mode)
  35. /*********************************************************
  36.                  Open a file using AOpen
  37.        Any open file handle from the required port
  38.        should be supplied or NULL for initial port
  39.  *********************************************************/
  40. {
  41. struct APort *ap;
  42. struct AFileHandle *new_afh;
  43.     if(!af) { if(!(ap = ACreatePort())) return(NULL); }
  44.     else ap = af->APort;
  45.     if(new_afh = AOpen(ap, name, mode)) return(new_afh);
  46.     if(!ap->First) ADeletePort(ap);
  47.     return(NULL);
  48. }
  49.  
  50.  
  51. /*********************************************************/
  52. struct AFileHandle
  53.         *AEasyMakeFD2AFD(struct AFileHandle *af, long fd)
  54. /*********************************************************
  55.        Make an AFileDescriptor from an ordinary fd
  56.        Any open file handle from the required port
  57.        should be supplied or NULL for initial port
  58.  *********************************************************/
  59. {
  60. struct APort *ap;
  61. struct AFileHandle *new_afh;
  62.     if(!af) { if(!(ap = ACreatePort())) return(NULL); }
  63.     else ap = af->APort;
  64.     if(new_afh = AMakeFD2AFD(ap, fd)) return(new_afh);
  65.     if(!ap->First) ADeletePort(ap);
  66.     return(NULL);
  67. }
  68.  
  69. /*********************************************************/
  70. void            ASafeEasyClose(struct AFileHandle **afh)
  71. /*********************************************************/
  72. { AEasyClose(*afh); *afh = NULL; }
  73.  
  74.  
  75.