Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/taskdump/symtab.c

    r8fd04ba9 red903174  
    3636 */
    3737
    38 #include <elf/elf.h>
    3938#include <stdio.h>
    4039#include <stdlib.h>
     
    4443#include <fcntl.h>
    4544
     45#include <elf.h>
    4646#include "include/symtab.h"
    4747
     
    5050    elf_section_header_t *shdr);
    5151static int chunk_load(int fd, off64_t start, size_t size, void **ptr);
     52static int read_all(int fd, void *buf, size_t len);
    5253
    5354/** Load symbol table from an ELF file.
     
    8990
    9091        rc = read_all(fd, &elf_hdr, sizeof(elf_header_t));
    91         if (rc != sizeof(elf_header_t)) {
     92        if (rc != EOK) {
    9293                printf("failed reading elf header\n");
    9394                free(stab);
     
    311312
    312313        rc = read_all(fd, sec_hdr, sizeof(elf_section_header_t));
    313         if (rc != sizeof(elf_section_header_t))
     314        if (rc != EOK)
    314315                return EIO;
    315316
     
    330331static int chunk_load(int fd, off64_t start, size_t size, void **ptr)
    331332{
    332         ssize_t rc;
    333         off64_t offs;
    334 
    335         offs = lseek(fd, start, SEEK_SET);
    336         if (offs == (off64_t) -1) {
     333        int rc;
     334
     335        rc = lseek(fd, start, SEEK_SET);
     336        if (rc == (off64_t) -1) {
    337337                printf("failed seeking chunk\n");
    338338                *ptr = NULL;
     
    347347
    348348        rc = read_all(fd, *ptr, size);
    349         if (rc != (ssize_t) size) {
     349        if (rc != EOK) {
    350350                printf("failed reading chunk\n");
    351351                free(*ptr);
     
    357357}
    358358
     359/** Read until the buffer is read in its entirety.
     360 *
     361 * This function fails if it cannot read exactly @a len bytes from the file.
     362 *
     363 * @param fd            The file to read from.
     364 * @param buf           Buffer for storing data, @a len bytes long.
     365 * @param len           Number of bytes to read.
     366 *
     367 * @return              EOK on error, EIO if file is short or return value
     368 *                      from read() if reading failed.
     369 */
     370static int read_all(int fd, void *buf, size_t len)
     371{
     372        int cnt = 0;
     373
     374        do {
     375                buf += cnt;
     376                len -= cnt;
     377                cnt = read(fd, buf, len);
     378        } while (cnt > 0 && (len - cnt) > 0);
     379
     380        if (cnt < 0)
     381                return cnt;
     382
     383        if (len - cnt > 0)
     384                return EIO;
     385
     386        return EOK;
     387}
     388
    359389/** @}
    360390 */
Note: See TracChangeset for help on using the changeset viewer.