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 @@
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <limits.h>
#include <vlc_common.h>
#include <vlc_plugin.h>
......@@ -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 )
{
char psz_file[MAXLEN], psz_data[MAXLEN];
char *psz_tmp;
int i_fd;
ssize_t i_ret;
char psz_file[MAXLEN];
unsigned int i_data;
snprintf( psz_file, sizeof(psz_file) - 1, psz_fmt, i_link );
if ( (i_fd = vlc_open( psz_file, O_RDONLY )) < 0 )
return i_fd;
i_ret = read( i_fd, psz_data, sizeof(psz_data) );
close( i_fd );
if ( i_ret < 0 )
return i_ret;
snprintf( psz_file, sizeof(psz_file), psz_fmt, i_link );
i_data = strtoul( psz_data, &psz_tmp, 0 );
if ( *psz_tmp != '\n' )
FILE *stream = vlc_fopen( psz_file, "rt" );
if( stream == NULL )
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 )
{
char psz_file[MAXLEN], psz_data[MAXLEN];
int i_fd;
ssize_t i_ret;
snprintf( psz_file, sizeof(psz_file) -1, psz_fmt, i_link );
char psz_file[MAXLEN];
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 )
return i_fd;
FILE *stream = vlc_fopen( psz_file, "wt" );
if( stream == NULL )
return -1;
i_ret = write( i_fd, psz_data, strlen(psz_data) + 1 );
close( i_fd );
return i_ret;
int ret = fprintf( stream, "%u\n", i_buf );
fclose( stream );
return ret;
}
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