Changeset 8e3498b in mainline for uspace/app
- Timestamp:
- 2017-12-04T18:44:24Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bde5c04
- Parents:
- 40feeac
- Location:
- uspace/app
- Files:
-
- 11 edited
-
bdsh/cmds/modules/cat/cat.c (modified) (3 diffs)
-
bdsh/cmds/modules/cmp/cmp.c (modified) (3 diffs)
-
bdsh/cmds/modules/cp/cp.c (modified) (17 diffs)
-
bdsh/cmds/modules/mkfile/mkfile.c (modified) (7 diffs)
-
sysinst/futil.c (modified) (6 diffs)
-
taskdump/elf_core.c (modified) (8 diffs)
-
taskdump/symtab.c (modified) (5 diffs)
-
tester/mm/pager1.c (modified) (2 diffs)
-
tester/vfs/vfs1.c (modified) (2 diffs)
-
viewer/viewer.c (modified) (1 diff)
-
websrv/websrv.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
r40feeac r8e3498b 180 180 off64_t head, off64_t tail, bool tail_first) 181 181 { 182 int fd, bytes = 0, count = 0, reads = 0; 182 int fd, count = 0, reads = 0; 183 size_t bytes; 183 184 char *buff = NULL; 184 int i;185 size_t i; 185 186 size_t offset = 0, copied_bytes = 0; 186 187 off64_t file_size = 0, length = 0; 187 188 aoff64_t pos = 0; 189 int rc; 188 190 189 191 bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0); … … 250 252 } 251 253 252 bytes = vfs_read(fd, &pos, buff + copied_bytes, bytes_to_read); 254 rc = vfs_read(fd, &pos, buff + copied_bytes, bytes_to_read, 255 &bytes); 253 256 copied_bytes = 0; 254 257 255 if ( bytes > 0) {258 if (rc == EOK && bytes > 0) { 256 259 buff[bytes] = '\0'; 257 260 offset = 0; … … 284 287 if (reading_stdin) 285 288 fflush(stdout); 286 } while ( bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE));289 } while (rc == EOK && bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE)); 287 290 288 291 vfs_put(fd); 289 if ( bytes == -1) {292 if (rc != EOK) { 290 293 printf("Error reading %s\n", fname); 291 294 free(buff); -
uspace/app/bdsh/cmds/modules/cmp/cmp.c
r40feeac r8e3498b 72 72 static int cmp_files(const char *fn0, const char *fn1) 73 73 { 74 int rc = 0;74 int rc = EOK; 75 75 const char *fn[2] = {fn0, fn1}; 76 76 int fd[2] = {-1, -1}; 77 77 char buffer[2][CMP_BUFLEN]; 78 s size_t offset[2];78 size_t offset[2]; 79 79 aoff64_t pos[2] = {}; 80 80 … … 90 90 do { 91 91 for (int i = 0; i < 2; i++) { 92 offset[i] = 0; 93 ssize_t size; 94 do { 95 size = vfs_read(fd[i], &pos[i], 96 buffer[i] + offset[i], 97 CMP_BUFLEN - offset[i]); 98 if (size < 0) { 99 rc = size; 100 printf("Error reading from %s\n", 101 fn[i]); 102 goto end; 103 } 104 offset[i] += size; 105 } while (size && offset[i] < CMP_BUFLEN); 92 rc = vfs_read(fd[i], &pos[i], buffer[i], CMP_BUFLEN, 93 &offset[i]); 94 if (rc != EOK) { 95 printf("Error reading from %s\n", 96 fn[i]); 97 goto end; 98 } 106 99 } 107 100 108 101 if (offset[0] != offset[1] || 109 102 memcmp(buffer[0], buffer[1], offset[0]) != 0) { 103 printf("Return 1\n"); 110 104 rc = 1; 111 105 goto end; … … 149 143 150 144 rc = cmp_files(argv[optind], argv[optind + 1]); 151 if (rc )145 if (rc != EOK) 152 146 return CMD_FAILURE; 153 147 else -
uspace/app/bdsh/cmds/modules/cp/cp.c
r40feeac r8e3498b 66 66 } dentry_type_t; 67 67 68 static int 64_tcopy_file(const char *src, const char *dest,68 static int copy_file(const char *src, const char *dest, 69 69 size_t blen, int vb); 70 70 … … 175 175 } 176 176 177 static int 64_tdo_copy(const char *src, const char *dest,177 static int do_copy(const char *src, const char *dest, 178 178 size_t blen, int vb, int recursive, int force, int interactive) 179 179 { 180 int r = -1;180 int rc = EOK; 181 181 char dest_path[PATH_MAX]; 182 182 char src_path[PATH_MAX]; … … 217 217 printf("The dest directory %s does not exists", 218 218 dest_path); 219 rc = ENOENT; 219 220 goto exit; 220 221 } … … 224 225 printf("Cannot overwrite existing directory %s\n", 225 226 dest_path); 227 rc = EEXIST; 226 228 goto exit; 227 229 } else if (dest_type == TYPE_FILE) { … … 233 235 */ 234 236 if (force && !interactive) { 235 if (vfs_unlink_path(dest_path) != EOK) { 237 rc = vfs_unlink_path(dest_path); 238 if (rc != EOK) { 236 239 printf("Unable to remove %s\n", 237 240 dest_path); … … 244 247 if (overwrite) { 245 248 printf("Overwriting file: %s\n", dest_path); 246 if (vfs_unlink_path(dest_path) != EOK) { 249 rc = vfs_unlink_path(dest_path); 250 if (rc != EOK) { 247 251 printf("Unable to remove %s\n", dest_path); 248 252 goto exit; … … 250 254 } else { 251 255 printf("Not overwriting file: %s\n", dest_path); 252 r = 0;256 rc = EOK; 253 257 goto exit; 254 258 } 255 259 } else { 256 260 printf("File already exists: %s\n", dest_path); 261 rc = EEXIST; 257 262 goto exit; 258 263 } … … 260 265 261 266 /* call copy_file and exit */ 262 r = (copy_file(src, dest_path, blen, vb) < 0);267 rc = (copy_file(src, dest_path, blen, vb) < 0); 263 268 264 269 } else if (src_type == TYPE_DIR) { … … 268 273 printf("Cannot copy the %s directory without the " 269 274 "-r option\n", src); 275 rc = EINVAL; 270 276 goto exit; 271 277 } else if (dest_type == TYPE_FILE) { 272 278 printf("Cannot overwrite a file with a directory\n"); 279 rc = EEXIST; 273 280 goto exit; 274 281 } … … 293 300 merge_paths(dest_path, PATH_MAX, src_dirname); 294 301 295 if (vfs_link_path(dest_path, KIND_DIRECTORY, 296 NULL) != EOK) { 302 rc = vfs_link_path(dest_path, KIND_DIRECTORY, 303 NULL); 304 if (rc != EOK) { 297 305 printf("Unable to create " 298 306 "dest directory %s\n", dest_path); … … 308 316 * e.g. cp -r /src /data/new_dir_src 309 317 */ 310 if (vfs_link_path(dest_path, KIND_DIRECTORY,311 NULL)!= EOK) {318 rc = vfs_link_path(dest_path, KIND_DIRECTORY, NULL); 319 if (rc != EOK) { 312 320 printf("Unable to create " 313 321 "dest directory %s\n", dest_path); … … 321 329 /* Something strange is happening... */ 322 330 printf("Unable to open src %s directory\n", src); 331 rc = ENOENT; 323 332 goto exit; 324 333 } … … 348 357 printf("Cannot copy a directory " 349 358 "into itself\n"); 359 rc = EEXIST; 350 360 goto exit; 351 361 } … … 355 365 356 366 /* Recursively call do_copy() */ 357 r = do_copy(src_dent, dest_dent, blen, vb, recursive,367 rc = do_copy(src_dent, dest_dent, blen, vb, recursive, 358 368 force, interactive); 359 if (r )369 if (rc != EOK) 360 370 goto exit; 361 371 … … 367 377 if (dir) 368 378 closedir(dir); 369 return r ;370 } 371 372 static int 64_tcopy_file(const char *src, const char *dest,379 return rc; 380 } 381 382 static int copy_file(const char *src, const char *dest, 373 383 size_t blen, int vb) 374 384 { 375 int fd1, fd2, bytes; 385 int fd1, fd2; 386 size_t rbytes, wbytes; 387 int rc; 376 388 off64_t total; 377 int64_t copied = 0;378 389 char *buff = NULL; 379 390 aoff64_t posr = 0, posw = 0; … … 410 421 printf("Unable to allocate enough memory to read %s\n", 411 422 src); 412 copied = -1;423 rc = ENOMEM; 413 424 goto out; 414 425 } 415 426 416 while (( bytes = vfs_read(fd1, &posr, buff, blen)) > 0) {417 if ((bytes = vfs_write(fd2, &posw, buff, bytes)) < 0)418 break;419 copied += bytes;420 } 421 422 if ( bytes < 0) {423 printf("\nError copying %s, (%d)\n", src, bytes);424 copied = bytes;427 while ((rc = vfs_read(fd1, &posr, buff, blen, &rbytes)) == EOK && 428 rbytes > 0) { 429 if ((rc = vfs_write(fd2, &posw, buff, rbytes, &wbytes)) != EOK) 430 break; 431 } 432 433 if (rc != EOK) { 434 printf("\nError copying %s, (%d)\n", src, rc); 435 return rc; 425 436 } 426 437 … … 430 441 if (buff) 431 442 free(buff); 432 return copied;443 return rc; 433 444 } 434 445 -
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
r40feeac r8e3498b 85 85 * 86 86 * @param str String containing the size specification. 87 * @return Non-negative size in bytes on success, -1 on failure. 87 * @param rsize Place to store size in bytes 88 * @return EOK on success or error code 88 89 */ 89 static ssize_t read_size(const char *str)90 static int read_size(const char *str, size_t *rsize) 90 91 { 91 s size_t number, unit;92 size_t number, unit; 92 93 char *ep; 93 94 94 95 number = strtol(str, &ep, 10); 95 if (ep[0] == '\0') 96 return number; 96 if (ep[0] == '\0') { 97 *rsize = number; 98 return EOK; 99 } 97 100 98 101 if (ep[1] != '\0') 99 return -1;102 return EINVAL; 100 103 101 104 switch (tolower(ep[0])) { … … 103 106 case 'm': unit = 1024*1024; break; 104 107 case 'g': unit = 1024*1024*1024; break; 105 default: return -1; 106 } 107 108 return number * unit; 108 default: return EINVAL; 109 } 110 111 *rsize = number * unit; 112 return EOK; 109 113 } 110 114 … … 114 118 int c, opt_ind; 115 119 int fd; 116 ssize_t file_size; 117 ssize_t total_written; 118 ssize_t to_write, rc, rc2 = 0; 120 size_t file_size; 121 size_t total_written; 122 size_t to_write; 123 size_t nwritten; 124 int rc; 119 125 char *file_name; 120 126 void *buffer; … … 136 142 break; 137 143 case 's': 138 file_size = read_size(optarg);139 if ( file_size < 0) {144 rc = read_size(optarg, &file_size); 145 if (rc != EOK) { 140 146 printf("%s: Invalid file size specification.\n", 141 147 cmdname); … … 166 172 167 173 pos = file_size - 1; 168 rc 2 = vfs_write(fd, &pos, &byte, sizeof(char));169 if (rc 2 < 0) {174 rc = vfs_write(fd, &pos, &byte, sizeof(char), &nwritten); 175 if (rc != EOK) { 170 176 vfs_put(fd); 171 177 goto error; … … 183 189 while (total_written < file_size) { 184 190 to_write = min(file_size - total_written, BUFFER_SIZE); 185 rc = vfs_write(fd, &pos, buffer, to_write );186 if (rc <= 0) {191 rc = vfs_write(fd, &pos, buffer, to_write, &nwritten); 192 if (rc != EOK) { 187 193 printf("%s: Error writing file (%d).\n", cmdname, errno); 188 194 vfs_put(fd); … … 190 196 return CMD_FAILURE; 191 197 } 192 total_written += rc;198 total_written += nwritten; 193 199 } 194 200 -
uspace/app/sysinst/futil.c
r40feeac r8e3498b 57 57 { 58 58 int sf, df; 59 s size_t nr, nw;59 size_t nr, nw; 60 60 int rc; 61 61 aoff64_t posr = 0, posw = 0; … … 72 72 73 73 do { 74 nr = vfs_read(sf, &posr, buf, BUF_SIZE); 74 rc = vfs_read(sf, &posr, buf, BUF_SIZE, &nr); 75 if (rc != EOK) 76 goto error; 75 77 if (nr == 0) 76 78 break; 77 if (nr < 0) 78 return EIO; 79 80 nw = vfs_write(df, &posw, buf, nr); 81 if (nw <= 0) 82 return EIO; 83 } while (true); 79 80 rc= vfs_write(df, &posw, buf, nr, &nw); 81 if (rc != EOK) 82 goto error; 83 84 } while (nr == BUF_SIZE); 84 85 85 86 (void) vfs_put(sf); … … 90 91 91 92 return EOK; 93 error: 94 vfs_put(sf); 95 vfs_put(df); 96 return rc; 92 97 } 93 98 … … 156 161 { 157 162 int sf; 158 ssize_t nr; 163 size_t nr; 164 int rc; 159 165 size_t fsize; 160 166 char *data; … … 168 174 vfs_put(sf); 169 175 return EIO; 170 } 176 } 171 177 172 178 fsize = st.size; … … 178 184 } 179 185 180 nr = vfs_read(sf, (aoff64_t []) { 0 }, data, fsize);181 if ( nr != (ssize_t)fsize) {186 rc = vfs_read(sf, (aoff64_t []) { 0 }, data, fsize, &nr); 187 if (rc != EOK || nr != fsize) { 182 188 vfs_put(sf); 183 189 free(data); -
uspace/app/taskdump/elf_core.c
r40feeac r8e3498b 97 97 98 98 int fd; 99 ssize_t rc; 99 int rc; 100 size_t nwr; 100 101 unsigned int i; 101 102 … … 206 207 } 207 208 208 rc = vfs_write(fd, &pos, &elf_hdr, sizeof(elf_hdr) );209 if (rc != sizeof(elf_hdr)) {209 rc = vfs_write(fd, &pos, &elf_hdr, sizeof(elf_hdr), &nwr); 210 if (rc != EOK) { 210 211 printf("Failed writing ELF header.\n"); 211 212 free(p_hdr); … … 214 215 215 216 for (i = 0; i < n_ph; ++i) { 216 rc = vfs_write(fd, &pos, &p_hdr[i], sizeof(p_hdr[i]) );217 if (rc != sizeof(p_hdr[i])) {217 rc = vfs_write(fd, &pos, &p_hdr[i], sizeof(p_hdr[i]), &nwr); 218 if (rc != EOK) { 218 219 printf("Failed writing program header.\n"); 219 220 free(p_hdr); … … 231 232 note.type = NT_PRSTATUS; 232 233 233 rc = vfs_write(fd, &pos, ¬e, sizeof(elf_note_t) );234 if (rc != sizeof(elf_note_t)) {234 rc = vfs_write(fd, &pos, ¬e, sizeof(elf_note_t), &nwr); 235 if (rc != EOK) { 235 236 printf("Failed writing note header.\n"); 236 237 free(p_hdr); … … 238 239 } 239 240 240 rc = vfs_write(fd, &pos, "CORE", note.namesz );241 if (rc != (ssize_t) note.namesz) {241 rc = vfs_write(fd, &pos, "CORE", note.namesz, &nwr); 242 if (rc != EOK) { 242 243 printf("Failed writing note header.\n"); 243 244 free(p_hdr); … … 247 248 pos = ALIGN_UP(pos, word_size); 248 249 249 rc = vfs_write(fd, &pos, &pr_status, sizeof(elf_prstatus_t) );250 if (rc != sizeof(elf_prstatus_t)) {250 rc = vfs_write(fd, &pos, &pr_status, sizeof(elf_prstatus_t), &nwr); 251 if (rc != EOK) { 251 252 printf("Failed writing register data.\n"); 252 253 free(p_hdr); … … 296 297 size_t total; 297 298 uintptr_t addr; 298 ssize_t rc; 299 int rc; 300 size_t nwr; 299 301 300 302 addr = area->start_addr; … … 309 311 } 310 312 311 rc = vfs_write(fd, pos, buffer, to_copy );312 if (rc != (ssize_t) to_copy) {313 rc = vfs_write(fd, pos, buffer, to_copy, &nwr); 314 if (rc != EOK) { 313 315 printf("Failed writing memory contents.\n"); 314 316 return EIO; -
uspace/app/taskdump/symtab.c
r40feeac r8e3498b 71 71 int fd; 72 72 int rc; 73 size_t nread; 73 74 int i; 74 75 … … 88 89 } 89 90 90 rc = vfs_read(fd, &pos, &elf_hdr, sizeof(elf_header_t) );91 if (rc != sizeof(elf_header_t)) {91 rc = vfs_read(fd, &pos, &elf_hdr, sizeof(elf_header_t), &nread); 92 if (rc != EOK || nread != sizeof(elf_header_t)) { 92 93 printf("failed reading elf header\n"); 93 94 free(stab); … … 304 305 { 305 306 int rc; 307 size_t nread; 306 308 aoff64_t pos = elf_hdr->e_shoff + idx * sizeof(elf_section_header_t); 307 309 308 rc = vfs_read(fd, &pos, sec_hdr, sizeof(elf_section_header_t) );309 if (rc != sizeof(elf_section_header_t))310 rc = vfs_read(fd, &pos, sec_hdr, sizeof(elf_section_header_t), &nread); 311 if (rc != EOK || nread != sizeof(elf_section_header_t)) 310 312 return EIO; 311 313 … … 326 328 static int chunk_load(int fd, off64_t start, size_t size, void **ptr) 327 329 { 328 ssize_t rc; 330 int rc; 331 size_t nread; 329 332 aoff64_t pos = start; 330 333 … … 335 338 } 336 339 337 rc = vfs_read(fd, &pos, *ptr, size );338 if (rc != (ssize_t)size) {340 rc = vfs_read(fd, &pos, *ptr, size, &nread); 341 if (rc != EOK || nread != size) { 339 342 printf("failed reading chunk\n"); 340 343 free(*ptr); -
uspace/app/tester/mm/pager1.c
r40feeac r8e3498b 44 44 static void *create_paged_area(size_t size) 45 45 { 46 size_t nwr; 47 int rc; 48 46 49 TPRINTF("Creating temporary file...\n"); 47 50 … … 52 55 (void) vfs_unlink_path(TEST_FILE); 53 56 54 if (vfs_write(fd, (aoff64_t []) {0}, text, sizeof(text)) < 0) { 57 rc = vfs_write(fd, (aoff64_t []) {0}, text, sizeof(text), &nwr); 58 if (rc != EOK) { 55 59 vfs_put(fd); 56 60 return NULL; -
uspace/app/tester/vfs/vfs1.c
r40feeac r8e3498b 84 84 85 85 size_t size = sizeof(text); 86 ssize_t cnt = vfs_write(fd0, &pos, text, size); 87 if (cnt < 0) 86 size_t cnt; 87 rc = vfs_write(fd0, &pos, text, size, &cnt); 88 if (rc != EOK) 88 89 return "write() failed"; 89 90 TPRINTF("Written %zd bytes\n", cnt); … … 93 94 char buf[BUF_SIZE]; 94 95 TPRINTF("read..\n"); 95 while (( cnt = vfs_read(fd0, &pos, buf, BUF_SIZE))) {96 TPRINTF("read returns %zd\n", cnt);97 if ( cnt < 0)96 while ((rc = vfs_read(fd0, &pos, buf, BUF_SIZE, &cnt))) { 97 TPRINTF("read returns rc = %d, cnt = %zu\n", rc, cnt); 98 if (rc != EOK) 98 99 return "read() failed"; 99 100 100 int _cnt = (int) cnt;101 if ( _cnt != cnt) {101 int icnt = (int) cnt; 102 if ((size_t) icnt != cnt) { 102 103 /* Count overflow, just to be sure. */ 103 104 TPRINTF("Read %zd bytes\n", cnt); 104 105 } else { 105 TPRINTF("Read %zd bytes: \"%.*s\"\n", cnt, _cnt, buf);106 TPRINTF("Read %zd bytes: \"%.*s\"\n", cnt, icnt, buf); 106 107 } 107 108 } -
uspace/app/viewer/viewer.c
r40feeac r8e3498b 126 126 } 127 127 128 ssize_t rd = vfs_read(fd, (aoff64_t []) {0}, tga, stat.size); 129 if ((rd < 0) || (rd != (ssize_t) stat.size)) { 128 size_t nread; 129 rc = vfs_read(fd, (aoff64_t []) {0}, tga, stat.size, &nread); 130 if (rc != EOK || nread != stat.size) { 130 131 free(tga); 131 132 vfs_put(fd); -
uspace/app/websrv/websrv.c
r40feeac r8e3498b 247 247 char *fname = NULL; 248 248 int rc; 249 size_t nr; 249 250 int fd = -1; 250 251 … … 279 280 aoff64_t pos = 0; 280 281 while (true) { 281 ssize_t nr = vfs_read(fd, &pos, fbuf, BUFFER_SIZE); 282 rc = vfs_read(fd, &pos, fbuf, BUFFER_SIZE, &nr); 283 if (rc != EOK) 284 goto out; 285 282 286 if (nr == 0) 283 287 break; 284 285 if (nr < 0) {286 rc = EIO;287 goto out;288 }289 288 290 289 rc = tcp_conn_send(conn, fbuf, nr);
Note:
See TracChangeset
for help on using the changeset viewer.
