Changeset 58898d1d in mainline for uspace/app/bdsh/cmds
- Timestamp:
- 2017-03-24T20:31:54Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8e9b2534
- Parents:
- c9e3692
- Location:
- uspace/app/bdsh/cmds/modules
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
rc9e3692 r58898d1d 31 31 #include <stdlib.h> 32 32 #include <unistd.h> 33 #include <sys/stat.h> 33 34 #include <getopt.h> 34 35 #include <str.h> … … 187 188 size_t offset = 0, copied_bytes = 0; 188 189 off64_t file_size = 0, length = 0; 190 aoff64_t pos = 0; 189 191 190 192 bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0); … … 205 207 close(fd); 206 208 printf("Unable to allocate enough memory to read %s\n", 207 209 fname); 208 210 return 1; 209 211 } 210 212 211 213 if (tail != CAT_FULL_FILE) { 212 file_size = lseek(fd, 0, SEEK_END); 214 struct stat st; 215 216 if (fstat(fd, &st) != EOK) { 217 close(fd); 218 free(buff); 219 printf("Unable to fstat %d\n", fd); 220 return 1; 221 } 222 file_size = st.size; 213 223 if (head == CAT_FULL_FILE) { 214 224 head = file_size; … … 223 233 224 234 if (tail_first) { 225 lseek(fd, (tail >= file_size) ? 0 : (file_size - tail), SEEK_SET);235 pos = (tail >= file_size) ? 0 : (file_size - tail); 226 236 } else { 227 lseek(fd, ((head - tail) >= file_size) ? 0 : (head - tail), SEEK_SET);237 pos = ((head - tail) >= file_size) ? 0 : (head - tail); 228 238 } 229 239 } else … … 243 253 } 244 254 245 bytes = read(fd, buff + copied_bytes, bytes_to_read);255 bytes = read(fd, &pos, buff + copied_bytes, bytes_to_read); 246 256 copied_bytes = 0; 247 257 -
uspace/app/bdsh/cmds/modules/cmp/cmp.c
rc9e3692 r58898d1d 79 79 char buffer[2][CMP_BUFLEN]; 80 80 ssize_t offset[2]; 81 aoff64_t pos[2] = {}; 81 82 82 83 for (int i = 0; i < 2; i++) { … … 94 95 ssize_t size; 95 96 do { 96 size = read(fd[i], buffer[i] + offset[i], 97 size = read(fd[i], &pos[i], 98 buffer[i] + offset[i], 97 99 CMP_BUFLEN - offset[i]); 98 100 if (size < 0) { -
uspace/app/bdsh/cmds/modules/cp/cp.c
rc9e3692 r58898d1d 377 377 int64_t copied = 0; 378 378 char *buff = NULL; 379 aoff64_t posr = 0, posw = 0; 380 struct stat st; 379 381 380 382 if (vb) … … 392 394 } 393 395 394 total = lseek(fd1, 0, SEEK_END); 395 396 if (fstat(fd1, &st) != EOK) { 397 printf("Unable to fstat %d\n", fd1); 398 close(fd1); 399 close(fd2); 400 return -1; 401 } 402 403 total = st.size; 396 404 if (vb) 397 405 printf("%" PRIu64 " bytes to copy\n", total); 398 399 lseek(fd1, 0, SEEK_SET);400 406 401 407 if (NULL == (buff = (char *) malloc(blen))) { … … 406 412 } 407 413 408 while ((bytes = read(fd1, buff, blen)) > 0) {409 if ((bytes = write(fd2, buff, bytes)) < 0)414 while ((bytes = read(fd1, &posr, buff, blen)) > 0) { 415 if ((bytes = write(fd2, &posw, buff, bytes)) < 0) 410 416 break; 411 417 copied += bytes; -
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
rc9e3692 r58898d1d 121 121 void *buffer; 122 122 bool create_sparse = false; 123 aoff64_t pos = 0; 123 124 124 125 file_size = 0; … … 164 165 if (create_sparse && file_size > 0) { 165 166 const char byte = 0x00; 166 167 if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0) { 168 close(fd); 169 goto error; 170 } 171 172 rc2 = write(fd, &byte, sizeof(char)); 167 168 pos = file_size - 1; 169 rc2 = write(fd, &pos, &byte, sizeof(char)); 173 170 if (rc2 < 0) { 174 171 close(fd); … … 187 184 while (total_written < file_size) { 188 185 to_write = min(file_size - total_written, BUFFER_SIZE); 189 rc = write(fd, buffer, to_write);186 rc = write(fd, &pos, buffer, to_write); 190 187 if (rc <= 0) { 191 188 printf("%s: Error writing file (%d).\n", cmdname, errno);
Note:
See TracChangeset
for help on using the changeset viewer.