drivers/lcd/pcf8574_lcd_backpack.c: Fix seek method. Had the same problems as noted for st7032.c driver.
This commit is contained in:
parent
508f90605c
commit
dc5d18a092
@ -1371,36 +1371,68 @@ static off_t pcf8574_lcd_seek(FAR struct file *filep, off_t offset, int whence)
|
|||||||
{
|
{
|
||||||
FAR struct inode *inode = filep->f_inode;
|
FAR struct inode *inode = filep->f_inode;
|
||||||
FAR struct pcf8574_lcd_dev_s *priv = (FAR struct pcf8574_lcd_dev_s *)inode->i_private;
|
FAR struct pcf8574_lcd_dev_s *priv = (FAR struct pcf8574_lcd_dev_s *)inode->i_private;
|
||||||
|
off_t pos;
|
||||||
int maxpos;
|
int maxpos;
|
||||||
|
|
||||||
nxsem_wait(&priv->sem_excl);
|
nxsem_wait(&priv->sem_excl);
|
||||||
|
|
||||||
maxpos = priv->cfg.rows * priv->cfg.cols + (priv->cfg.rows - 1);
|
maxpos = priv->cfg.rows * priv->cfg.cols + (priv->cfg.rows - 1);
|
||||||
|
pos = filep->f_pos;
|
||||||
|
|
||||||
switch (whence)
|
switch (whence)
|
||||||
{
|
{
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
filep->f_pos += offset;
|
pos += offset;
|
||||||
if (filep->f_pos > maxpos)
|
if (pos > maxpos)
|
||||||
filep->f_pos = maxpos;
|
{
|
||||||
break;
|
pos = maxpos;
|
||||||
|
}
|
||||||
|
else if (pos < 0)
|
||||||
|
{
|
||||||
|
pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
case SEEK_SET:
|
filep->f_pos = pos;
|
||||||
filep->f_pos = offset;
|
break;
|
||||||
if (filep->f_pos > maxpos)
|
|
||||||
filep->f_pos = maxpos;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SEEK_END:
|
case SEEK_SET:
|
||||||
filep->f_pos = maxpos;
|
pos = offset;
|
||||||
break;
|
if (pos > maxpos)
|
||||||
|
{
|
||||||
|
pos = maxpos;
|
||||||
|
}
|
||||||
|
else if (pos < 0)
|
||||||
|
{
|
||||||
|
pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
filep->f_pos = pos;
|
||||||
/* Return EINVAL if the whence argument is invalid */
|
break;
|
||||||
filep->f_pos = -EINVAL;
|
|
||||||
|
case SEEK_END:
|
||||||
|
pos = maxpos + offset;
|
||||||
|
if (pos > maxpos)
|
||||||
|
{
|
||||||
|
pos = maxpos;
|
||||||
|
}
|
||||||
|
else if (pos < 0)
|
||||||
|
{
|
||||||
|
pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
filep->f_pos = pos;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
/* Return EINVAL if the whence argument is invalid */
|
||||||
|
|
||||||
|
pos = (off_t)-EINVAL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nxsem_post(&priv->sem_excl);
|
nxsem_post(&priv->sem_excl);
|
||||||
return filep->f_pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user