diff options
-rw-r--r-- | managemon.c | 4 | ||||
-rw-r--r-- | xmalloc.c | 24 |
2 files changed, 19 insertions, 9 deletions
diff --git a/managemon.c b/managemon.c index ec4586b2..6d1b3d85 100644 --- a/managemon.c +++ b/managemon.c @@ -410,7 +410,9 @@ static int sysfs_open2(char *devnum, char *name, char *attr) * never needs too. */ char buf[200]; - read(fd, buf, sizeof(buf)); + if (read(fd, buf, sizeof(buf)) < 0) + /* pretend not to ignore return value */ + return fd; } return fd; } @@ -35,42 +35,50 @@ void *xmalloc(size_t len) { void *rv = malloc(len); char *msg; + int n; if (rv) return rv; msg = ": memory allocation failure - aborting\n"; - write(2, Name, strlen(Name)); - exit(4+!!write(2, msg, strlen(msg))); + n = write(2, Name, strlen(Name)); + n += write(2, msg, strlen(msg)); + exit(4+!!n); } void *xrealloc(void *ptr, size_t len) { void *rv = realloc(ptr, len); char *msg; + int n; if (rv) return rv; msg = ": memory allocation failure - aborting\n"; - write(2, Name, strlen(Name)); - exit(4+!!write(2, msg, strlen(msg))); + n = write(2, Name, strlen(Name)); + n += write(2, msg, strlen(msg)); + exit(4+!!n); } void *xcalloc(size_t num, size_t size) { void *rv = calloc(num, size); char *msg; + int n; if (rv) return rv; msg = ": memory allocation failure - aborting\n"; - write(2, Name, strlen(Name)); - exit(4+!!write(2, msg, strlen(msg))); + n = write(2, Name, strlen(Name)); + n += write(2, msg, strlen(msg)); + exit(4+!!n); } char *xstrdup(const char *str) { char *rv = strdup(str); char *msg; + int n; if (rv) return rv; msg = ": memory allocation failure - aborting\n"; - write(2, Name, strlen(Name)); - exit(4+!!write(2, msg, strlen(msg))); + n = write(2, Name, strlen(Name)); + n += write(2, msg, strlen(msg)); + exit(4+!!n); } |