Changeset 58898d1d in mainline for uspace/app/bdsh/cmds/modules/cat/cat.c
- Timestamp:
- 2017-03-24T20:31:54Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8e9b2534
- Parents:
- c9e3692
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.