mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
fs/vfs: file_read() is an internal OS interface and should not errors via the errno
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* configs/nucleo-f3x1re/src/stm32_ajoystick.c
|
* configs/nucleo-f3x1re/src/stm32_ajoystick.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2014, 2016-2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -210,13 +210,12 @@ static int ajoy_sample(FAR const struct ajoy_lowerhalf_s *lower,
|
|||||||
MAX_ADC_CHANNELS * sizeof(struct adc_msg_s));
|
MAX_ADC_CHANNELS * sizeof(struct adc_msg_s));
|
||||||
if (nread < 0)
|
if (nread < 0)
|
||||||
{
|
{
|
||||||
int errcode = get_errno();
|
if (nread != -EINTR)
|
||||||
if (errcode != EINTR)
|
|
||||||
{
|
{
|
||||||
ierr("ERROR: read failed: %d\n", errcode);
|
ierr("ERROR: read failed: %d\n", (int)nread);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -errcode;
|
return nread;
|
||||||
}
|
}
|
||||||
else if (nread < NJOYSTICK_CHANNELS * sizeof(struct adc_msg_s))
|
else if (nread < NJOYSTICK_CHANNELS * sizeof(struct adc_msg_s))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* configs/nucleo-l476rg/src/stm32_ajoystick.c
|
* configs/nucleo-l476rg/src/stm32_ajoystick.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2014, 2016-2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -209,13 +209,12 @@ static int ajoy_sample(FAR const struct ajoy_lowerhalf_s *lower,
|
|||||||
MAX_ADC_CHANNELS * sizeof(struct adc_msg_s));
|
MAX_ADC_CHANNELS * sizeof(struct adc_msg_s));
|
||||||
if (nread < 0)
|
if (nread < 0)
|
||||||
{
|
{
|
||||||
int errcode = get_errno();
|
if (nread != -EINTR)
|
||||||
if (errcode != EINTR)
|
|
||||||
{
|
{
|
||||||
ierr("ERROR: read failed: %d\n", errcode);
|
ierr("ERROR: read failed: %d\n", (int)nread);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -errcode;
|
return nread;
|
||||||
}
|
}
|
||||||
else if (nread < NJOYSTICK_CHANNELS * sizeof(struct adc_msg_s))
|
else if (nread < NJOYSTICK_CHANNELS * sizeof(struct adc_msg_s))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -191,13 +191,12 @@ static int ajoy_sample(FAR const struct ajoy_lowerhalf_s *lower,
|
|||||||
MAX_ADC_CHANNELS * sizeof(struct adc_msg_s));
|
MAX_ADC_CHANNELS * sizeof(struct adc_msg_s));
|
||||||
if (nread < 0)
|
if (nread < 0)
|
||||||
{
|
{
|
||||||
int errcode = get_errno();
|
if (nread != iEINTR)
|
||||||
if (errcode != EINTR)
|
|
||||||
{
|
{
|
||||||
ierr("ERROR: read failed: %d\n", errcode);
|
ierr("ERROR: read failed: %d\n", (int)nread);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -errcode;
|
return nread;
|
||||||
}
|
}
|
||||||
else if (nread < 2 * sizeof(struct adc_msg_s))
|
else if (nread < 2 * sizeof(struct adc_msg_s))
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-1
@@ -95,7 +95,7 @@ ssize_t file_pread(FAR struct file *filep, FAR void *buf, size_t nbytes,
|
|||||||
ret = file_read(filep, buf, nbytes);
|
ret = file_read(filep, buf, nbytes);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = get_errno();
|
errcode = -ret;
|
||||||
ret = ERROR;
|
ret = ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-13
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* fs/vfs/fs_read.c
|
* fs/vfs/fs_read.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2012-2014, 2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2012-2014, 2016-2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -102,15 +102,7 @@ ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes)
|
|||||||
ret = (int)inode->u.i_ops->read(filep, (FAR char *)buf, (size_t)nbytes);
|
ret = (int)inode->u.i_ops->read(filep, (FAR char *)buf, (size_t)nbytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If an error occurred, set errno and return -1 (ERROR) */
|
/* Return the number of bytes read (or possibly an error code) */
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
set_errno(-ret);
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Otherwise, return the number of bytes read */
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -180,11 +172,14 @@ ssize_t read(int fd, FAR void *buf, size_t nbytes)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Then let file_read do all of the work. Note that file_read()
|
/* Then let file_read do all of the work. */
|
||||||
* sets the errno variable.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = file_read(filep, buf, nbytes);
|
ret = file_read(filep, buf, nbytes);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
set_errno((int)-ret);
|
||||||
|
ret = ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -402,9 +402,8 @@ static uint16_t sendfile_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
ret = file_read(pstate->snd_file, dev->d_appdata, sndlen);
|
ret = file_read(pstate->snd_file, dev->d_appdata, sndlen);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
int errcode = get_errno();
|
nerr("ERROR: Failed to read from input file: %d\n", (int)ret);
|
||||||
nerr("ERROR: Failed to read from input file: %d\n", errcode);
|
pstate->snd_sent = ret;
|
||||||
pstate->snd_sent = -errcode;
|
|
||||||
goto end_wait;
|
goto end_wait;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user