1 /*****************************************************************************
2 * file.c: file input (file: access plug-in)
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: file.c,v 1.7 2002/06/01 12:31:58 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 void input_getfunctions( function_list_t * );
47 static int FileOpen ( input_thread_t * );
49 /*****************************************************************************
50 * Build configuration tree.
51 *****************************************************************************/
56 SET_DESCRIPTION( _("Standard filesystem file reading") )
57 ADD_CAPABILITY( ACCESS, 50 )
58 ADD_SHORTCUT( "stream" )
62 input_getfunctions( &p_module->p_functions->access );
65 MODULE_DEACTIVATE_START
66 MODULE_DEACTIVATE_STOP
68 /*****************************************************************************
69 * Functions exported as capabilities. They are declared as static so that
70 * we don't pollute the namespace too much.
71 *****************************************************************************/
72 static void input_getfunctions( function_list_t * p_function_list )
74 #define input p_function_list->functions.access
75 input.pf_open = FileOpen;
76 input.pf_read = input_FDRead;
77 input.pf_close = input_FDClose;
78 input.pf_set_program = input_SetProgram;
79 input.pf_set_area = NULL;
80 input.pf_seek = input_FDSeek;
84 /*****************************************************************************
85 * FileOpen: open the file
86 *****************************************************************************/
87 static int FileOpen( input_thread_t * p_input )
89 char * psz_name = p_input->psz_name;
91 struct stat stat_info;
92 input_socket_t * p_access_data;
97 b_stdin = psz_name[0] == '-' && psz_name[1] == '\0';
99 if( !b_stdin && (i_stat = stat( psz_name, &stat_info )) == (-1) )
101 msg_Err( p_input, "cannot stat() file `%s' (%s)",
102 psz_name, strerror(errno));
106 vlc_mutex_lock( &p_input->stream.stream_lock );
108 if( *p_input->psz_access && !strncmp( p_input->psz_access, "stream", 7 ) )
111 p_input->stream.b_pace_control = 0;
112 p_input->stream.b_seekable = 0;
113 p_input->stream.p_selected_area->i_size = 0;
118 p_input->stream.b_pace_control = 1;
122 p_input->stream.b_seekable = 0;
123 p_input->stream.p_selected_area->i_size = 0;
125 else if( S_ISREG(stat_info.st_mode) || S_ISCHR(stat_info.st_mode)
126 || S_ISBLK(stat_info.st_mode) )
128 p_input->stream.b_seekable = 1;
129 p_input->stream.p_selected_area->i_size = stat_info.st_size;
131 else if( S_ISFIFO(stat_info.st_mode)
132 #if !defined( SYS_BEOS ) && !defined( WIN32 )
133 || S_ISSOCK(stat_info.st_mode)
137 p_input->stream.b_seekable = 0;
138 p_input->stream.p_selected_area->i_size = 0;
142 vlc_mutex_unlock( &p_input->stream.stream_lock );
143 msg_Err( p_input, "unknown file type for `%s'", psz_name );
148 p_input->stream.p_selected_area->i_tell = 0;
149 p_input->stream.i_method = INPUT_METHOD_FILE;
150 vlc_mutex_unlock( &p_input->stream.stream_lock );
152 msg_Dbg( p_input, "opening file `%s'", psz_name );
153 p_access_data = malloc( sizeof(input_socket_t) );
154 p_input->p_access_data = (void *)p_access_data;
155 if( p_access_data == NULL )
157 msg_Err( p_input, "out of memory" );
163 p_access_data->i_handle = 0;
165 else if( (p_access_data->i_handle = open( psz_name,
166 /*O_NONBLOCK | O_LARGEFILE*/ 0 )) == (-1) )
168 msg_Err( p_input, "cannot open file %s (%s)", psz_name,
170 free( p_access_data );