Ignore:
Timestamp:
2015-10-06T19:01:36Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0328987
Parents:
f1f7584
Message:

UNIX-like I/O functions should use errno to return error code for many reasons.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    rf1f7584 r6afc9d7  
    2727 */
    2828
     29#include <errno.h>
    2930#include <stdio.h>
    3031#include <stdlib.h>
     
    166167
    167168                if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0)
    168                         goto exit;
     169                        goto error;
    169170
    170171                rc2 = write(fd, &byte, sizeof(char));
    171                 goto exit;
     172                if (rc2 < 0)
     173                        goto error;
     174                return CMD_SUCCESS;
    172175        }
    173176
     
    183186                rc = write(fd, buffer, to_write);
    184187                if (rc <= 0) {
    185                         printf("%s: Error writing file (%zd).\n", cmdname, rc);
     188                        printf("%s: Error writing file (%d).\n", cmdname, errno);
    186189                        close(fd);
    187190                        return CMD_FAILURE;
     
    191194
    192195        free(buffer);
    193 exit:
    194         rc = close(fd);
    195 
    196         if (rc != 0 || rc2 < 0) {
    197                 printf("%s: Error writing file (%zd).\n", cmdname, rc);
    198                 return CMD_FAILURE;
    199         }
     196
     197        if (close(fd) < 0)
     198                goto error;
    200199
    201200        return CMD_SUCCESS;
     201error:
     202        printf("%s: Error writing file (%d).\n", cmdname, errno);
     203        return CMD_FAILURE;
    202204}
Note: See TracChangeset for help on using the changeset viewer.