gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

pinfile.cxx (1565B)


      1 /*
      2  *
      3  *  C++ Portable Types Library (PTypes)
      4  *  Version 2.1.1  Released 27-Jun-2007
      5  *
      6  *  Copyright (C) 2001-2007 Hovik Melikyan
      7  *
      8  *  http://www.melikyan.com/ptypes/
      9  *
     10  */
     11 
     12 #ifdef WIN32
     13 #  include <windows.h>
     14 #else
     15 #  include <fcntl.h>
     16 #  include <unistd.h>
     17 #endif
     18 
     19 #include "pstreams.h"
     20 
     21 
     22 namespace ptypes {
     23 
     24 
     25 // *BSD hack
     26 #ifndef O_LARGEFILE
     27 #  define O_LARGEFILE 0
     28 #endif
     29 
     30 
     31 infile::infile()
     32     : instm(), filename(), syshandle(invhandle), peerhandle(invhandle)  {}
     33 
     34 
     35 infile::infile(const char* ifn)
     36     : instm(), filename(ifn), syshandle(invhandle), peerhandle(invhandle)  {}
     37 
     38 
     39 infile::infile(const string& ifn)
     40     : instm(), filename(ifn), syshandle(invhandle), peerhandle(invhandle)  {}
     41 
     42 
     43 infile::~infile() 
     44 {
     45     close(); 
     46 }
     47 
     48 
     49 int infile::classid()
     50 {
     51     return CLASS2_INFILE;
     52 }
     53 
     54 
     55 string infile::get_streamname() 
     56 {
     57     return filename;
     58 }
     59 
     60 
     61 void infile::doopen() 
     62 {
     63     if (syshandle != invhandle)
     64         handle = syshandle;
     65     else
     66     {
     67 #ifdef WIN32
     68         SECURITY_ATTRIBUTES sa;
     69         sa.nLength = sizeof(SECURITY_ATTRIBUTES);
     70         sa.lpSecurityDescriptor = NULL;
     71         sa.bInheritHandle = TRUE;
     72 
     73         handle = int(CreateFileA(filename, GENERIC_READ,
     74             FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, OPEN_EXISTING, 
     75             FILE_FLAG_SEQUENTIAL_SCAN, 0));
     76 #else
     77         handle = ::open(filename, O_RDONLY | O_LARGEFILE);
     78 #endif
     79         if (handle == invhandle)
     80             error(uerrno(), "Couldn't open");
     81     }
     82 }
     83 
     84 
     85 void infile::doclose()
     86 {
     87     instm::doclose();
     88     syshandle = invhandle;
     89     peerhandle = invhandle;
     90 }
     91 
     92 
     93 }