X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fsmb.c;h=c192f2a9fe00cc36721ca23bad9046367aead113;hb=3da67c9857f763a793eaf995697b923e4d5a6309;hp=e45a466f2904dcbe3b163caa7fedfacd0729f402;hpb=2e1e0990567db4bd21567f830a8dfd4f027ddca3;p=vlc diff --git a/modules/access/smb.c b/modules/access/smb.c index e45a466f29..c192f2a9fe 100644 --- a/modules/access/smb.c +++ b/modules/access/smb.c @@ -24,10 +24,10 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include + #include -#include +#include #ifdef WIN32 #ifdef HAVE_FCNTL_H @@ -109,8 +109,8 @@ struct access_sys_t static void Win32AddConnection( access_t *, char *, char *, char *, char * ); #endif -void smb_auth( const char *srv, const char *shr, char *wg, int wglen, - char *un, int unlen, char *pw, int pwlen ) +static void smb_auth( const char *srv, const char *shr, char *wg, int wglen, + char *un, int unlen, char *pw, int pwlen ) { //wglen = unlen = pwlen = 0; } @@ -220,26 +220,27 @@ static int Open( vlc_object_t *p_this ) if( !smbc_init_context( p_smb ) ) { - msg_Err( p_access, "cannot initialize context (%s)", strerror(errno) ); + msg_Err( p_access, "cannot initialize context (%m)" ); smbc_free_context( p_smb, 1 ); free( psz_uri ); return VLC_EGENERIC; } - if( !(p_file = p_smb->open( p_smb, psz_uri, O_RDONLY, 0 )) ) + if( !(p_file = (p_smb->open)( p_smb, psz_uri, O_RDONLY, 0 )) ) { - msg_Err( p_access, "open failed for '%s' (%s)", - p_access->psz_path, strerror(errno) ); + msg_Err( p_access, "open failed for '%s' (%m)", + p_access->psz_path ); smbc_free_context( p_smb, 1 ); free( psz_uri ); return VLC_EGENERIC; } - p_access->info.i_size = 0; + /* Init p_access */ + STANDARD_READ_ACCESS_INIT; + i_ret = p_smb->fstat( p_smb, p_file, &filestat ); - if( i_ret ) msg_Err( p_access, "stat failed (%s)", strerror(errno) ); + if( i_ret ) msg_Err( p_access, "stat failed (%m)" ); else p_access->info.i_size = filestat.st_size; - #else #ifndef WIN32 @@ -250,35 +251,36 @@ static int Open( vlc_object_t *p_this ) } #endif +/* +** some version of glibc defines open as a macro, causing havoc +** with other macros using 'open' under the hood, such as the +** following one: +*/ +#if defined(smbc_open) && defined(open) +# undef open +#endif if( (i_smb = smbc_open( psz_uri, O_RDONLY, 0 )) < 0 ) { - msg_Err( p_access, "open failed for '%s' (%s)", - p_access->psz_path, strerror(errno) ); + msg_Err( p_access, "open failed for '%s' (%m)", + p_access->psz_path ); free( psz_uri ); return VLC_EGENERIC; } - p_access->info.i_size = 0; + /* Init p_access */ + STANDARD_READ_ACCESS_INIT; + i_ret = smbc_fstat( i_smb, &filestat ); - if( i_ret ) msg_Err( p_access, "stat failed (%s)", strerror(i_ret) ); + if( i_ret ) + { + errno = i_ret; + msg_Err( p_access, "stat failed (%m)" ); + } else p_access->info.i_size = filestat.st_size; #endif free( psz_uri ); - /* Init p_access */ - p_access->pf_read = Read; - p_access->pf_block = NULL; - p_access->pf_seek = Seek; - p_access->pf_control = Control; - p_access->info.i_update = 0; - p_access->info.i_pos = 0; - p_access->info.b_eof = VLC_FALSE; - p_access->info.i_title = 0; - p_access->info.i_seekpoint = 0; - p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) ); - memset( p_sys, 0, sizeof( access_sys_t ) ); - #ifdef USE_CTX p_sys->p_smb = p_smb; p_sys->p_file = p_file; @@ -333,7 +335,7 @@ static int Seek( access_t *p_access, int64_t i_pos ) #endif if( i_ret == -1 ) { - msg_Err( p_access, "seek failed (%s)", strerror(errno) ); + msg_Err( p_access, "seek failed (%m)" ); return VLC_EGENERIC; } @@ -360,7 +362,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len ) #endif if( i_read < 0 ) { - msg_Err( p_access, "read failed (%s)", strerror(errno) ); + msg_Err( p_access, "read failed (%m)" ); return -1; } @@ -457,15 +459,15 @@ static void Win32AddConnection( access_t *p_access, char *psz_path, net_resource.dwType = RESOURCETYPE_DISK; /* Find out server and share names */ - strncpy( psz_server, psz_path, sizeof( psz_server ) ); + strlcpy( psz_server, psz_path, sizeof( psz_server ) ); psz_share[0] = 0; psz_parser = strchr( psz_path, '/' ); if( psz_parser ) { char *psz_parser2 = strchr( ++psz_parser, '/' ); if( psz_parser2 ) - strncpy( psz_share, psz_parser, sizeof( psz_share ) ); - } + strlcpy( psz_share, psz_parser, sizeof( psz_share ) ); + } sprintf( psz_remote, "\\\\%s\\%s", psz_server, psz_share ); net_resource.lpRemoteName = psz_remote; @@ -476,7 +478,7 @@ static void Win32AddConnection( access_t *p_access, char *psz_path, { msg_Dbg( p_access, "connected to %s", psz_remote ); } - else if( i_result != ERROR_ALREADY_ASSIGNED && + else if( i_result != ERROR_ALREADY_ASSIGNED && i_result != ERROR_DEVICE_ALREADY_REMEMBERED ) { msg_Dbg( p_access, "already connected to %s", psz_remote );