Commit 4e84bd2c authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

linsys_sdi: simplify and fix sysfs usage

parent 0aa6c19c
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <limits.h>
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_plugin.h> #include <vlc_plugin.h>
...@@ -1660,47 +1661,35 @@ static int HandleSDBuffer( demux_t *p_demux, uint8_t *p_buffer, ...@@ -1660,47 +1661,35 @@ static int HandleSDBuffer( demux_t *p_demux, uint8_t *p_buffer,
static int ReadULSysfs( const char *psz_fmt, unsigned int i_link ) static int ReadULSysfs( const char *psz_fmt, unsigned int i_link )
{ {
char psz_file[MAXLEN], psz_data[MAXLEN]; char psz_file[MAXLEN];
char *psz_tmp;
int i_fd;
ssize_t i_ret;
unsigned int i_data; unsigned int i_data;
snprintf( psz_file, sizeof(psz_file) - 1, psz_fmt, i_link ); snprintf( psz_file, sizeof(psz_file), psz_fmt, i_link );
if ( (i_fd = vlc_open( psz_file, O_RDONLY )) < 0 ) FILE *stream = vlc_fopen( psz_file, "rt" );
return i_fd; if( stream == NULL )
i_ret = read( i_fd, psz_data, sizeof(psz_data) );
close( i_fd );
if ( i_ret < 0 )
return i_ret;
i_data = strtoul( psz_data, &psz_tmp, 0 );
if ( *psz_tmp != '\n' )
return -1; return -1;
return i_data; int ret = fscanf( stream, "%u", &i_data );
fclose( stream );
return (ret == 1 && i_data <= INT_MAX) ? (int)i_data : -1;
} }
static ssize_t WriteULSysfs( const char *psz_fmt, unsigned int i_link, static int WriteULSysfs( const char *psz_fmt, unsigned int i_link,
unsigned int i_buf ) unsigned int i_buf )
{ {
char psz_file[MAXLEN], psz_data[MAXLEN]; char psz_file[MAXLEN];
int i_fd;
ssize_t i_ret;
snprintf( psz_file, sizeof(psz_file) -1, psz_fmt, i_link );
snprintf( psz_data, sizeof(psz_data) -1, "%u\n", i_buf ); snprintf( psz_file, sizeof(psz_file), psz_fmt, i_link );
if ( (i_fd = vlc_open( psz_file, O_WRONLY )) < 0 ) FILE *stream = vlc_fopen( psz_file, "wt" );
return i_fd; if( stream == NULL )
return -1;
i_ret = write( i_fd, psz_data, strlen(psz_data) + 1 ); int ret = fprintf( stream, "%u\n", i_buf );
close( i_fd ); fclose( stream );
return i_ret; return ret;
} }
static int InitCapture( demux_t *p_demux ) static int InitCapture( demux_t *p_demux )
......
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