Changeset 8fd04ba9 in mainline for uspace/app/taskdump/elf_core.c


Ignore:
Timestamp:
2011-07-24T12:48:28Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4022513
Parents:
e16e2ba4
Message:

read_all() and write_all().

File:
1 edited

Legend:

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

    re16e2ba4 r8fd04ba9  
    6767
    6868static off64_t align_foff_up(off64_t, uintptr_t, size_t);
    69 static int write_all(int, const void *, size_t);
    7069static int align_pos(int, size_t);
    7170static int write_mem_area(int, as_area_info_t *, async_sess_t *);
     
    10099
    101100        int fd;
    102         int rc;
     101        ssize_t rc;
    103102        unsigned int i;
    104103
     
    204203
    205204        rc = write_all(fd, &elf_hdr, sizeof(elf_hdr));
    206         if (rc != EOK) {
     205        if (rc != sizeof(elf_hdr)) {
    207206                printf("Failed writing ELF header.\n");
    208207                free(p_hdr);
     
    212211        for (i = 0; i < n_ph; ++i) {
    213212                rc = write_all(fd, &p_hdr[i], sizeof(p_hdr[i]));
    214                 if (rc != EOK) {
     213                if (rc != sizeof(p_hdr[i])) {
    215214                        printf("Failed writing program header.\n");
    216215                        free(p_hdr);
     
    233232
    234233        rc = write_all(fd, &note, sizeof(elf_note_t));
    235         if (rc != EOK) {
     234        if (rc != sizeof(elf_note_t)) {
    236235                printf("Failed writing note header.\n");
    237236                free(p_hdr);
     
    240239
    241240        rc = write_all(fd, "CORE", note.namesz);
    242         if (rc != EOK) {
     241        if (rc != (ssize_t) note.namesz) {
    243242                printf("Failed writing note header.\n");
    244243                free(p_hdr);
     
    254253
    255254        rc = write_all(fd, &pr_status, sizeof(elf_prstatus_t));
    256         if (rc != EOK) {
     255        if (rc != sizeof(elf_prstatus_t)) {
    257256                printf("Failed writing register data.\n");
    258257                free(p_hdr);
     
    304303        size_t total;
    305304        uintptr_t addr;
    306         int rc;
     305        ssize_t rc;
    307306
    308307        addr = area->start_addr;
     
    318317
    319318                rc = write_all(fd, buffer, to_copy);
    320                 if (rc != EOK) {
     319                if (rc != (ssize_t) to_copy) {
    321320                        printf("Failed writing memory contents.\n");
    322321                        return EIO;
     
    326325                total += to_copy;
    327326        }
    328 
    329         return EOK;
    330 }
    331 
    332 /** Write until the buffer is written in its entirety.
    333  *
    334  * This function fails if it cannot write exactly @a len bytes to the file.
    335  *
    336  * @param fd            The file to write to.
    337  * @param buf           Data, @a len bytes long.
    338  * @param len           Number of bytes to write.
    339  *
    340  * @return              EOK on error, return value from write() if writing
    341  *                      failed.
    342  */
    343 static int write_all(int fd, const void *data, size_t len)
    344 {
    345         int cnt = 0;
    346 
    347         do {
    348                 data += cnt;
    349                 len -= cnt;
    350                 cnt = write(fd, data, len);
    351         } while (cnt > 0 && (len - cnt) > 0);
    352 
    353         if (cnt < 0)
    354                 return cnt;
    355 
    356         if (len - cnt > 0)
    357                 return EIO;
    358327
    359328        return EOK;
Note: See TracChangeset for help on using the changeset viewer.