Changes in uspace/app/bdsh/cmds/modules/cat/cat.c [ce04ea44:6afc9d7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
rce04ea44 r6afc9d7 33 33 #include <getopt.h> 34 34 #include <str.h> 35 #include <fcntl.h> 35 36 #include <io/console.h> 36 37 #include <io/color.h> … … 186 187 size_t offset = 0, copied_bytes = 0; 187 188 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 = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ);197 fd = open(fname, O_RDONLY); 198 198 199 199 if (fd < 0) { … … 203 203 204 204 if (NULL == (buff = (char *) malloc(blen + 1))) { 205 vfs_put(fd);205 close(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 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; 212 file_size = lseek(fd, 0, SEEK_END); 221 213 if (head == CAT_FULL_FILE) { 222 214 head = file_size; … … 231 223 232 224 if (tail_first) { 233 pos = (tail >= file_size) ? 0 : (file_size - tail);225 lseek(fd, (tail >= file_size) ? 0 : (file_size - tail), SEEK_SET); 234 226 } else { 235 pos = ((head - tail) >= file_size) ? 0 : (head - tail);227 lseek(fd, ((head - tail) >= file_size) ? 0 : (head - tail), SEEK_SET); 236 228 } 237 229 } else … … 251 243 } 252 244 253 bytes = vfs_read(fd, &pos, buff + copied_bytes, bytes_to_read);245 bytes = read(fd, buff + copied_bytes, bytes_to_read); 254 246 copied_bytes = 0; 255 247 … … 287 279 } while (bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE)); 288 280 289 vfs_put(fd);281 close(fd); 290 282 if (bytes == -1) { 291 283 printf("Error reading %s\n", fname);
Note:
See TracChangeset
for help on using the changeset viewer.