1 /*****************************************************************************
2 * file.c: file input (file: access plug-in)
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: file.c,v 1.1 2002/08/04 17:23:41 sam Exp $
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
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.
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.
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, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include <sys/types.h>
35 #include <vlc/input.h>
39 #elif defined( _MSC_VER ) && defined( _WIN32 )
43 /*****************************************************************************
45 *****************************************************************************/
46 static int Open( vlc_object_t *p_this )
48 input_thread_t * p_input = (input_thread_t *)p_this;
49 char * psz_name = p_input->psz_name;
51 struct stat stat_info;
52 input_socket_t * p_access_data;
57 b_stdin = psz_name[0] == '-' && psz_name[1] == '\0';
59 if( !b_stdin && (i_stat = stat( psz_name, &stat_info )) == (-1) )
61 msg_Err( p_input, "cannot stat() file `%s' (%s)",
62 psz_name, strerror(errno));
66 p_input->pf_read = input_FDRead;
67 p_input->pf_set_program = input_SetProgram;
68 p_input->pf_set_area = NULL;
69 p_input->pf_seek = input_FDSeek;
71 vlc_mutex_lock( &p_input->stream.stream_lock );
73 if( *p_input->psz_access && !strncmp( p_input->psz_access, "stream", 7 ) )
76 p_input->stream.b_pace_control = 0;
77 p_input->stream.b_seekable = 0;
78 p_input->stream.p_selected_area->i_size = 0;
83 p_input->stream.b_pace_control = 1;
87 p_input->stream.b_seekable = 0;
88 p_input->stream.p_selected_area->i_size = 0;
90 else if( S_ISREG(stat_info.st_mode) || S_ISCHR(stat_info.st_mode)
91 || S_ISBLK(stat_info.st_mode) )
93 p_input->stream.b_seekable = 1;
94 p_input->stream.p_selected_area->i_size = stat_info.st_size;
96 else if( S_ISFIFO(stat_info.st_mode)
97 #if !defined( SYS_BEOS ) && !defined( WIN32 )
98 || S_ISSOCK(stat_info.st_mode)
102 p_input->stream.b_seekable = 0;
103 p_input->stream.p_selected_area->i_size = 0;
107 vlc_mutex_unlock( &p_input->stream.stream_lock );
108 msg_Err( p_input, "unknown file type for `%s'", psz_name );
113 p_input->stream.p_selected_area->i_tell = 0;
114 p_input->stream.i_method = INPUT_METHOD_FILE;
115 vlc_mutex_unlock( &p_input->stream.stream_lock );
117 msg_Dbg( p_input, "opening file `%s'", psz_name );
118 p_access_data = malloc( sizeof(input_socket_t) );
119 p_input->p_access_data = (void *)p_access_data;
120 if( p_access_data == NULL )
122 msg_Err( p_input, "out of memory" );
128 p_access_data->i_handle = 0;
130 else if( (p_access_data->i_handle = open( psz_name,
131 /*O_NONBLOCK | O_LARGEFILE*/ 0 )) == (-1) )
133 msg_Err( p_input, "cannot open file %s (%s)", psz_name,
135 free( p_access_data );
142 /*****************************************************************************
144 *****************************************************************************/
146 set_description( _("Standard filesystem file reading") );
147 set_capability( "access", 50 );
148 add_shortcut( "stream" );
149 set_callbacks( Open, __input_FDClose );