Changeset 368ee04 in mainline for uspace/app/bdsh/cmds/modules/cat/cat.c
- Timestamp:
- 2017-04-05T18:10:39Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 93ad8166
- Parents:
- 39f892a9 (diff), 2166728 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
r39f892a9 r368ee04 33 33 #include <getopt.h> 34 34 #include <str.h> 35 #include <fcntl.h>36 35 #include <io/console.h> 37 36 #include <io/color.h> … … 187 186 size_t offset = 0, copied_bytes = 0; 188 187 off64_t file_size = 0, length = 0; 188 aoff64_t pos = 0; 189 189 190 190 bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0); … … 195 195 blen = STR_BOUNDS(1); 196 196 } else 197 fd = open(fname, O_RDONLY);197 fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ); 198 198 199 199 if (fd < 0) { … … 203 203 204 204 if (NULL == (buff = (char *) malloc(blen + 1))) { 205 close(fd);205 vfs_put(fd); 206 206 printf("Unable to allocate enough memory to read %s\n", 207 207 fname); 208 208 return 1; 209 209 } 210 210 211 211 if (tail != CAT_FULL_FILE) { 212 file_size = lseek(fd, 0, SEEK_END); 212 struct stat st; 213 214 if (vfs_stat(fd, &st) != EOK) { 215 vfs_put(fd); 216 free(buff); 217 printf("Unable to vfs_stat %d\n", fd); 218 return 1; 219 } 220 file_size = st.size; 213 221 if (head == CAT_FULL_FILE) { 214 222 head = file_size; … … 223 231 224 232 if (tail_first) { 225 lseek(fd, (tail >= file_size) ? 0 : (file_size - tail), SEEK_SET);233 pos = (tail >= file_size) ? 0 : (file_size - tail); 226 234 } else { 227 lseek(fd, ((head - tail) >= file_size) ? 0 : (head - tail), SEEK_SET);235 pos = ((head - tail) >= file_size) ? 0 : (head - tail); 228 236 } 229 237 } else … … 243 251 } 244 252 245 bytes = read(fd, buff + copied_bytes, bytes_to_read);253 bytes = vfs_read(fd, &pos, buff + copied_bytes, bytes_to_read); 246 254 copied_bytes = 0; 247 255 … … 279 287 } while (bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE)); 280 288 281 close(fd);289 vfs_put(fd); 282 290 if (bytes == -1) { 283 291 printf("Error reading %s\n", fname);
Note:
See TracChangeset
for help on using the changeset viewer.