bstream.c revision eab441e29d159ff1e25d3af8cd61798e641989b2
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2012 Marcel Telka <marcel@telka.sk>
*/
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <libintl.h>
#include <limits.h>
#include "bstream.h"
#include "util.h"
#include "audio.h"
#include "byteorder.h"
#include "main.h"
int str_errno;
char *
{
switch (serrno) {
case STR_ERR_NO_ERR:
return (gettext("No error"));
case STR_ERR_NO_REG_FILE:
return (gettext("Not a regular file"));
case STR_ERR_NO_READ_STDIN:
return (gettext("Stdin not open for reading"));
case STR_ERR_AU_READ_ERR:
return (gettext("Unable to read au header"));
return (gettext("Unsupported au format"));
case STR_ERR_AU_BAD_HEADER:
return (gettext("Bad au header"));
case STR_ERR_WAV_READ_ERR:
return (gettext("Unable to read wav header"));
return (gettext("Unsupported wav format"));
case STR_ERR_WAV_BAD_HEADER:
return (gettext("Bad wav header"));
case STR_ERR_ISO_READ_ERR:
return (gettext("Unable to read ISO header"));
case STR_ERR_ISO_BAD_HEADER:
return (gettext("Invalid ISO header or not an ISO"));
default:
return (gettext("unknown error"));
}
}
static int
{
str_errno = 0;
return (0);
return (0);
}
return (1);
}
static int
{
str_errno = 0;
return (1);
}
static int
{
str_errno = 0;
}
static int
{
str_errno = 0;
}
/*
* with reverse byteorder
*/
static int
{
int cnt;
str_errno = 0;
if (cnt > 0) {
int i;
for (i = 0; i < cnt; i += 2) {
}
}
return (cnt);
}
/*
* This will change the byteorder in the buffer but that is fine with us.
*/
static int
{
int i;
str_errno = 0;
if (size > 0) {
for (i = 0; i < size; i += 2) {
}
}
}
static int
{
int fd;
str_errno = 0;
free(h);
}
static int
{
str_errno = 0;
free(h);
return (0);
}
static int
{
str_errno = 0;
return (1);
}
return (1);
}
free(h);
return (0);
}
static int
{
str_errno = 0;
sz -= PRE_DEF_AU_HDR_LEN;
return (1);
return (1);
free(h);
return (0);
}
/* ARGSUSED */
static void
{
}
static void
{
}
static void
{
return;
}
SEEK_SET) < 0) {
return;
}
}
static void
{
}
open_file_read_stream(char *file)
{
int fd;
str_errno = 0;
return (NULL);
return (NULL);
}
if (fd < 0)
return (NULL);
h = (bstreamhandle)my_zalloc(sizeof (*h));
h->bstr_read = file_stream_read;
h->bstr_close = file_stream_close;
h->bstr_size = file_stream_size;
return (h);
}
open_iso_read_stream(char *fname)
{
h = open_file_read_stream(fname);
/* If we don't have a valid handle immediately return NULL */
if (h == NULL)
return (NULL);
if (debug)
(void) printf("Checking the ISO file header\n");
/* Check to see if we have a valid sized ISO image */
if (iso_size < ISO9660_HEADER_SIZE) {
if (debug)
(void) printf("ISO header size not sane.\n");
h->bstr_close(h);
return (NULL);
}
if (debug)
(void) printf("ISO header size is sane.\n");
/* Skip over the boot block sector of the ISO. */
/*
* Try to read in the ISO Descriptor and validate this
* is in fact an ISO image.
*/
/*
* Bytes one through five of a valid image should contain:
* - BEA01 (ISO 13490 image)
* - CD001 (ISO 9660 or ISO 13490 image)
* - CDROM (High Sierra format, the ISO 9660 predecessor)
* If neither is the case then we should close the stream,
* set str_errno, and return NULL.
*/
if (debug)
(void) printf("Invalid ISO identifier.\n");
h->bstr_close(h);
return (NULL);
}
} else {
h->bstr_close(h);
return (NULL);
}
/*
* Our ISO image is valid rewind the stream
* and return the handle.
*/
if (debug)
(void) printf("ISO header is sane.\n");
h->bstr_rewind(h);
return (h);
}
open_stdin_read_stream(void)
{
int mode;
str_errno = 0;
return (NULL);
}
mode &= 3;
return (NULL);
}
h = (bstreamhandle)my_zalloc(sizeof (*h));
h->bstr_fd = 0;
h->bstr_read = file_stream_read;
h->bstr_close = stdin_stream_close;
h->bstr_size = file_stream_size;
return (h);
}
open_au_read_stream(char *fname)
{
str_errno = 0;
if (fd < 0)
return (NULL);
goto au_open_failed;
}
goto au_open_failed;
}
goto au_open_failed;
}
goto au_open_failed;
}
goto au_open_failed;
}
goto au_open_failed;
}
} else {
}
if (data_size == 0) {
goto au_open_failed;
}
goto au_open_failed;
}
h = (bstreamhandle)my_zalloc(sizeof (*h));
h->bstr_close = file_stream_close;
h->bstr_size = audio_stream_size;
h->bstr_rewind = au_stream_rewind;
h->bstr_private = (void *)data_size;
return (h);
return (NULL);
}
open_wav_read_stream(char *fname)
{
str_errno = 0;
if (fd < 0)
return (NULL);
goto wav_open_failed;
}
goto wav_open_failed;
}
goto wav_open_failed;
}
goto wav_open_failed;
}
goto wav_open_failed;
}
goto wav_open_failed;
}
h = (bstreamhandle)my_zalloc(sizeof (*h));
h->bstr_read = file_stream_read;
h->bstr_close = file_stream_close;
h->bstr_size = audio_stream_size;
h->bstr_rewind = wav_stream_rewind;
h->bstr_private = (void *)data_size;
return (h);
return (NULL);
}
open_aur_read_stream(char *fname)
{
h = open_file_read_stream(fname);
if (h != NULL) {
}
return (h);
}
open_au_write_stream(char *fname)
{
str_errno = 0;
fd = -1;
/* O_RDWR because we need to read while closing */
if (fd < 0)
}
h = (bstreamhandle)my_zalloc(sizeof (*h));
return (h);
if (fd != -1)
return (NULL);
}
open_wav_write_stream(char *fname)
{
str_errno = 0;
fd = -1;
if (fd < 0)
}
h = (bstreamhandle)my_zalloc(sizeof (*h));
h->bstr_write = file_stream_write;
return (h);
if (fd != -1)
return (NULL);
}
open_aur_write_stream(char *fname)
{
int fd;
str_errno = 0;
if (fd < 0)
return (NULL);
h = (bstreamhandle)my_zalloc(sizeof (*h));
h->bstr_close = file_stream_close;
return (h);
}
open_file_write_stream(char *fname)
{
int fd;
str_errno = 0;
if (fd < 0)
return (NULL);
h = (bstreamhandle)my_zalloc(sizeof (*h));
h->bstr_write = file_stream_write;
h->bstr_close = file_stream_close;
return (h);
}
open_temp_file_stream(void)
{
char *t;
int fd;
str_errno = 0;
t = (char *)get_tmp_name();
return (NULL);
if (debug)
if (fd < 0)
return (NULL);
(void) unlink(t);
h = (bstreamhandle)my_zalloc(sizeof (*h));
h->bstr_read = file_stream_read;
h->bstr_write = file_stream_write;
h->bstr_close = file_stream_close;
h->bstr_size = file_stream_size;
return (h);
}
/*
* check_avail_temp_space returns 0 if there is adequate space
* in the temporary directory, or a non-zero error code if
* something goes wrong
*/
int
{
u_longlong_t free_size = 0;
return (errno);
}
return (ENOMEM);
return (0);
}
char *
get_tmp_name(void)
{
char *t;
char *envptr;
/*
* generate temp directory path based on this order:
* user specified (-m option), temp env variable,
* and finally /tmp if nothing is found.
*/
if (alt_tmp_dir) {
/* copy and leave room for temp filename */
} else {
} else {
}
}
/*
* no need to check if path is valid. statvfs will catch
* it later and fail with a proper error message.
*/
return (t);
}