summaryrefslogtreecommitdiff
path: root/nuttx/fs
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-12-15 07:16:26 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-12-15 07:16:26 -0600
commita25b672daf2fddc82012e014aa12b52cf55a4fda (patch)
tree3704ae2b78062d56c0ff82408c6cc6f78a137f96 /nuttx/fs
parentf3da17d4d462c3575bf6b9cb4fe83b1457e9af3f (diff)
downloadnuttx-a25b672daf2fddc82012e014aa12b52cf55a4fda.tar.gz
nuttx-a25b672daf2fddc82012e014aa12b52cf55a4fda.tar.bz2
nuttx-a25b672daf2fddc82012e014aa12b52cf55a4fda.zip
Trivial enhancement to /proc/uptime
Diffstat (limited to 'nuttx/fs')
-rw-r--r--nuttx/fs/procfs/fs_procfsuptime.c49
1 files changed, 23 insertions, 26 deletions
diff --git a/nuttx/fs/procfs/fs_procfsuptime.c b/nuttx/fs/procfs/fs_procfsuptime.c
index 819214b76..2e46daf1a 100644
--- a/nuttx/fs/procfs/fs_procfsuptime.c
+++ b/nuttx/fs/procfs/fs_procfsuptime.c
@@ -80,11 +80,7 @@
struct uptime_file_s
{
struct procfs_file_s base; /* Base open file structure */
-#ifdef CONFIG_SYSTEM_TIME64
- uint64_t ticktime; /* Sampled 64-bit timer */
-#else
- uint32_t ticktime; /* Sampled 32-bit timer */
-#endif
+ unsigned int linesize; /* Number of valid characters in line[] */
char line[UPTIME_LINELEN]; /* Pre-allocated buffer for formatted lines */
};
@@ -256,47 +252,48 @@ static ssize_t uptime_read(FAR struct file *filep, FAR char *buffer,
#ifdef CONFIG_SYSTEM_TIME64
/* 64-bit timer */
- attr->ticktime = clock_systimer64();
+ ticktime = clock_systimer64();
#else
/* 32-bit timer */
- attr->ticktime = clock_systimer();
+ ticktime = clock_systimer();
#endif
- }
-
- ticktime = attr->ticktime;
#if defined(CONFIG_HAVE_DOUBLE) && defined(CONFIG_LIBC_FLOATINGPOINT)
- /* Convert the system up time to a seconds + hundredths of seconds string */
+ /* Convert the system up time to a seconds + hundredths of seconds string */
- now = (double)ticktime / (double)CLOCKS_PER_SEC;
- linesize = snprintf(attr->line, UPTIME_LINELEN, "%10.2f\n", now);
+ now = (double)ticktime / (double)CLOCKS_PER_SEC;
+ linesize = snprintf(attr->line, UPTIME_LINELEN, "%10.2f\n", now);
#else
- /* Convert the system up time to seconds + hundredths of seconds */
+ /* Convert the system up time to seconds + hundredths of seconds */
- sec = ticktime / CLOCKS_PER_SEC;
- remainder = (unsigned int)(ticktime % CLOCKS_PER_SEC);
- csec = (100 * remainder + (CLOCKS_PER_SEC / 2)) / CLOCKS_PER_SEC;
+ sec = ticktime / CLOCKS_PER_SEC;
+ remainder = (unsigned int)(ticktime % CLOCKS_PER_SEC);
+ csec = (100 * remainder + (CLOCKS_PER_SEC / 2)) / CLOCKS_PER_SEC;
- /* Make sure that rounding did not force the hundredths of a second above 99 */
+ /* Make sure that rounding did not force the hundredths of a second above 99 */
- if (csec > 99)
- {
- sec++;
- csec -= 100;
- }
+ if (csec > 99)
+ {
+ sec++;
+ csec -= 100;
+ }
- /* Convert the seconds + hundredths of seconds to a string */
+ /* Convert the seconds + hundredths of seconds to a string */
- linesize = snprintf(attr->line, UPTIME_LINELEN, "%7lu.%02u\n", sec, csec);
+ linesize = snprintf(attr->line, UPTIME_LINELEN, "%7lu.%02u\n", sec, csec);
#endif
+ /* Save the linesize in case we are re-entered with f_pos > 0 */
+
+ attr->linesize = linesize;
+ }
/* Transfer the system up time to user receive buffer */
offset = filep->f_pos;
- ret = procfs_memcpy(attr->line, linesize, buffer, buflen, &offset);
+ ret = procfs_memcpy(attr->line, attr->linesize, buffer, buflen, &offset);
/* Update the file offset */