ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/BeOS/extfs_beos.cpp
(Generate patch)

Comparing BasiliskII/src/BeOS/extfs_beos.cpp (file contents):
Revision 1.3 by cebix, 1999-10-21T22:39:59Z vs.
Revision 1.9 by cebix, 1999-12-22T16:16:14Z

# Line 75 | Line 75 | void extfs_exit(void)
75   *  Add component to path name
76   */
77  
78 < void add_path_component(char *path, const char *component, int max_len)
78 > void add_path_component(char *path, const char *component)
79   {
80          int l = strlen(path);
81 <        if (l < max_len-1 && path[l-1] != '/') {
81 >        if (l < MAX_PATH_LENGTH-1 && path[l-1] != '/') {
82                  path[l] = '/';
83                  path[l+1] = 0;
84          }
85 <        strncat(path, s, max_len-1);
85 >        strncat(path, component, MAX_PATH_LENGTH-1);
86   }
87  
88  
# Line 283 | Line 283 | int open_rfork(const char *path, int fla
283          // Open temporary file for resource fork
284          char rname[L_tmpnam];
285          tmpnam(rname);
286 <        int rfd = open(rname, O_RDWR | O_CREAT | O_TRUNC, 0664);
286 >        int rfd = open(rname, O_RDWR | O_CREAT | O_TRUNC, 0666);
287          if (rfd < 0) {
288                  close(fd);
289                  return -1;
# Line 369 | Line 369 | void close_rfork(const char *path, int f
369  
370   /*
371   *  Read "length" bytes from file to "buffer",
372 < *  returns number of bytes read (or 0)
372 > *  returns number of bytes read (or -1 on error)
373   */
374  
375   static inline ssize_t sread(int fd, void *buf, size_t count)
# Line 379 | Line 379 | static inline ssize_t sread(int fd, void
379          return res;
380   }
381  
382 < size_t extfs_read(int fd, void *buffer, size_t length)
382 > ssize_t extfs_read(int fd, void *buffer, size_t length)
383   {
384        errno = 0;
385
384          // Buffer in kernel space?
387        size_t actual = 0;
385          if ((uint32)buffer < 0x80000000) {
386  
387                  // Yes, transfer via buffer
388 +                ssize_t actual = 0;
389                  while (length) {
390                          size_t transfer_size = (length > TMP_BUF_SIZE) ? TMP_BUF_SIZE : length;
391                          ssize_t res = sread(fd, tmp_buf, transfer_size);
392 <                        if (res >= 0) {
393 <                                memcpy(buffer, tmp_buf, res);
394 <                                buffer = (void *)((uint8 *)buffer + res);
395 <                                length -= res;
396 <                                actual += res;
397 <                        }
392 >                        if (res < 0)
393 >                                return res;
394 >                        memcpy(buffer, tmp_buf, res);
395 >                        buffer = (void *)((uint8 *)buffer + res);
396 >                        length -= res;
397 >                        actual += res;
398                          if (res != transfer_size)
399                                  return actual;
400                  }
401 +                return actual;
402  
403          } else {
404  
405                  // No, transfer directly
406 <                actual = sread(fd, buffer, length);
408 <                if (actual < 0)
409 <                        actual = 0;
406 >                return sread(fd, buffer, length);
407          }
411        return actual;
408   }
409  
410  
411   /*
412   *  Write "length" bytes from "buffer" to file,
413 < *  returns number of bytes written (or 0)
413 > *  returns number of bytes written (or -1 on error)
414   */
415  
416   static inline ssize_t swrite(int fd, void *buf, size_t count)
# Line 424 | Line 420 | static inline ssize_t swrite(int fd, voi
420          return res;
421   }
422  
423 < size_t extfs_write(int fd, void *buffer, size_t length)
423 > ssize_t extfs_write(int fd, void *buffer, size_t length)
424   {
429        errno = 0;
430
425          // Buffer in kernel space?
432        size_t actual = 0;
426          if ((uint32)buffer < 0x80000000) {
427  
428                  // Yes, transfer via buffer
429 +                ssize_t actual = 0;
430                  while (length) {
431                          size_t transfer_size = (length > TMP_BUF_SIZE) ? TMP_BUF_SIZE : length;
432                          memcpy(tmp_buf, buffer, transfer_size);
433                          ssize_t res = swrite(fd, tmp_buf, transfer_size);
434 <                        if (res >= 0) {
435 <                                buffer = (void *)((uint8 *)buffer + res);
436 <                                length -= res;
437 <                                actual += res;
438 <                        }
434 >                        if (res < 0)
435 >                                return res;
436 >                        buffer = (void *)((uint8 *)buffer + res);
437 >                        length -= res;
438 >                        actual += res;
439                          if (res != transfer_size)
440                                  return actual;
441                  }
442 +                return actual;
443  
444          } else {
445  
446                  // No, transfer directly
447 <                actual = swrite(fd, buffer, length);
453 <                if (actual < 0)
454 <                        actual = 0;
447 >                return swrite(fd, buffer, length);
448          }
449 <        return actual;
449 > }
450 >
451 >
452 > /*
453 > *  Remove file/directory, returns false on error (and sets errno)
454 > */
455 >
456 > bool extfs_remove(const char *path)
457 > {
458 >        if (remove(path) < 0) {
459 >                if (errno == EISDIR)
460 >                        return rmdir(path) == 0;
461 >                else
462 >                        return false;
463 >        }
464 >        return true;
465 > }
466 >
467 >
468 > /*
469 > *  Rename/move file/directory, returns false on error (and sets errno)
470 > */
471 >
472 > bool extfs_rename(const char *old_path, const char *new_path)
473 > {
474 >        return rename(old_path, new_path) == 0;
475   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines