mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 17:48:54 +08:00
drivers/lcd/st7032.c: Fix seek method. Was not taking into account the offset for the SEEK_END case. On errors, it was clobbering the filep->f_pos setting.
This commit is contained in:
+21
-10
@@ -903,43 +903,54 @@ static off_t st7032_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 st7032_dev_s *priv = (FAR struct st7032_dev_s *)inode->i_private;
|
FAR struct st7032_dev_s *priv = (FAR struct st7032_dev_s *)inode->i_private;
|
||||||
int maxpos;
|
off_t maxpos;
|
||||||
|
off_t pos;
|
||||||
|
|
||||||
nxsem_wait(&priv->sem_excl);
|
nxsem_wait(&priv->sem_excl);
|
||||||
|
|
||||||
maxpos = ST7032_MAX_ROW * ST7032_MAX_COL + (ST7032_MAX_ROW - 1);
|
maxpos = ST7032_MAX_ROW * ST7032_MAX_COL + (ST7032_MAX_ROW - 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;
|
pos = maxpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filep->f_pos = pos;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEEK_SET:
|
case SEEK_SET:
|
||||||
filep->f_pos = offset;
|
pos = offset;
|
||||||
if (filep->f_pos > maxpos)
|
if (pos > maxpos)
|
||||||
{
|
{
|
||||||
filep->f_pos = maxpos;
|
pos = maxpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filep->f_pos = pos;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEEK_END:
|
case SEEK_END:
|
||||||
filep->f_pos = maxpos;
|
pos = maxpos + offset;
|
||||||
|
if (pos > maxpos)
|
||||||
|
{
|
||||||
|
pos = maxpos;
|
||||||
|
}
|
||||||
|
|
||||||
|
filep->f_pos = pos;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Return EINVAL if the whence argument is invalid */
|
/* Return EINVAL if the whence argument is invalid */
|
||||||
|
|
||||||
filep->f_pos = -EINVAL;
|
pos = (off_t)-EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxsem_post(&priv->sem_excl);
|
nxsem_post(&priv->sem_excl);
|
||||||
return filep->f_pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user