"Fossies" - the Fresh Open Source Software Archive

Member "dosemu-1.4.0/src/plugin/midimisc/mid_o_pipe.c" (29 Nov 2006, 2144 Bytes) of package /linux/misc/old/dosemu-1.4.0.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "mid_o_pipe.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  *  Copyright (C) 2006 Stas Sergeev <stsp@users.sourceforge.net>
    3  *
    4  * The below copyright strings have to be distributed unchanged together
    5  * with this file. This prefix can not be modified or separated.
    6  */
    7 
    8 /*
    9  *  This program is free software; you can redistribute it and/or modify
   10  *  it under the terms of the GNU General Public License as published by
   11  *  the Free Software Foundation; either version 2 of the License, or
   12  *  (at your option) any later version.
   13  *
   14  *  This program is distributed in the hope that it will be useful,
   15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17  *  GNU General Public License for more details.
   18  *
   19  *  You should have received a copy of the GNU General Public License
   20  *  along with this program; if not, write to the Free Software
   21  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   22  */
   23 #include "emu.h"
   24 #include "init.h"
   25 #include "sound/midi.h"
   26 #include <sys/types.h>
   27 #include <sys/stat.h>
   28 #include <unistd.h>
   29 #include <fcntl.h>
   30 #include <errno.h>
   31 #include <string.h>
   32 
   33 
   34 static int pipe_fd = -1;
   35 static const char *midopipe_name = "MIDI Output: named pipe";
   36 
   37 static int midopipe_init(void)
   38 {
   39     char *name = DOSEMU_MIDI_PATH;
   40     mkfifo(name, 0666);
   41     pipe_fd =
   42     RPT_SYSCALL(open(name, O_WRONLY | O_CREAT | O_NONBLOCK, 0666));
   43     if (pipe_fd == -1) {
   44     S_printf("%s: unable to open %s for writing: %s\n",
   45          midopipe_name, name, strerror(errno));
   46     return 0;
   47     }
   48     return 1;
   49 }
   50 
   51 static void midopipe_done(void)
   52 {
   53     if (pipe_fd == -1)
   54     return;
   55     close(pipe_fd);
   56     pipe_fd = -1;
   57 }
   58 
   59 static void midopipe_reset(void)
   60 {
   61 }
   62 
   63 static void midopipe_write(unsigned char val)
   64 {
   65     if (pipe_fd == -1)
   66     return;
   67     write(pipe_fd, &val, 1);
   68 }
   69 
   70 CONSTRUCTOR(static int midopipe_register(void))
   71 {
   72     struct midi_out_plugin midopipe;
   73     midopipe.name = midopipe_name;
   74     midopipe.init = midopipe_init;
   75     midopipe.done = midopipe_done;
   76     midopipe.reset = midopipe_reset;
   77     midopipe.write = midopipe_write;
   78     midopipe.stop = NULL;
   79     return midi_register_output_plugin(midopipe);
   80 }