Ignore:
File:
1 edited

Legend:

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

    rbc41f3a3 r9d58539  
    2727 */
    2828
    29 #include <errno.h>
    3029#include <stdio.h>
    3130#include <stdlib.h>
     
    3433#include <sys/types.h>
    3534#include <sys/stat.h>
     35#include <fcntl.h>
    3636#include <macros.h>
    3737#include <getopt.h>
     
    126126        argc = cli_count_args(argv);
    127127
    128         for (c = 0, optreset = 1, optind = 0, opt_ind = 0; c != -1;) {
     128        for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
    129129                c = getopt_long(argc, argv, "ps:h", long_options, &opt_ind);
    130130                switch (c) {
     
    165165                const char byte = 0x00;
    166166
    167                 if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0) {
    168                         close(fd);
    169                         goto error;
    170                 }
     167                if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0)
     168                        goto exit;
    171169
    172170                rc2 = write(fd, &byte, sizeof(char));
    173                 if (rc2 < 0) {
    174                         close(fd);
    175                         goto error;
    176                 }
    177                 return CMD_SUCCESS;
     171                goto exit;
    178172        }
    179173
     
    189183                rc = write(fd, buffer, to_write);
    190184                if (rc <= 0) {
    191                         printf("%s: Error writing file (%d).\n", cmdname, errno);
     185                        printf("%s: Error writing file (%zd).\n", cmdname, rc);
    192186                        close(fd);
    193                         free(buffer);
    194187                        return CMD_FAILURE;
    195188                }
     
    198191
    199192        free(buffer);
    200 
    201         if (close(fd) < 0)
    202                 goto error;
     193exit:
     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        }
    203200
    204201        return CMD_SUCCESS;
    205 error:
    206         printf("%s: Error writing file (%d).\n", cmdname, errno);
    207         return CMD_FAILURE;
    208202}
Note: See TracChangeset for help on using the changeset viewer.