Changes in uspace/app/bdsh/cmds/modules/mkfile/mkfile.c [f9d8c3a:36ab7c7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
rf9d8c3a r36ab7c7 54 54 static struct option const long_options[] = { 55 55 {"size", required_argument, 0, 's'}, 56 {"sparse", no_argument, 0, 'p'},57 56 {"help", no_argument, 0, 'h'}, 58 57 {0, 0, 0, 0} … … 70 69 " -h, --help A short option summary\n" 71 70 " -s, --size sz Size of the file\n" 72 " -p, --sparse Create a sparse file\n"73 71 "\n" 74 72 "Size is a number followed by 'k', 'm' or 'g' for kB, MB, GB.\n" … … 117 115 ssize_t file_size; 118 116 ssize_t total_written; 119 ssize_t to_write, rc , rc2 = 0;117 ssize_t to_write, rc; 120 118 char *file_name; 121 119 void *buffer; 122 bool create_sparse = false;123 120 124 121 file_size = 0; … … 127 124 128 125 for (c = 0, optind = 0, opt_ind = 0; c != -1;) { 129 c = getopt_long(argc, argv, " ps:h", long_options, &opt_ind);126 c = getopt_long(argc, argv, "s:h", long_options, &opt_ind); 130 127 switch (c) { 131 128 case 'h': 132 129 help_cmd_mkfile(HELP_LONG); 133 130 return CMD_SUCCESS; 134 case 'p':135 create_sparse = true;136 break;137 131 case 's': 138 132 file_size = read_size(optarg); … … 162 156 } 163 157 164 if (create_sparse && file_size > 0) {165 const char byte = 0x00;166 167 if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0)168 goto exit;169 170 rc2 = write(fd, &byte, sizeof(char));171 goto exit;172 }173 174 158 buffer = calloc(BUFFER_SIZE, 1); 175 159 if (buffer == NULL) { … … 190 174 } 191 175 192 free(buffer);193 exit:194 176 rc = close(fd); 195 196 if (rc != 0 || rc2 < 0) { 177 if (rc != 0) { 197 178 printf("%s: Error writing file (%zd).\n", cmdname, rc); 198 179 return CMD_FAILURE; 199 180 } 200 181 182 free(buffer); 183 201 184 return CMD_SUCCESS; 202 185 }
Note:
See TracChangeset
for help on using the changeset viewer.