Ignore:
File:
1 edited

Legend:

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

    r86cf96d rbc41f3a3  
    2727 */
    2828
     29#include <errno.h>
    2930#include <stdio.h>
    3031#include <stdlib.h>
     
    3334#include <sys/types.h>
    3435#include <sys/stat.h>
    35 #include <fcntl.h>
    3636#include <macros.h>
    3737#include <getopt.h>
     
    165165                const char byte = 0x00;
    166166
    167                 if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0)
    168                         goto exit;
     167                if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0) {
     168                        close(fd);
     169                        goto error;
     170                }
    169171
    170172                rc2 = write(fd, &byte, sizeof(char));
    171                 goto exit;
     173                if (rc2 < 0) {
     174                        close(fd);
     175                        goto error;
     176                }
     177                return CMD_SUCCESS;
    172178        }
    173179
     
    183189                rc = write(fd, buffer, to_write);
    184190                if (rc <= 0) {
    185                         printf("%s: Error writing file (%zd).\n", cmdname, rc);
     191                        printf("%s: Error writing file (%d).\n", cmdname, errno);
    186192                        close(fd);
     193                        free(buffer);
    187194                        return CMD_FAILURE;
    188195                }
     
    191198
    192199        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         }
     200
     201        if (close(fd) < 0)
     202                goto error;
    200203
    201204        return CMD_SUCCESS;
     205error:
     206        printf("%s: Error writing file (%d).\n", cmdname, errno);
     207        return CMD_FAILURE;
    202208}
Note: See TracChangeset for help on using the changeset viewer.