Commit 8a4429ff authored by Ralf Habacker's avatar Ralf Habacker

added pipe related files real

parent 182a261b
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-pipe-unix.c unix related pipe implementation
*
* Copyright (C) 2002, 2003, 2006 Red Hat, Inc.
* Copyright (C) 2003 CodeFactory AB
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "dbus-protocol.h"
#include "dbus-string.h"
#include "dbus-internals.h"
#include "dbus-pipe.h"
#include <io.h>
/**
* write data to a pipe.
*
* @param pipe the pipe instance
* @param buffer the buffer to write data from
* @param start the first byte in the buffer to write
* @param len the number of bytes to try to write
* @param error error return
* @returns the number of bytes written or -1 on error
*/
int
_dbus_pipe_write (DBusPipe *pipe,
const DBusString *buffer,
int start,
int len,
DBusError *error)
{
int written;
written = _dbus_write (pipe->fd_or_handle, buffer, start, len);
if (written < 0)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Writing to pipe: %s\n",
_dbus_strerror (errno));
}
return written;
}
/**
* close a pipe.
*
* @param pipe the pipe instance
* @param error return location for an error
* @returns #FALSE if error is set
*/
int
_dbus_pipe_close (DBusPipe *pipe,
DBusError *error)
{
if (_dbus_close (pipe->fd_or_handle, error) < 0)
{
return -1;
}
else
{
_dbus_pipe_invalidate (pipe);
return 0;
}
}
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-pipe-win.c windows related pipe implementation
*
* Copyright (C) 2002, 2003, 2006 Red Hat, Inc.
* Copyright (C) 2003 CodeFactory AB
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "dbus-protocol.h"
#include "dbus-string.h"
#include "dbus-internals.h"
#include "dbus-pipe.h"
#include <io.h>
/**
* write data to a pipe.
*
* @param pipe the pipe instance
* @param buffer the buffer to write data from
* @param start the first byte in the buffer to write
* @param len the number of bytes to try to write
* @param error error return
* @returns the number of bytes written or -1 on error
*/
int
_dbus_pipe_write (DBusPipe *pipe,
const DBusString *buffer,
int start,
int len,
DBusError *error)
{
int written;
const char *buffer_c = _dbus_string_get_const_data (buffer);
written = _write (pipe->fd_or_handle, buffer_c + start, len);
if (written < 0)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Writing to pipe: %s\n",
strerror (errno));
}
return written;
}
/**
* close a pipe.
*
* @param pipe the pipe instance
* @param error return location for an error
* @returns #FALSE if error is set
*/
int
_dbus_pipe_close (DBusPipe *pipe,
DBusError *error)
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
if (_close (pipe->fd_or_handle) < 0)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
"Could not close pipe %d: %s", pipe->fd_or_handle, strerror (errno));
return -1;
}
else
{
_dbus_pipe_invalidate (pipe);
return 0;
}
}
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-pipe.c pipe implementation (internal to D-Bus implementation)
*
* Copyright (C) 2002, 2003, 2006 Red Hat, Inc.
* Copyright (C) 2003 CodeFactory AB
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "dbus-pipe.h"
/*
* init a pipe instance.
*
* @param pipe the pipe
* @param fd the file descriptor to init from
*/
void
_dbus_pipe_init (DBusPipe *pipe,
int fd)
{
pipe->fd_or_handle = fd;
}
/**
* init a pipe with stdout
*
* @param pipe the pipe
*/
void
_dbus_pipe_init_stdout (DBusPipe *pipe)
{
_dbus_pipe_init (pipe, 1);
}
/**
* check if a pipe is valid; pipes can be set invalid, similar to
* a -1 file descriptor.
*
* @param pipe the pipe instance
* @returns #FALSE if pipe is not valid
*/
dbus_bool_t
_dbus_pipe_is_valid(DBusPipe *pipe)
{
return pipe->fd_or_handle >= 0;
}
/**
* Check if a pipe is stdout or stderr.
*
* @param pipe the pipe instance
* @returns #TRUE if pipe is one of the standard out/err channels
*/
dbus_bool_t
_dbus_pipe_is_stdout_or_stderr (DBusPipe *pipe)
{
return pipe->fd_or_handle == 1 || pipe->fd_or_handle == 2;
}
/**
* Initializes a pipe to an invalid value.
* @param pipe the pipe
*/
void
_dbus_pipe_invalidate (DBusPipe *pipe)
{
pipe->fd_or_handle = -1;
}
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-sysdeps.h Wrappers around system/libc features (internal to D-Bus implementation)
*
* Copyright (C) 2002, 2003 Red Hat, Inc.
* Copyright (C) 2003 CodeFactory AB
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef DBUS_PIPE_H
#define DBUS_PIPE_H
#include <config.h>
#include <dbus/dbus-types.h>
#include <dbus/dbus-errors.h>
#include <dbus/dbus-string.h>
typedef struct {
int fd_or_handle;
} DBusPipe;
void _dbus_pipe_init (DBusPipe *pipe,
int fd);
void _dbus_pipe_init_stdout (DBusPipe *pipe);
int _dbus_pipe_write (DBusPipe *pipe,
const DBusString *buffer,
int start,
int len,
DBusError *error);
int _dbus_pipe_close (DBusPipe *pipe,
DBusError *error);
dbus_bool_t _dbus_pipe_is_valid (DBusPipe *pipe);
void _dbus_pipe_invalidate (DBusPipe *pipe);
dbus_bool_t _dbus_pipe_is_stdout_or_stderr (DBusPipe *pipe);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment