summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-09-18 11:50:38 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-09-18 11:50:38 +0200
commit21fc4aa4615803896f28bfc8e0009504effdd690 (patch)
treed923bd3819859fb6093abce5f682013da37e8130
parent6c881352db2c4200b89b3d9700e7353f36ae823f (diff)
inotail.c: Use BUFSIZ and post-increment
For consistency reasons mostly :-)
-rw-r--r--inotail.c22
-rw-r--r--inotail.h3
2 files changed, 11 insertions, 14 deletions
diff --git a/inotail.c b/inotail.c
index fdb2919..02cf462 100644
--- a/inotail.c
+++ b/inotail.c
@@ -94,7 +94,7 @@ static inline void setup_file(struct file_struct *f)
{
f->fd = f->i_watch = -1;
f->size = 0;
- f->blksize = BUFFER_SIZE;
+ f->blksize = BUFSIZ;
f->ignore = 0;
}
@@ -256,7 +256,7 @@ static ssize_t tail_pipe_lines(struct file_struct *f, unsigned long n_lines)
tmp = emalloc(sizeof(struct line_buf));
while (1) {
- if ((rc = read(f->fd, tmp->buf, BUFFER_SIZE)) <= 0) {
+ if ((rc = read(f->fd, tmp->buf, BUFSIZ)) <= 0) {
if (rc < 0 && (errno == EINTR || errno == EAGAIN))
continue;
else
@@ -269,15 +269,15 @@ static ssize_t tail_pipe_lines(struct file_struct *f, unsigned long n_lines)
/* Count the lines in the current buffer */
while ((p = memchr(p, '\n', tmp->buf + rc - p))) {
- ++p;
- ++tmp->n_lines;
+ p++;
+ tmp->n_lines++;
}
total_lines += tmp->n_lines;
/* Try to append to the previous buffer if there's enough free
* space
*/
- if (tmp->n_bytes + last->n_bytes < BUFFER_SIZE) {
+ if (tmp->n_bytes + last->n_bytes < BUFSIZ) {
memcpy(&last->buf[last->n_bytes], tmp->buf, tmp->n_bytes);
last->n_bytes += tmp->n_bytes;
last->n_lines += tmp->n_lines;
@@ -304,8 +304,8 @@ static ssize_t tail_pipe_lines(struct file_struct *f, unsigned long n_lines)
/* Count incomplete lines */
if (last->buf[last->n_bytes - 1] != '\n') {
- ++last->n_lines;
- ++total_lines;
+ last->n_lines++;
+ total_lines++;
}
/* Skip unneeded buffers */
@@ -315,10 +315,10 @@ static ssize_t tail_pipe_lines(struct file_struct *f, unsigned long n_lines)
p = tmp->buf;
if (total_lines > n_lines) {
- size_t j;
+ unsigned long j;
for (j = total_lines - n_lines; j; --j) {
p = memchr(p, '\n', tmp->buf + tmp->n_bytes - p);
- ++p;
+ p++;
}
}
@@ -330,13 +330,11 @@ static ssize_t tail_pipe_lines(struct file_struct *f, unsigned long n_lines)
for (tmp = tmp->next; tmp; tmp = tmp->next)
if ((rc = write(STDOUT_FILENO, tmp->buf, tmp->n_bytes)) <= 0) {
- /* e.g. when writing to a pipe which gets closed */
fprintf(stderr, "Error: Could not write to stdout (%s)\n", strerror(errno));
goto out;
}
rc = 0;
-
out:
while (first) {
tmp = first->next;
@@ -351,7 +349,7 @@ out:
static ssize_t tail_pipe_bytes(struct file_struct *f, unsigned long n_bytes)
{
ssize_t rc;
- char buf[BUFFER_SIZE];
+ char buf[BUFSIZ];
/* We will just tail everything here */
while ((rc = read(f->fd, buf, f->blksize)) > 0) {
diff --git a/inotail.h b/inotail.h
index dcc948d..f9eabba 100644
--- a/inotail.h
+++ b/inotail.h
@@ -9,7 +9,6 @@
#include <sys/types.h>
-#define BUFFER_SIZE 4096
#define DEFAULT_N_LINES 10 /* Number of items to tail. */
/* tail modes */
@@ -27,7 +26,7 @@ struct file_struct {
/* struct for linked list of buffers/lines in tail_pipe_lines */
struct line_buf {
- char buf[BUFFER_SIZE];
+ char buf[BUFSIZ];
size_t n_lines;
size_t n_bytes;
struct line_buf *next;
dd6832c1974b880acd23d3'>mei: bus: Add device enabling and disabling APISamuel Ortiz1-0/+3 It should be left to the drivers to enable and disable the device on the MEI bus when e.g getting probed. For drivers to be able to safely call the enable and disable hooks, the mei_cl_ops must be set before it's probed and thus this should happen before registering the device on the MEI bus. Hence the mei_cl_add_device() prototype change. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 2013-03-29mei: bus: Implement bus driver data setter/getterSamuel Ortiz1-0/+3 MEI drivers should be able to carry their private data around. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 2013-03-29mei: bus: Initial implementation for I/O routinesSamuel Ortiz1-0/+11 Signed-off-by: Samuel Ortiz <sameo@linux.intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 2013-03-29mei: bus: Implement driver registrationSamuel Ortiz1-0/+7 Signed-off-by: Samuel Ortiz <sameo@linux.intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 2013-03-29mei: bus: Initial MEI Client bus type implementationSamuel Ortiz1-0/+20 mei client bus will present some of the mei clients as devices for other standard subsystems Implement the probe, remove, match, device addtion routines, along with the sysfs and uevent ones. mei_cl_device_id is also added to mod_devicetable.h A mei-cleint-bus.txt document describing the rationale and the API usage is also added while ABI/testing/sysfs-bus-mei describeis the modalias ABI. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>