Changes in uspace/app/bdsh/cmds/modules/mkfile/mkfile.c [c672195:f9d8c3a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
rc672195 rf9d8c3a 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 29 28 30 29 #include <stdio.h> … … 55 54 static struct option const long_options[] = { 56 55 {"size", required_argument, 0, 's'}, 56 {"sparse", no_argument, 0, 'p'}, 57 57 {"help", no_argument, 0, 'h'}, 58 58 {0, 0, 0, 0} … … 70 70 " -h, --help A short option summary\n" 71 71 " -s, --size sz Size of the file\n" 72 " -p, --sparse Create a sparse file\n" 72 73 "\n" 73 74 "Size is a number followed by 'k', 'm' or 'g' for kB, MB, GB.\n" … … 116 117 ssize_t file_size; 117 118 ssize_t total_written; 118 ssize_t to_write, rc ;119 ssize_t to_write, rc, rc2 = 0; 119 120 char *file_name; 120 121 void *buffer; 122 bool create_sparse = false; 121 123 122 124 file_size = 0; … … 125 127 126 128 for (c = 0, optind = 0, opt_ind = 0; c != -1;) { 127 c = getopt_long(argc, argv, " s:h", long_options, &opt_ind);129 c = getopt_long(argc, argv, "ps:h", long_options, &opt_ind); 128 130 switch (c) { 129 131 case 'h': 130 132 help_cmd_mkfile(HELP_LONG); 131 133 return CMD_SUCCESS; 134 case 'p': 135 create_sparse = true; 136 break; 132 137 case 's': 133 138 file_size = read_size(optarg); … … 155 160 printf("%s: failed to create file %s.\n", cmdname, file_name); 156 161 return CMD_FAILURE; 162 } 163 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; 157 172 } 158 173 … … 175 190 } 176 191 192 free(buffer); 193 exit: 177 194 rc = close(fd); 178 if (rc != 0) { 195 196 if (rc != 0 || rc2 < 0) { 179 197 printf("%s: Error writing file (%zd).\n", cmdname, rc); 180 198 return CMD_FAILURE; 181 199 } 182 183 free(buffer);184 200 185 201 return CMD_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.