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